TLexer.g revision 324c4644fee44b9898524c09511bd33c3f12e2df
1// This is a sample lexer generated by the ANTLR3 Maven Archetype 2// generator. It shows how to use a superclass to implement 3// support methods and variables you may use in the lexer actions 4// rather than create a messy lexer that has the Java code embedded 5// in it. 6// 7 8lexer grammar TLexer; 9 10options { 11 12 language=Java; // Default 13 14 // Tell ANTLR to make the generated lexer class extend the 15 // the named class, which is where any supporting code and 16 // variables will be placed. 17 // 18 superClass = AbstractTLexer; 19} 20 21// What package should the generated source exist in? 22// 23@header { 24 25 package ${package}; 26} 27 28// This is just a simple lexer that matches the usual suspects 29// 30 31KEYSER : 'Keyser' ; 32SOZE : 'Soze' ; 33 34ADD : '+' ; 35SEMI: ';' ; 36 37ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')* 38 ; 39 40INT : '0'..'9'+ 41 ; 42 43COMMENT 44 : '//' ~('\n'|'\r')* '\r'? '\n' {skip();} 45 | '/*' ( options {greedy=false;} : . )* '*/' {skip();} 46 ; 47 48WS : ( ' ' 49 | '\t' 50 | '\r' 51 | '\n' 52 ) {skip();} 53 ; 54 55STRING 56 : '"' ( ESC_SEQ | ~('\\'|'"') )* '"' 57 ; 58 59fragment 60HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ; 61 62fragment 63ESC_SEQ 64 : '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\') 65 | UNICODE_ESC 66 | OCTAL_ESC 67 ; 68 69fragment 70OCTAL_ESC 71 : '\\' ('0'..'3') ('0'..'7') ('0'..'7') 72 | '\\' ('0'..'7') ('0'..'7') 73 | '\\' ('0'..'7') 74 ; 75 76fragment 77UNICODE_ESC 78 : '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT 79 ; 80 81