我有一个非常简单的事件日志格式,只是我很难用BNF(对于gocc
(来描述它。
这是我的简单事件日志格式:
timestamp nested-event-A Running
timestamp Start of nested-event-B
timestamp Start unested-event-C
timestamp End unested-event-C
timestamp Start unested-event-D
timestamp End unested-event-D
timestamp Start unested-event-E
timestamp End unested-event-E
. . .
timestamp End of nested-event-B
timestamp nested-event-A completed
假设语法从EventLog
开始,我甚至在开始第一个BNF时遇到了困难。
我可以从开始吗
EventLog ::= nested-event | unested-event
或者,
我可以从开始吗
EventLog ::= nested-event
nested-event ::= nested-event-start unested-event+ nested-event-end
你认为最好的描述方式是什么?
关于EventLog的生成,您的选择必须取决于启动事件是否始终是嵌套事件或是否可以取消嵌套。如果您的日志包含许多任何类型事件的日志,请使用:
您可以使用:
EventLog ::= event*
event ::= nested-event | unested-event
nested-event ::= nested-event-start unested-event+ nested-event-end
...
好的,这是完整的gocc
BNF,经过测试并有效:
/* 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 ;
为了完整起见,以下是使用上述语法测试良好的示例数据:
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