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