@@ -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 ( / \% i f / , $ . if_keyword ) ,
122+ / \s + / ,
123+ alias ( $ . string , $ . condition ) ,
124+ sep0 ( $ . _command , ';' ) ,
125+ repeat ( seq (
126+ alias ( / \% e l i f / , $ . elif_keyword ) ,
127+ / \s + / ,
128+ alias ( $ . string , $ . condition ) ,
129+ sep0 ( $ . _command , ';' ) ,
130+ ) ) ,
131+ optional ( seq (
132+ alias ( / \% e l s e / , $ . else_keyword ) ,
133+ / \s + / ,
134+ sep0 ( $ . _command , ';' ) ,
135+ ) ) ,
136+ alias ( / % e n d i f / , $ . 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+
914938function sep1 ( rule , separator ) {
915939 return seq ( rule , repeat ( seq ( separator , rule ) ) ) ;
916940}
0 commit comments