1lexer grammar t020fuzzy; 2options { 3 language=JavaScript; 4 filter=true; 5} 6 7@members { 8this.outbuf = []; 9this.output = function(msg) { 10 this.outbuf.push(msg); 11}; 12} 13 14IMPORT 15 : 'import' WS name=QIDStar WS? ';' 16 ; 17 18/** Avoids having "return foo;" match as a field */ 19RETURN 20 : 'return' (options {greedy=false;}:.)* ';' 21 ; 22 23CLASS 24 : 'class' WS name=ID WS? ('extends' WS QID WS?)? 25 ('implements' WS QID WS? (',' WS? QID WS?)*)? '{' 26 {this.output("found class "+$name.text+"\n");} 27 ; 28 29METHOD 30 : TYPE WS name=ID WS? '(' ( ARG WS? (',' WS? ARG WS?)* )? ')' WS? 31 ('throws' WS QID WS? (',' WS? QID WS?)*)? '{' 32 {this.output("found method "+$name.text+"\n");} 33 ; 34 35FIELD 36 : TYPE WS name=ID '[]'? WS? (';'|'=') 37 {this.output("found var "+$name.text+"\n");} 38 ; 39 40STAT: ('if'|'while'|'switch'|'for') WS? '(' ; 41 42CALL 43 : name=QID WS? '(' 44 {this.output("found call "+$name.text+"\n");} 45 ; 46 47COMMENT 48 : '/*' (options {greedy=false;} : . )* '*/' 49 {this.output("found comment "+this.getText()+"\n");} 50 ; 51 52SL_COMMENT 53 : '//' (options {greedy=false;} : . )* '\n' 54 {this.output("found // comment "+this.getText()+"\n");} 55 ; 56 57STRING 58 : '"' (options {greedy=false;}: ESC | .)* '"' 59 ; 60 61CHAR 62 : '\'' (options {greedy=false;}: ESC | .)* '\'' 63 ; 64 65WS : (' '|'\t'|'\n')+ 66 ; 67 68fragment 69QID : ID ('.' ID)* 70 ; 71 72/** QID cannot see beyond end of token so using QID '.*'? somewhere won't 73 * ever match since k=1 lookahead in the QID loop of '.' will make it loop. 74 * I made this rule to compensate. 75 */ 76fragment 77QIDStar 78 : ID ('.' ID)* '.*'? 79 ; 80 81fragment 82TYPE: QID '[]'? 83 ; 84 85fragment 86ARG : TYPE WS ID 87 ; 88 89fragment 90ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')* 91 ; 92 93fragment 94ESC : '\\' ('"'|'\''|'\\') 95 ; 96