-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgrammar.js
47 lines (45 loc) · 1.35 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
module.exports = grammar({
name: 'pyf',
rules: {
// TODO: add the actual grammar rules
source_file: $ => repeat($._text_or_interpolation),
_text_or_interpolation: $ => choice(
$.escape,
$.interpolation,
$.text),
interpolation: $ => seq(
'{',
$.interpolation_content,
optional($.format_string),
'}'
),
interpolation_content: $ => repeat1(choice(/[^:]/, "::")),
text: $ => /[^{}]+/,
escape: $ => choice(
"}}",
"{{",
),
// format_string: $ => /:[^}]+/,
format_string: $ => $.format_spec,
format_spec: $ => seq(":",
optional(seq(optional($.fill), $.align)),
optional($.sign),
optional($.alternate),
optional($.zero),
optional($.width),
optional($.grouping_option),
optional(seq($.precision_dot, $.precision)),
optional($.type),
),
zero: $ => "0",
alternate: $ => "#",
fill: $ => /./,
align: $ => choice("<", ">", "=", "^"),
sign: $ => choice("+", "-", " "),
width: $ => /[0-9]+/,
grouping_option: $ => choice("_", ","),
precision: $ => /[0-9]+/,
precision_dot: $ => ".",
type: $ => choice("b" , "c" , "d" , "e" , "E" , "f" , "F" , "g" , "G" , "n" , "o" , "s" , "x" , "X" , "%"),
}
});