KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > lexer > DelegatingInputBridge


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.languages.lexer;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.List JavaDoc;
24 import org.netbeans.api.languages.CharInput;
25 import org.netbeans.modules.languages.lexer.SLexer.TokenProperties;
26 import org.netbeans.modules.languages.lexer.SLexer.Vojta;
27 import org.netbeans.modules.languages.parser.Pattern;
28
29
30 class DelegatingInputBridge extends CharInput {
31
32     private InputBridge input;
33     private Pattern start;
34     private Pattern end;
35     private String JavaDoc tokenType;
36     private List JavaDoc<Vojta> embeddings = new ArrayList JavaDoc<Vojta> ();
37
38     DelegatingInputBridge (
39         InputBridge input,
40         Pattern start,
41         Pattern end,
42         String JavaDoc tokenType
43     ) {
44         this.input = input;
45         this.start = start;
46         this.end = end;
47         this.tokenType = tokenType;
48     }
49
50     public char read () {
51         readEmbeddings ();
52         return input.read ();
53     }
54
55     public void setIndex (int index) {
56         input.setIndex (index);
57     }
58
59     public int getIndex () {
60         return input.getIndex ();
61     }
62
63     public char next () {
64         readEmbeddings ();
65         return input.next ();
66     }
67
68     public boolean eof () {
69         readEmbeddings ();
70         return input.eof ();
71     }
72
73     public String JavaDoc getString (int from, int to) {
74         return input.getString (from, to);
75     }
76
77     public String JavaDoc toString () {
78         return input.toString ();
79     }
80     
81     public List JavaDoc<Vojta> getEmbeddings () {
82         List JavaDoc<Vojta> e = embeddings;
83         embeddings = new ArrayList JavaDoc<Vojta> ();
84         return e;
85     }
86     
87     private void readEmbeddings () {
88         int startIndex = input.getIndex ();
89         if (!input.eof () && start.next (input) != null) {
90             int startSkipLength = input.getIndex () - startIndex;
91             int endSkipLength = input.getIndex ();
92             while (!input.eof () && end.next (input) == null) {
93                 input.read ();
94                 endSkipLength = input.getIndex ();
95             }
96             endSkipLength = input.getIndex () - endSkipLength;
97             embeddings.add (
98                 new Vojta (
99                     tokenType,
100                     startIndex,
101                     input.getIndex (),
102                     new TokenProperties (
103                         "E",
104                         startSkipLength,
105                         endSkipLength
106                     )
107                 )
108             );
109         }
110     }
111 }
112
113
114
Popular Tags