feat: add block command and tests for function, macro, and block
This commit is contained in:
parent
6e51463ef3
commit
686ad8b040
140
corpus/block_commands.txt
Normal file
140
corpus/block_commands.txt
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
======================================================
|
||||||
|
Function definition with no arguments [block_commands]
|
||||||
|
======================================================
|
||||||
|
|
||||||
|
function(fn)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(function_def
|
||||||
|
(function_command
|
||||||
|
(function)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(endfunction_command
|
||||||
|
(endfunction)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
========================================================
|
||||||
|
Function definition with many arguments [block_commands]
|
||||||
|
========================================================
|
||||||
|
|
||||||
|
function(fn arg1 arg2 arg3)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(function_def
|
||||||
|
(function_command
|
||||||
|
(function)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(endfunction_command
|
||||||
|
(endfunction)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
===================================================
|
||||||
|
Macro definition with no arguments [block_commands]
|
||||||
|
===================================================
|
||||||
|
|
||||||
|
macro(fn)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(macro_def
|
||||||
|
(macro_command
|
||||||
|
(macro)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(endmacro_command
|
||||||
|
(endmacro)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
========================================================
|
||||||
|
macro definition with many arguments [block_commands]
|
||||||
|
========================================================
|
||||||
|
|
||||||
|
macro(fn arg1 arg2 arg3)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(macro_def
|
||||||
|
(macro_command
|
||||||
|
(macro)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(endmacro_command
|
||||||
|
(endmacro)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
============================
|
||||||
|
Block scope [block_commands]
|
||||||
|
============================
|
||||||
|
|
||||||
|
block(SCOPE_FOR POLICIES VARIABLES PROPAGATE var)
|
||||||
|
endblock()
|
||||||
|
|
||||||
|
---
|
||||||
|
(source_file
|
||||||
|
(block_def
|
||||||
|
(block_command
|
||||||
|
(block)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
(argument
|
||||||
|
(unquoted_argument)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(endblock_command
|
||||||
|
(endblock)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
|
@ -11,6 +11,8 @@ commands = [
|
||||||
"endfunction",
|
"endfunction",
|
||||||
"macro",
|
"macro",
|
||||||
"endmacro",
|
"endmacro",
|
||||||
|
"block",
|
||||||
|
"endblock"
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = grammar({
|
module.exports = grammar({
|
||||||
|
@ -75,10 +77,14 @@ module.exports = grammar({
|
||||||
endmacro_command: ($) => command($.endmacro, repeat($._untrimmed_argument)),
|
endmacro_command: ($) => command($.endmacro, repeat($._untrimmed_argument)),
|
||||||
macro_def: ($) => seq($.macro_command, repeat($._untrimmed_command_invocation), $.endmacro_command),
|
macro_def: ($) => seq($.macro_command, repeat($._untrimmed_command_invocation), $.endmacro_command),
|
||||||
|
|
||||||
|
block_command: ($) => command($.block, repeat($._untrimmed_argument)),
|
||||||
|
endblock_command: ($) => command($.endblock, repeat($._untrimmed_argument)),
|
||||||
|
block_def: ($) => seq($.block_command, repeat($._untrimmed_command_invocation), $.endblock_command),
|
||||||
|
|
||||||
normal_command: ($) => command($.identifier, repeat($._untrimmed_argument)),
|
normal_command: ($) => command($.identifier, repeat($._untrimmed_argument)),
|
||||||
|
|
||||||
_command_invocation: ($) =>
|
_command_invocation: ($) =>
|
||||||
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def),
|
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def, $.block_def),
|
||||||
_untrimmed_command_invocation: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $._command_invocation),
|
_untrimmed_command_invocation: ($) => choice(/\s/, $.bracket_comment, $.line_comment, $._command_invocation),
|
||||||
|
|
||||||
...commandNames(...commands),
|
...commandNames(...commands),
|
||||||
|
|
|
@ -941,6 +941,88 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"block_command": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "block"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[\\t ]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "("
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_untrimmed_argument"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ")"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"endblock_command": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "endblock"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[\\t ]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "("
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_untrimmed_argument"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ")"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"block_def": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "block_command"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_untrimmed_command_invocation"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "endblock_command"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"normal_command": {
|
"normal_command": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -998,6 +1080,10 @@
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "macro_def"
|
"name": "macro_def"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "block_def"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1070,6 +1156,14 @@
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[eE][nN][dD][mM][aA][cC][rR][oO]"
|
"value": "[eE][nN][dD][mM][aA][cC][rR][oO]"
|
||||||
},
|
},
|
||||||
|
"block": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[bB][lL][oO][cC][kK]"
|
||||||
|
},
|
||||||
|
"endblock": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[eE][nN][dD][bB][lL][oO][cC][kK]"
|
||||||
|
},
|
||||||
"identifier": {
|
"identifier": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[A-Za-z_][A-Za-z0-9_]*"
|
"value": "[A-Za-z_][A-Za-z0-9_]*"
|
||||||
|
|
|
@ -22,6 +22,88 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "block_command",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "argument",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "block",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bracket_comment",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "line_comment",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_command",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bracket_comment",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "endblock_command",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "foreach_loop",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "function_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "if_condition",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "line_comment",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "macro_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "normal_command",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "while_loop",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "cache_var",
|
"type": "cache_var",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -91,6 +173,33 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "endblock_command",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "argument",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "bracket_comment",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "endblock",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "line_comment",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "endforeach_command",
|
"type": "endforeach_command",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -265,6 +374,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_comment",
|
"type": "bracket_comment",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -343,6 +456,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_comment",
|
"type": "bracket_comment",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -436,6 +553,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_comment",
|
"type": "bracket_comment",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -522,6 +643,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_comment",
|
"type": "bracket_comment",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -653,6 +778,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": false,
|
"required": false,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_comment",
|
"type": "bracket_comment",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -788,6 +917,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "block_def",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_comment",
|
"type": "bracket_comment",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -887,6 +1020,10 @@
|
||||||
"type": "\\t",
|
"type": "\\t",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "block",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "bracket_argument",
|
"type": "bracket_argument",
|
||||||
"named": true
|
"named": true
|
||||||
|
@ -903,6 +1040,10 @@
|
||||||
"type": "elseif",
|
"type": "elseif",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "endblock",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "endforeach",
|
"type": "endforeach",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
41158
src/parser.c
41158
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue