Skip to content

Commit 56348ac

Browse files
feat: implement grammar
1 parent 7b5effd commit 56348ac

File tree

15 files changed

+3960
-3
lines changed

15 files changed

+3960
-3
lines changed

Cargo.lock

Lines changed: 199 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust/lib.rs

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

grammar.js

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,100 @@
1010
module.exports = grammar({
1111
name: "cst",
1212

13+
extras: _ => [],
14+
1315
rules: {
14-
// TODO: add the actual grammar rules
15-
source_file: $ => "hello"
16+
cst: $ => seq(
17+
optional($._eol),
18+
repeat($._line),
19+
optional($._eol)
20+
),
21+
22+
_line: $ => seq(
23+
optional($.range),
24+
repeat1($._space),
25+
choice(
26+
$.node,
27+
$.text,
28+
$.literal,
29+
$.error,
30+
$.missing
31+
),
32+
$._eol
33+
),
34+
35+
range: $ => seq(
36+
field("start", $.position),
37+
repeat1($._space),
38+
"-",
39+
$._space,
40+
field("end", $.position)
41+
),
42+
43+
position: $ => seq(
44+
field("row", $.number),
45+
":",
46+
field("column", $.number)
47+
),
48+
49+
node: $ => seq(
50+
optional($.field),
51+
optional($._mark),
52+
alias($._identifier, $.kind),
53+
choice(
54+
optional($._space),
55+
seq($._space, $.text)
56+
)
57+
),
58+
59+
text: $ => seq(
60+
"`",
61+
$.content,
62+
"`"
63+
),
64+
65+
literal: $ => seq(
66+
"\"",
67+
$.content,
68+
"\""
69+
),
70+
71+
error: $ => seq(
72+
$._mark,
73+
"ERROR",
74+
choice(
75+
optional($._space),
76+
seq($._space, $.text)
77+
)
78+
),
79+
80+
missing: $ => seq(
81+
"MISSING",
82+
token.immediate(":"),
83+
$._space,
84+
$.literal
85+
),
86+
87+
field: $ => seq(
88+
field("name", $._identifier),
89+
token.immediate(":"),
90+
$._space
91+
),
92+
93+
content: $ => repeat1(
94+
choice(/[^\r\n]/, field("escape", $._escape))
95+
),
96+
97+
_identifier: _ => /[\w-][\w.-]*/,
98+
99+
_escape: _ => /\\[abeEfnrtv\\]/,
100+
101+
number: _ => /\d+/,
102+
103+
_mark: _ => "\u2022",
104+
105+
_space: _ => / /,
106+
107+
_eol: _ => /[\r\n]|\r\n/
16108
}
17109
});

0 commit comments

Comments
 (0)