-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.js
46 lines (36 loc) · 1.05 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
module.exports = grammar({
name: 'gaptst',
inline: ($) => [$._statement],
externals: ($) => [$.output_line],
rules: {
test_file: ($) => repeat(choice($.comment, $.test_case, $._statement)),
_statement: ($) =>
choice($.local_statement, $.exec_statement, $.if_statement),
if_statement: ($) =>
seq(
'#@if',
field('condition', $.gap_expression),
repeat(choice($.comment, $.test_case)),
optional($.else_clause),
'#@fi',
'\n',
),
else_clause: ($) =>
seq('#@else', '\n', repeat(choice($.comment, $.test_case))),
local_statement: ($) => seq('#@local', $.gap_expression),
exec_statement: ($) => seq('#@exec', $.gap_expression),
test_case: ($) =>
seq(
'gap> ',
alias($.gap_expression, $.input_line),
repeat(
choice(
seq('> ', alias($.gap_expression, $.input_line)),
$.output_line,
),
),
),
comment: (_) => /\n?#([^@\n].*)?\n*/,
gap_expression: (_) => /[^\n]*?\n?/,
},
});