Skip to content

Commit fd3bda0

Browse files
committed
feat: add if statement
1 parent 210dc46 commit fd3bda0

5 files changed

Lines changed: 483134 additions & 389879 deletions

File tree

grammar.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = grammar({
1717
],
1818

1919
rules: {
20-
file: ($) => repeat(seq(optional($._statement_list), $._end)),
20+
file: ($) => repeat(seq(optional(choice($._statement_list, $.if_statement)), $._end)),
2121

2222
_statement_list: ($) => sep1($._command, ';'),
2323

@@ -116,6 +116,26 @@ module.exports = grammar({
116116
$.wait_for_directive,
117117
),
118118

119+
if_statement: ($) =>
120+
seq(
121+
alias(/\%if/, $.if_keyword),
122+
/\s+/,
123+
alias($.string, $.condition),
124+
sep0($._command, ';'),
125+
repeat(seq(
126+
alias(/\%elif/, $.elif_keyword),
127+
/\s+/,
128+
alias($.string, $.condition),
129+
sep0($._command, ';'),
130+
)),
131+
optional(seq(
132+
alias(/\%else/, $.else_keyword),
133+
/\s+/,
134+
sep0($._command, ';'),
135+
)),
136+
alias(/%endif/, $.endif_keyword),
137+
),
138+
119139
_working_directory: ($) =>
120140
option($, "c", alias($._string, $.working_directory)),
121141
attach_session_directive: ($) =>
@@ -911,6 +931,10 @@ function command($, cmd, ...args) {
911931
return seq(alias(cmd, $.command), ...args);
912932
}
913933

934+
function sep0(rule, separator) {
935+
return choice(rule, sep1(rule, separator));
936+
}
937+
914938
function sep1(rule, separator) {
915939
return seq(rule, repeat(seq(separator, rule)));
916940
}

src/grammar.json

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

0 commit comments

Comments
 (0)