-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
118 lines (88 loc) · 2.89 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
function optseq() {
return optional(prec.left(seq.apply(null, arguments)));
}
function repseq() {
return repeat(prec.left(seq.apply(null, arguments)));
}
function sep1(separator, rule) {
return prec.left(seq(
rule,
repeat(prec.left(seq(separator, rule)))
));
}
const rules = {
source_file: $ => $.value_change_dump_definitions,
value_change_dump_definitions: $ => seq(
repeat1($.declaration_command),
seq('$enddefinitions', '$end'),
repeat1($.simulation_command)
),
declaration_command: $ => choice(
seq('$comment', /[^$]*/, '$end'),
seq('$date', /[^$]*/, '$end'),
seq('$scope', optseq($.scope_type, $.scope_identifier), '$end'),
seq('$timescale', optseq($.time_number, $.time_unit), '$end'),
seq('$upscope', '$end'),
seq('$var', optseq($.var_type, $.size, $.identifier_code, $.reference), '$end'),
seq('$version', /[^$]*/, '$end')
),
simulation_command: $ => choice(
seq('$dumpall', repeat($.value_change), '$end'),
seq('$dumpoff', repeat($.value_change), '$end'),
seq('$dumpon', repeat($.value_change), '$end'),
seq('$dumpvars', repeat($.value_change), '$end'),
seq('$comment', /.*/, '$end'),
$.simulation_time,
$.value_change
),
scope_type: $ => choice('begin', 'fork', 'function', 'module', 'task'),
time_number: $ => choice('1', '10', '100'),
time_unit: $ => choice('s', 'ms', 'us', 'ns', 'ps', 'fs'),
var_type: $ => choice(
'event', 'integer', 'parameter', 'real', 'realtime', 'reg', 'supply0', 'supply1', 'time',
'tri', 'triand', 'trior', 'trireg', 'tri0', 'tri1', 'wand', 'wire', 'wor'
),
simulation_time: $ => seq('#', $.decimal_number),
value_change: $ => choice(
$.scalar_value_change,
$.vector_value_change
),
scalar_value_change: $ => seq($.value, $.identifier_code),
value: $ => /[01xXzZ]/,
vector_value_change: $ => choice(
seq(/[bB]/, $.binary_number, $.identifier_code),
seq(/[rR]/, $.real_number, $.identifier_code)
),
identifier_code: $ => /[!-~]+/,
size: $ => $.decimal_number,
reference: $ => seq(
$.identifier,
optional(choice(
seq('[', $._bit_select_index, ']'),
seq('[', $._msb_index, ':', $._lsb_index, ']')
))
),
index: $ => $.decimal_number,
_bit_select_index: $ => $.index,
_msb_index: $ => $.index,
_lsb_index: $ => $.index,
scope_identifier: $ => /[a-zA-Z0-9_$]+/,
comment_text: $ => /.*/,
date_text: $ => /.*/,
version_text: $ => /.*/,
system_task: $ => /\$.*/,
decimal_number: $ => token(/[0-9]+/),
binary_number: $ => token(/[01xz]+/),
real_number: $ => token(/[0-9][0-9_]*\.[0-9][0-9_]*/), // %.16g printf() format. 64-bit IEEE 754 double-precision number
identifier: $ => /[!-~]+/
};
module.exports = grammar({
name: 'vcd',
rules: rules,
extras: $ => [/\s/],
externals: $ => []
});
/* eslint camelcase: 0 */
/* eslint no-undef: 0 */
/* eslint no-unused-vars: 0 */