-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.js
48 lines (36 loc) · 1.04 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
module.exports = grammar({
name: 'racket',
extras: $ => [ $._comment, /\s+/ ],
rules: {
source_file: $ => seq(
$.lang_line,
repeat($.datum)
),
lang_line: $ => seq('#lang', $.symbol),
datum: $ => choice(
$.number,
$.symbol,
$.string,
$.boolean,
$.list_or_pair,
$.quoted_datum
),
boolean: $ => choice($.true_lit, $.false_lit),
true_lit: $ => token(choice("#t", "#T")),
false_lit: $ => token(choice("#f", "#F")),
string: $ => seq('"', /[^"]*/, '"'), // TODO: escaped quotes
quoted_datum: $ => seq(choice("'", "`"), $.datum),
number: $ => token(choice(
/\d+([\./]\d+)?/,
/#x[0-9A-Fa-f]+/
)),
symbol: $ => /[^()\[\]{}",'`;#|\s\\]+/, // TODO: verbatim symbols with |
list_or_pair: $ => choice(
seq("(", repeat(choice($.datum, $.dot)), ")"),
seq("[", repeat(choice($.datum, $.dot)), "]"),
seq("{", repeat(choice($.datum, $.dot)), "}"),
),
dot: $ => ".",
_comment: $ => token(seq(';', /.*/))
}
});