Add while and its test case

This commit is contained in:
Uy Ha 2021-06-17 22:43:12 +02:00
parent 169a1d2622
commit 1a4e86b5bf
5 changed files with 8064 additions and 5527 deletions

View file

@ -10,8 +10,8 @@ TODO
- Control structures
- if()/elseif()/else()endif()
- foreach()/endforeach()
- if()/elseif()/else()endif() [DONE]
- foreach()/endforeach() [DONE]
- while()/endwhile()
- Command definitions

View file

@ -76,8 +76,8 @@ module.exports = grammar({
if_command: ($) => command($.if, args(choice($.argument, ...if_args))),
elseif_command: ($) => command($.elseif, args(choice($.argument, ...if_args))),
else_command: ($) => command($.else, optional(args(choice($.argument, ...if_args)))),
endif_command: ($) => command($.endif, optional(args(choice($.argument, ...if_args)))),
else_command: ($) => command($.else, optional(choice($.argument, ...if_args))),
endif_command: ($) => command($.endif, optional(choice($.argument, ...if_args))),
if_condition: ($) =>
seq($.if_command, repeat(choice($._command_invocation, $.elseif_command, $.else_command)), $.endif_command),
@ -85,11 +85,15 @@ module.exports = grammar({
endforeach_command: ($) => command($.endforeach, optional($.argument)),
foreach_loop: ($) => seq($.foreach_command, repeat($._command_invocation), $.endforeach_command),
while_command: ($) => command($.while, args(choice($.argument, ...if_args))),
endwhile_command: ($) => command($.endwhile, optional(choice($.argument, ...if_args))),
while_loop: ($) => seq($.while_command, repeat($._command_invocation), $.endwhile_command),
normal_command: ($) => command($.identifier, optional(args($.argument))),
_command_invocation: ($) => choice($.normal_command, $.if_condition, $.foreach_loop),
_command_invocation: ($) => choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop),
...commandNames("if", "elseif", "else", "endif", "foreach", "endforeach"),
...commandNames("if", "elseif", "else", "endif", "foreach", "endforeach", "while", "endwhile"),
identifier: (_) => /[A-Za-z_][A-Za-z0-9_]*/,
integer: (_) => /[+-]*\d+/,
},

File diff suppressed because it is too large Load diff

View file

@ -133,6 +133,25 @@
]
}
},
{
"type": "endwhile_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "endwhile",
"named": true
}
]
}
},
{
"type": "env_var",
"named": true,
@ -199,6 +218,10 @@
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
@ -257,6 +280,10 @@
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
@ -348,6 +375,10 @@
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
@ -409,6 +440,60 @@
]
}
},
{
"type": "while_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "while",
"named": true
}
]
}
},
{
"type": "while_loop",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "endwhile_command",
"named": true
},
{
"type": "foreach_loop",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "normal_command",
"named": true
},
{
"type": "while_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
},
{
"type": "\"",
"named": false
@ -673,6 +758,10 @@
"type": "endif",
"named": true
},
{
"type": "endwhile",
"named": true
},
{
"type": "foreach",
"named": true
@ -685,6 +774,10 @@
"type": "if",
"named": true
},
{
"type": "while",
"named": true
},
{
"type": "{",
"named": false

11514
src/parser.c

File diff suppressed because it is too large Load diff