-
Notifications
You must be signed in to change notification settings - Fork 3
/
grammar.js
80 lines (66 loc) · 1.27 KB
/
grammar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module.exports = grammar({
name: 'log',
extras: $ => [
/\s/
],
rules: {
logs: $ => repeat(choice($.begin_header, $.log_line, $.ide_log_line)),
begin_header: $ => seq(repeat1('-'), $._any),
ide_log_line: $ => seq(
$.date,
$.time,
$.priority,
$.thread_name,
$.tag,
$.message
),
thread_name: $ => seq(
'[',
field('thread_name', /[^\]]+/),
']'
),
log_line: $ => seq(
$.date,
$.time,
$.pid,
$.tid,
$.priority,
$.tag,
$.message
),
pid: $ => $._num,
tid: $ => $._num,
date: $ => seq(
optional(seq(
field("year", $._num),
'-'
)),
field("month", $._num),
'-',
field("day", $._num)
),
time: $ => seq(
field("hour", $._num),
':',
field("min", $._num),
':',
field("sec", $._num),
choice('.', ','),
field("ms", $._num)
),
priority: $ => choice(
'E', 'ERROR',
'W', 'WARN',
'I', 'INFO',
'D', 'DEBUG',
'V', 'VERBOSE',
'T', 'TRACE',
'F', 'FINE',
'S', 'SILENT',
),
tag: $ => /\S+:/,
message: $ => $._any,
_any: $ => /\S.*\S/,
_num: $ => /[0-9]+/
}
});