How to describe this event log in formal BNF?
Solution 1:
Regarding the productions of EventLog, your choice must depend on the knowledge whether if the starting event is always a nested one or can be unested. If your log consist with many logs of any kind of events, go with:
You can go with:
EventLog ::= event*
event ::= nested-event | unested-event
nested-event ::= nested-event-start unested-event+ nested-event-end
...
Solution 2:
OK, here is the full gocc
BNF, proven to be tested and working:
/* Lexical part */
_digit : '0'-'9' ;
_jobLog : 'M' 'y' 'J' 'o' 'b' ;
_lineend : [ '\r' ] '\n' ;
timestamp
: _digit _digit _digit _digit '-' _digit _digit '-' _digit _digit
' ' _digit _digit ':' _digit _digit ':' _digit _digit '.' { _digit } ' '
;
jobLogStart : _jobLog' ' 'R' 'u' 'n' 'n' 'i' 'n' 'g' ' ' 'j' 'o' 'b' _lineend ;
processLogStart : 'S' 't' 'a' 'r' 't' ' ' 'o' 'f' ' ' { . } _lineend;
taskLogStart : 'S' 't' 'a' 'r' 't' ' ' { . } _lineend;
taskLogEnd : 'E' 'n' 'd' ' ' { . } _lineend;
processLogEnd : 'E' 'n' 'd' ' ' 'o' 'f' ' ' { . } _lineend;
jobLogEnd : _jobLog ' ' 'J' 'o' 'b' ' ' 'c' 'o' 'm' 'p' 'l' 'e' 't' 'e' 'd' _lineend ;
/* Syntax part */
EventLog
: JobLog
;
JobLog
: JobLogStart ProcessLog JobLogEnd
;
ProcessLog
: ProcessLogStart TaskLog ProcessLogEnd
;
TaskLog
: TaskLogStart TaskLogEnd
| TaskLog
TaskLogStart TaskLogEnd
;
TaskLogStart : timestamp taskLogStart ;
TaskLogEnd : timestamp taskLogEnd ;
ProcessLogStart : timestamp processLogStart ;
ProcessLogEnd : timestamp processLogEnd ;
JobLogStart : timestamp jobLogStart ;
JobLogEnd : timestamp jobLogEnd ;
For the completeness, here is the sample data that tested fine with above syntax:
2022-01-18 10:19:41.6007 MyJob Running job
2022-01-18 10:21:24.8027 Start of The Processing 1/18/2022
2022-01-18 10:21:24.8027 Start unested event C
2022-01-18 10:21:24.8027 End unested event C
2022-01-18 10:21:24.8199 Start unested event D with more words
2022-01-18 10:33:21.9885 End unested event D with more words
2022-01-18 10:33:21.9885 Start unested event E with different words
2022-01-18 10:33:21.9885 End unested event E with different words
2022-01-18 10:33:23.9087 Start unested event F with different words
2022-01-18 10:33:40.8774 End unested event F with different words
2022-01-18 10:33:40.8774 Start ...
2022-01-18 10:35:13.4284 End ...
2022-01-18 10:35:13.4445 Start ...
2022-01-18 10:35:13.5237 End ...
2022-01-18 10:35:13.5237 Start ...
2022-01-18 10:35:13.6597 End ...
2022-01-18 10:35:13.6597 Start ...
2022-01-18 10:36:24.4468 End ...
2022-01-18 10:36:24.4468 Start ...
2022-01-18 10:36:24.4554 End ...
2022-01-18 10:36:24.7238 End of The Processing 1/18/2022
2022-01-18 10:36:24.9746 MyJob Job completed