-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
54 lines (36 loc) · 1.24 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
module.exports = grammar({
name: 'amethyst',
word: $ => $.identifier,
rules: {
source_file: $ => repeat($.sexpr),
sexpr_call: $ => seq(
'(',
field('func', $.identifier),
repeat(choice($.value, $.quoted, $.key)),
')'
),
sexpr_not_call: $ => seq(
'(',
repeat(choice($.value, $.quoted, $.key)),
')'
),
sexpr: $ => choice($.sexpr_call, $.sexpr_not_call),
value: $ => choice($.number, $.character, $.boolean, $.string, $.sexpr, $.identifier),
quoted: $ => seq('\'', $.value),
identifier: $ => /:|[a-zA-Z\-_=+|\/?~!@$%^&*<>][0-9a-zA-Z\-_=+|\/?~!@$%^&*<>]*/,
key: $ => /:[a-zA-Z\-_=+|\/?~!@$%^&*<>][0-9a-zA-Z\-_=+|\/?~!@$%^&*<>]*/,
number: $ => /[0-9]+|0x[0-9a-fA-F]+|0b[01]+|0o[0-7]+|[0-9]+((\.[0-9]+)([eE][+\-]?[0-9]+)?|[eE][+\-]?[0-9]+)/,
boolean: $ => choice('true', 'false'),
string: $ => /"([^\\"]|\\.)*"/,
character: $ => /'([^\\]|\\.)'/,
block_comment: $ => seq(
'/*',
repeat(choice(/./, $.block_comment)),
'*/'
),
line_comment: $ => /\/\/.*\n/,
},
conflicts: $ => [[$.sexpr_call], [$.sexpr_call, $.sexpr_not_call]],
extras: $ => [/\s|\n/, $.line_comment, $.block_comment],
inline: $ => [$.value, $.sexpr],
});