[antlr-interest] Antlr newbie trying to make Sloc counter with antlr
tjtaill36
tjtaill36 at gmail.com
Fri Feb 25 06:53:02 PST 2011
Hi all,
I am new to antlr and I am trying use it to gather metrics about code
starting with the low hanging fruit I wanted to count slocs so I made the
following grammar but it doesn't seem to work correctly any advice would be
appreciated. Also can I use the just a lexer by itself or do I absolutely
need a Parser as well ?
lexer grammar Slocs;
options {
language = Java;
filter=true;
}
@lexer::header {
package code.metrics;
}
@lexer::members {
public int slocs = 0;
}
COMMENT:
('/*' .* '*/' | '//' ~('\r' | '\n')* ) {$channel=HIDDEN;}
;
SLOC:
.* ';' {slocs++;}
;
LINE:
.* NEWLINE {$channel=HIDDEN;}
;
fragment NEWLINE:
'\r'? '\n'
;
Thanks
Troy
More information about the antlr-interest
mailing list