Changeset 3075
- Timestamp:
- Apr 25, 2013, 11:45:08 PM (6 years ago)
- Location:
- proto/RE/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
proto/RE/src/lexicalAnalyzer/Lextant.java
r3072 r3075 19 19 public enum Lextant { 20 20 ANY(".", "main"), 21 RIGHTSQUARE("]", "charClass" , "]", "main"),21 RIGHTSQUARE("]", "charClass"), 22 22 BACKSLASH("\\", "charClass", "\\", "main"), 23 23 OR("|", "main"), … … 26 26 STAR("*", "main"), 27 27 PLUS("+", "main"), 28 RIGHTCURLY("}", "boundedRepetition" , "}", "main"),28 RIGHTCURLY("}", "boundedRepetition"), 29 29 LEFTROUND("(", "main"), 30 30 RIGHTROUND(")", "main"), … … 32 32 SOS("^", "main"), 33 33 LEFTSQUARE("[", "main"), 34 EOS(" !", "main"),34 EOS("$", "main"), 35 35 LEFTCURLY("{", "main"), 36 COMMA(",", "boundedRepetition" , ",", "main"),36 COMMA(",", "boundedRepetition"), 37 37 38 38 -
proto/RE/src/lexicalAnalyzer/Scanner.java
r3072 r3075 72 72 return new Scanner(charStream, 73 73 new WhitespaceTokenRecognizer(charStream, IGNORE), 74 new PunctuatorTokenRecognizer(charStream, LEXTANT, context), 74 75 new CommentTokenRecognizer(charStream, IGNORE, "(?#", ")"), 75 new CharacterTokenRecognizer(charStream, CHARACTER, "(", ")", "[", "|", "?", "*", "+", ".", "^", "!", "\\", "{"), 76 new PunctuatorTokenRecognizer(charStream, LEXTANT, context), 77 new EndOfInputTokenRecognizer(charStream, NONE) 76 new EndOfInputTokenRecognizer(charStream, NONE), 77 new CharacterTokenRecognizer(charStream, CHARACTER) 78 78 ); 79 79 } … … 84 84 return new Scanner(charStream, 85 85 new WhitespaceTokenRecognizer(charStream, IGNORE), 86 new CharacterTokenRecognizer(charStream, CHARACTER, "]", "^", "-", "\\"),87 86 new PunctuatorTokenRecognizer(charStream, LEXTANT, context), 87 new CharacterTokenRecognizer(charStream, CHARACTER), 88 88 new EndOfInputTokenRecognizer(charStream, NONE) 89 89 ); … … 95 95 return new Scanner(charStream, 96 96 new WhitespaceTokenRecognizer(charStream, IGNORE), 97 new PunctuatorTokenRecognizer(charStream, LEXTANT, context), 97 98 new IntegerTokenRecognizer(charStream, INTEGER_CONST), 98 new PunctuatorTokenRecognizer(charStream, LEXTANT, context),99 99 new EndOfInputTokenRecognizer(charStream, NONE) 100 100 ); -
proto/RE/src/lexicalAnalyzer/tokenRecognizers/CharacterTokenRecognizer.java
r3072 r3075 18 18 public class CharacterTokenRecognizer extends TokenRecognizerImp { 19 19 20 private String [] excludedCharacters = null; 21 22 public CharacterTokenRecognizer(BookmarkCharStream input, LexicalType lexicalType, String ... excludedCharacters) { 20 public CharacterTokenRecognizer(BookmarkCharStream input, LexicalType lexicalType) { 23 21 super(input, lexicalType); 24 25 this.excludedCharacters = new String [excludedCharacters.length];26 for(int i=0;i<excludedCharacters.length;i++) {27 this.excludedCharacters[i] = excludedCharacters[i];28 }29 22 } 30 23 31 24 protected Result tryToReadToken() { 32 25 33 if(isEndOfInput(input.peek())) {34 setToken(NullToken.make(lexicalType));35 return Result.NOT_FOUND;36 }37 38 // ?39 if(inputStartsWithAny(excludedCharacters)) {40 return Result.NOT_FOUND;41 }42 43 26 LocatedChar firstChar = input.next(); 44 27 TextLocation location = firstChar.getLocation(); … … 51 34 } 52 35 53 private boolean isEndOfInput(LocatedChar c) {54 return c == LocatedCharStream.FLAG_END_OF_INPUT;55 }56 36 } 57 37 -
proto/RE/src/lexicalAnalyzer/tokenRecognizers/TokenRecognizerImp.java
r3072 r3075 115 115 return result; 116 116 } 117 118 // ?119 protected boolean inputStartsWithAny(String ... lexemes) {120 Bookmark bookmark = input.bookmark();121 boolean result = false;122 117 123 for(int i=0; i<lexemes.length; i++) {124 result = sloppyInputStartsWith(lexemes[i], input.peek().getCharacter());125 126 if(result) {127 break;128 }129 }130 131 input.moveback(bookmark);132 return result;133 }134 135 // ? single character prefix without progressing the input stream136 private boolean sloppyInputStartsWith(String lexeme, char c) {137 for(int i=0; i<lexeme.length(); i++) {138 if(c != lexeme.charAt(i)) {139 return false;140 }141 }142 return true;143 }144 145 118 private boolean sloppyInputStartsWith(String lexeme) { 146 119 for(int i=0; i<lexeme.length(); i++) { -
proto/RE/src/parser/Parser.java
r3072 r3075 435 435 else if( nowReading.isLextant(Lextant.BACKSLASH) ) { 436 436 expect(Lextant.BACKSLASH); 437 } 438 else if( nowReading.isLextant(Lextant.LEFTCURLY) ) { 439 expect(Lextant.LEFTCURLY); 437 440 } 438 441 if(allowCompression) {
Note: See TracChangeset
for help on using the changeset viewer.