-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgrammar.js
39 lines (33 loc) · 1.09 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
///////////////////////////////////////////////////////////////////////////////
//
// Tokens
//
///////////////////////////////////////////////////////////////////////////////
const PARENS_LEFT = "(";
const PARENS_RIGHT = ")";
///////////////////////////////////////////////////////////////////////////////
//
// Precedences
//
///////////////////////////////////////////////////////////////////////////////
const PREC = {};
///////////////////////////////////////////////////////////////////////////////
//
// Combinators
//
///////////////////////////////////////////////////////////////////////////////
const delim = (open, x, close) => seq(open, x, close);
///////////////////////////////////////////////////////////////////////////////
//
// Grammar
//
///////////////////////////////////////////////////////////////////////////////
module.exports = grammar({
name: "sexp",
rules: {
sexp: ($) => $._sexp,
_sexp: ($) => choice($.atom, $.list),
atom: ($) => /[_@a-zA-Z0-9\xC0-\xD6\xD8-\xDE\xDF-\xF6\xF8-\xFF:-]+/,
list: ($) => delim(PARENS_LEFT, repeat($._sexp), PARENS_RIGHT),
},
});