MSS
MSS

Reputation: 3633

Antlr4 - Grammar Parsing a log file

I am trying to parse log file entries.

LogGram.g4

grammar LogGram;

logs: log* ;

log : dateformat Identifier '[' className ']' '(' thread ')'
;

thread : Letter+ SPECIAL* LetterOrDigit+
   ;

className : Identifier ('.' Identifier)* ;

dateformat : DATE TMSTAMP ;    

Identifier : Letter LetterOrDigit* ;

Letter : [a-zA-Z$_] ;

LetterOrDigit : [a-zA-Z0-9$_];

SPECIAL : [-@#,;:'"/] ;

DATE : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT ;

TMSTAMP : DIGIT DIGIT ':' DIGIT DIGIT ':' DIGIT DIGIT ',' DIGIT DIGIT DIGIT         
 ;

DIGIT : [0-9] ;

WS : [ \t\r\n\u000C]+ -> skip;

Server.log

2017-08-10 12:50:56,081 ERROR [io.undertow.request] (default task-32)

Console Output while parsing and printing it

line 1:53 mismatched input 'default' expecting Letter
2017-08-10 12:50:56,081 ERROR [io.undertow.request] (defaulttask-32) 

Why is the mismatch line appearing before printing output?

Upvotes: 1

Views: 644

Answers (1)

StanislavL
StanislavL

Reputation: 57381

I am not antlr expert. Just an idea

SPECIAL : [-@#,;:'"/] ;

uses - char which is used to define ranges could you try another way

HYPHEN : '-';
SPECIAL : [@#,;:'"/] | HYPHEN ;

Upvotes: 1

Related Questions