Mercurial > hg > graal-jvmci-8
annotate src/share/tools/IdealGraphVisualizer/Text Editor/src/at/ssw/visualizer/texteditor/model/Scanner.java @ 2843:6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Wed, 01 Jun 2011 15:22:40 +0200 |
parents | |
children |
rev | line source |
---|---|
2843
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
1 package at.ssw.visualizer.texteditor.model; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
2 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
3 import java.util.BitSet; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
4 import java.util.Set; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
5 import java.util.logging.Level; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
6 import java.util.logging.Logger; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
7 import javax.swing.text.BadLocationException; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
8 import javax.swing.text.Document; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
9 import org.netbeans.editor.Syntax; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
10 import org.netbeans.editor.TokenContextPath; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
11 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
12 /** |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
13 * The implementing class must specify the used <code> TokenID</code>s and |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
14 * implement the scanner for the specified text. |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
15 * |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
16 * @author Alexander Reder |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
17 * @author Christian Wimmer |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
18 */ |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
19 public abstract class Scanner extends Syntax { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
20 protected static final int EOF = 0; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
21 protected static final BitSet DIGIT = charsOf("0123456789"); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
22 protected static final BitSet HEX = charsOf("0123456789abcdefABCDEF"); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
23 protected static final BitSet LETTER = charsOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
24 protected static final BitSet LETTER_DIGIT = charsOf("0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
25 protected static final BitSet LC_LETTER = charsOf("_abcdefghijklmnopqrstuvwxyz"); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
26 protected static final BitSet LC_LETTER_DIGIT = charsOf("0123456789_abcdefghijklmnopqrstuvwxyz"); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
27 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
28 protected static BitSet charsOf(String s) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
29 BitSet result = new BitSet(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
30 for (int i = 0; i < s.length(); i++) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
31 result.set(s.charAt(i)); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
32 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
33 return result; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
34 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
35 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
36 protected BitSet whitespace; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
37 protected char ch; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
38 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
39 public Scanner(String whitespace, TokenContextPath tokenContextPath) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
40 this.whitespace = charsOf(whitespace); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
41 this.whitespace.set(EOF); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
42 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
43 this.tokenContextPath = tokenContextPath; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
44 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
45 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
46 public void setText(Document document) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
47 try { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
48 setText(document.getText(0, document.getLength()), 0, document.getLength()); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
49 } catch (BadLocationException ex) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
50 Logger logger = Logger.getLogger(Scanner.class.getName()); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
51 logger.log(Level.SEVERE, ex.getMessage(), ex); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
52 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
53 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
54 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
55 public void setText(String s, int offset, int length) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
56 this.buffer = s.toCharArray(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
57 this.offset = offset; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
58 this.tokenOffset = offset; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
59 this.stopOffset = Math.min(buffer.length, offset + length); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
60 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
61 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
62 public String getTokenString() { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
63 return new String(buffer, getTokenOffset(), getTokenLength()); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
64 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
65 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
66 public void findTokenBegin(int offset) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
67 this.offset = Math.max(offset, 0); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
68 findTokenBegin(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
69 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
70 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
71 /** |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
72 * If offset is in a token this method will read backwards until a |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
73 * whitespace character occurs. |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
74 */ |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
75 protected void findTokenBegin() { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
76 if (offset >= stopOffset) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
77 offset = stopOffset - 1; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
78 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
79 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
80 if (!whitespace.get(buffer[offset])) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
81 while (offset > 0 && !whitespace.get(buffer[offset - 1])) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
82 offset--; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
83 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
84 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
85 ch = buffer[offset]; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
86 tokenOffset = offset; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
87 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
88 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
89 /** |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
90 * Reads the next character. |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
91 */ |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
92 protected void readNext() { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
93 offset++; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
94 if (offset < stopOffset) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
95 ch = buffer[offset]; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
96 } else { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
97 ch = EOF; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
98 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
99 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
100 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
101 protected boolean isWhitespace() { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
102 boolean result = false; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
103 while (whitespace.get(ch) && ch != EOF) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
104 result = true; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
105 readNext(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
106 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
107 return result; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
108 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
109 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
110 /** |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
111 * Read to the next whitespace |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
112 */ |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
113 protected void readToWhitespace() { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
114 do { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
115 readNext(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
116 } while (!whitespace.get(ch)); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
117 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
118 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
119 private boolean readNextOrRestart(boolean result, boolean readNext) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
120 if (result) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
121 if (readNext) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
122 readNext(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
123 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
124 } else { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
125 offset = tokenOffset; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
126 ch = buffer[offset]; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
127 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
128 return result; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
129 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
130 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
131 protected boolean isKeyword(Set<String> keywords) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
132 int beginOffset = offset; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
133 int endOffset = offset; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
134 while (endOffset < stopOffset && !whitespace.get(buffer[endOffset])) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
135 endOffset++; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
136 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
137 String word = new String(buffer, beginOffset, endOffset - beginOffset); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
138 if (!keywords.contains(word)) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
139 return false; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
140 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
141 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
142 offset = endOffset - 1; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
143 readNext(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
144 return true; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
145 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
146 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
147 protected boolean expectEnd() { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
148 return readNextOrRestart(whitespace.get(ch), false); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
149 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
150 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
151 protected boolean expectEnd(char expected) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
152 return readNextOrRestart(ch == expected, false) && offset + 1 < stopOffset && whitespace.get(buffer[offset + 1]); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
153 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
154 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
155 protected boolean expectChar(char expected) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
156 return readNextOrRestart(ch == expected, true); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
157 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
158 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
159 protected boolean expectChar(BitSet expected) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
160 return readNextOrRestart(expected.get(ch), true); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
161 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
162 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
163 protected boolean expectChars(BitSet expected) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
164 while (expected.get(ch)) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
165 readNext(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
166 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
167 return true; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
168 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
169 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
170 protected boolean skipUntil(char expected) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
171 while (ch != expected && !whitespace.get(ch)) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
172 readNext(); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
173 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
174 return expectChar(expected); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
175 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
176 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
177 protected boolean beforeChar(char before) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
178 int curOffset = offset - 1; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
179 while (curOffset >= 0 && buffer[curOffset] != before && whitespace.get(buffer[curOffset])) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
180 curOffset--; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
181 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
182 return curOffset >= 0 && buffer[curOffset] == before; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
183 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
184 |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
185 protected boolean beforeChars(BitSet before) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
186 int curOffset = offset - 1; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
187 while (curOffset >= 0 && !before.get(buffer[curOffset]) && whitespace.get(buffer[curOffset])) { |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
188 curOffset--; |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
189 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
190 return curOffset >= 0 && before.get(buffer[curOffset]); |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
191 } |
6960cc79f664
IdealGraphVisualizer: Import editor component from C1XVisualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
192 } |