-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
41 lines (36 loc) · 1.11 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
module.exports = grammar({
name: "satysfi",
extras: $ => [$.comment, /\s/],
rules: {
space: $ => /[ \t]/,
break: $ => /[\n\r]/,
nonbreak: $ => /[^\n\r]/,
nzdigit: $ => /[1-9]/,
digit: $ => choice("0", $.nzdigit),
hex: $ => choice($.digit, /[A-F]/),
capital: $ => /[A-Z]/,
small: $ => /[a-z]/,
latin: $ => choice($.small, $.capital),
item: $ => repeat1("*"),
identifier: $ => seq($.small, repeat(choice($.digit, $.latin, "-"))),
constructor: $ => seq($.capital, repeat(choice($.digit, $.latin, "-"))),
symbol: $ => choice(/[ -@]/, /[[-`]/, /[{-~]/),
opsymbol: $ => /[-+*/^&|!:=<>~'.?]/,
str: $ => /[^ \t\n\r@`\\{}<>%|*$#;]/,
mathsymbol: $ => /[-+*/:=<>~'.,?`]/,
int: $ => choice(
$.digit,
seq($.nzdigit, repeat1($.digit)),
seq(/0[xX]/, repeat1($.hex))
),
float: $ => choice(
seq(repeat1($.digit), ".", repeat($.digit)),
seq(".", repeat1($.digit))
),
length: $ => seq(
choice($.digit, seq($.nzdigit, repeat1($.digit)), $.float),
choice("pt", "mm", "cm", "inch")
),
comment: $ => /%.*/
}
});