Stop treating command argument as special:
- Planning to move the highlight responsibility to the highlight query - Stop trying to parse frequently used commands - One test is failing because of `unquoted_argument`, planning to fix
This commit is contained in:
parent
1669ad95a0
commit
e3dfc2cdca
|
@ -6,8 +6,8 @@ message([[]])
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
@ -20,8 +20,8 @@ message([[an argument]])
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
@ -34,8 +34,8 @@ message([[first argument]] [[second argument]])
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (bracket_argument))
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
|
@ -52,8 +52,8 @@ message(
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (bracket_argument))
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
|
@ -69,8 +69,8 @@ with line break
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
@ -85,8 +85,8 @@ with line break ]==]
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
|
|
@ -17,8 +17,9 @@ message(STATUS #[[Some comment]] "comment is next" #[[Some comment]])
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
(bracket_comment)
|
||||
(argument (quoted_argument (quoted_element)))
|
||||
(bracket_comment)
|
||||
|
@ -46,8 +47,9 @@ message #Some other line comment
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
(line_comment)
|
||||
(argument (unquoted_argument))
|
||||
(line_comment)
|
||||
|
|
|
@ -79,7 +79,10 @@ endif()
|
|||
(if)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(message_command (message))
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endif_command (endif))
|
||||
)
|
||||
)
|
||||
|
|
|
@ -7,8 +7,8 @@ message()
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -21,8 +21,8 @@ message( )
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -37,8 +37,8 @@ message(
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -51,15 +51,16 @@ message(STATUS [=[Some argument ]==] ]=] )
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
||||
=============================================================
|
||||
==============================================================
|
||||
Message with STATUS and bracket argument and newline [message]
|
||||
=============================================================
|
||||
==============================================================
|
||||
|
||||
message(STATUS
|
||||
[=[Some argument
|
||||
|
@ -68,8 +69,9 @@ message(STATUS
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
|
|
@ -6,8 +6,8 @@ message("")
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (quoted_argument))
|
||||
)
|
||||
)
|
||||
|
@ -20,8 +20,8 @@ message("An argument")
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (quoted_argument (quoted_element)))
|
||||
)
|
||||
)
|
||||
|
@ -34,8 +34,8 @@ message("First argument" "Second argument")
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (quoted_argument (quoted_element)))
|
||||
(argument (quoted_argument (quoted_element)))
|
||||
)
|
||||
|
@ -50,8 +50,8 @@ with line break")
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (quoted_argument (quoted_element)))
|
||||
)
|
||||
)
|
||||
|
@ -64,8 +64,8 @@ message("${var}")
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(quoted_argument
|
||||
(quoted_element
|
||||
|
@ -84,8 +84,8 @@ message("${var} ${var}")
|
|||
|
||||
---
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(quoted_argument
|
||||
(quoted_element
|
||||
|
|
|
@ -7,8 +7,9 @@ message(STATUS)
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -21,8 +22,8 @@ message(STATUS Hello)
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
)
|
||||
|
@ -37,8 +38,14 @@ STATUS)
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command (message))
|
||||
(message_command (message))
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
)
|
||||
============================================================
|
||||
Command invocations with escape sequence [unquoted_argument]
|
||||
|
@ -50,8 +57,14 @@ STATUS)
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command (message))
|
||||
(message_command (message))
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
)
|
||||
|
||||
========================================
|
||||
|
@ -61,8 +74,8 @@ message(${var_ref})
|
|||
---
|
||||
|
||||
(source_file
|
||||
(message_command
|
||||
(message)
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument
|
||||
(unquoted_argument
|
||||
(variable_ref (normal_var (variable)))
|
||||
|
|
89
grammar.js
89
grammar.js
|
@ -11,69 +11,6 @@ commands = [
|
|||
"endfunction",
|
||||
"macro",
|
||||
"endmacro",
|
||||
"message",
|
||||
];
|
||||
if_args = [
|
||||
"1",
|
||||
"ON",
|
||||
"YES",
|
||||
"TRUE",
|
||||
"Y",
|
||||
"0",
|
||||
"OFF",
|
||||
"NO",
|
||||
"FALSE",
|
||||
"N",
|
||||
"IGNORE",
|
||||
"NOTFOUND",
|
||||
"NOT",
|
||||
"AND",
|
||||
"OR",
|
||||
"COMMAND",
|
||||
"POLICY",
|
||||
"TARGET",
|
||||
"TEST",
|
||||
"DEFINED",
|
||||
"CACHE",
|
||||
"ENV",
|
||||
"IN_LIST",
|
||||
"EXISTS",
|
||||
"IS_NEWER_THAN",
|
||||
"IS_DIRECTORY",
|
||||
"IS_SYMLINK",
|
||||
"IS_ABSOLUTE",
|
||||
"MATCHES",
|
||||
"LESS",
|
||||
"GREATER",
|
||||
"EQUAL",
|
||||
"LESS_EQUAL",
|
||||
"GREATER_EQUAL",
|
||||
"STRLESS",
|
||||
"STRGREATER",
|
||||
"STREQUAL",
|
||||
"STRLESS_EQUAL",
|
||||
"STRGREATER_EQUAL",
|
||||
"VERSION_LESS",
|
||||
"VERSION_GREATER",
|
||||
"VERSION_EQUAL",
|
||||
"VERSION_LESS_EQUAL",
|
||||
"VERSION_GREATER_EQUAL",
|
||||
];
|
||||
foreach_args = ["IN", "RANGE", "ZIP_LISTS", "LISTS", "ITEMS"];
|
||||
message_args = [
|
||||
"FATAL_ERROR",
|
||||
"SEND_ERROR",
|
||||
"WARNING",
|
||||
"AUTHOR_WARNING",
|
||||
"DEPRECATION",
|
||||
"NOTICE",
|
||||
"STATUS",
|
||||
"VERBOSE",
|
||||
"DEBUG",
|
||||
"TRACE",
|
||||
"CHECK_START",
|
||||
"CHECK_PASS",
|
||||
"CHECK_FAIL",
|
||||
];
|
||||
|
||||
module.exports = grammar({
|
||||
|
@ -103,19 +40,19 @@ module.exports = grammar({
|
|||
|
||||
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, /[^\s\n\r()#\"\\]/, $.escape_sequence))),
|
||||
|
||||
if_command: ($) => command($.if, repeat(choice($.argument, ...if_args))),
|
||||
elseif_command: ($) => command($.elseif, repeat(choice($.argument, ...if_args))),
|
||||
else_command: ($) => command($.else, optional(choice($.argument, ...if_args))),
|
||||
endif_command: ($) => command($.endif, optional(choice($.argument, ...if_args))),
|
||||
if_command: ($) => command($.if, repeat(choice($.argument))),
|
||||
elseif_command: ($) => command($.elseif, repeat(choice($.argument))),
|
||||
else_command: ($) => command($.else, optional(choice($.argument))),
|
||||
endif_command: ($) => command($.endif, optional(choice($.argument))),
|
||||
if_condition: ($) =>
|
||||
seq($.if_command, repeat(choice($._command_invocation, $.elseif_command, $.else_command)), $.endif_command),
|
||||
|
||||
foreach_command: ($) => command($.foreach, repeat(choice($.argument, ...foreach_args))),
|
||||
foreach_command: ($) => command($.foreach, repeat(choice($.argument))),
|
||||
endforeach_command: ($) => command($.endforeach, optional($.argument)),
|
||||
foreach_loop: ($) => seq($.foreach_command, repeat($._command_invocation), $.endforeach_command),
|
||||
|
||||
while_command: ($) => command($.while, repeat(choice($.argument, ...if_args))),
|
||||
endwhile_command: ($) => command($.endwhile, optional(choice($.argument, ...if_args))),
|
||||
while_command: ($) => command($.while, repeat(choice($.argument))),
|
||||
endwhile_command: ($) => command($.endwhile, optional(choice($.argument))),
|
||||
while_loop: ($) => seq($.while_command, repeat($._command_invocation), $.endwhile_command),
|
||||
|
||||
function_command: ($) => command($.function, repeat($.argument)),
|
||||
|
@ -126,20 +63,10 @@ module.exports = grammar({
|
|||
endmacro_command: ($) => command($.endmacro, repeat($.argument)),
|
||||
macro_def: ($) => seq($.macro_command, repeat($._command_invocation), $.endmacro_command),
|
||||
|
||||
message_command: ($) => command($.message, optional(repeat(choice($.argument, ...message_args)))),
|
||||
|
||||
normal_command: ($) => command($.identifier, repeat($.argument)),
|
||||
|
||||
_command_invocation: ($) =>
|
||||
choice(
|
||||
$.normal_command,
|
||||
$.if_condition,
|
||||
$.foreach_loop,
|
||||
$.while_loop,
|
||||
$.function_def,
|
||||
$.macro_def,
|
||||
$.message_command
|
||||
),
|
||||
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def),
|
||||
|
||||
...commandNames(...commands),
|
||||
identifier: (_) => /[A-Za-z_][A-Za-z0-9_]*/,
|
||||
|
|
1173
src/grammar.json
1173
src/grammar.json
File diff suppressed because it is too large
Load diff
|
@ -241,10 +241,6 @@
|
|||
"type": "macro_def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
|
@ -307,10 +303,6 @@
|
|||
"type": "macro_def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
|
@ -381,10 +373,6 @@
|
|||
"type": "macro_def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
|
@ -447,10 +435,6 @@
|
|||
"type": "macro_def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
|
@ -462,25 +446,6 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "argument",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true,
|
||||
|
@ -573,10 +538,6 @@
|
|||
"type": "macro_def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
|
@ -692,10 +653,6 @@
|
|||
"type": "macro_def",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
|
@ -735,254 +692,6 @@
|
|||
"type": ")",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "0",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "1",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "AND",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "AUTHOR_WARNING",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "CACHE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "CHECK_FAIL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "CHECK_PASS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "CHECK_START",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "COMMAND",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "DEBUG",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "DEFINED",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "DEPRECATION",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ENV",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "EXISTS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "FALSE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "FATAL_ERROR",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "GREATER",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "GREATER_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IGNORE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IN",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IN_LIST",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IS_ABSOLUTE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IS_DIRECTORY",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IS_NEWER_THAN",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IS_SYMLINK",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ITEMS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "LESS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "LESS_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "LISTS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "MATCHES",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "N",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "NO",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "NOT",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "NOTFOUND",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "NOTICE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "OFF",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ON",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "OR",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "POLICY",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "RANGE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "SEND_ERROR",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STATUS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STREQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STRGREATER",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STRGREATER_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STRLESS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "STRLESS_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "TARGET",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "TEST",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "TRACE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "TRUE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VERBOSE",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VERSION_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VERSION_GREATER",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VERSION_GREATER_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VERSION_LESS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "VERSION_LESS_EQUAL",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "WARNING",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "Y",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "YES",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "ZIP_LISTS",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "\\n",
|
||||
"named": false
|
||||
|
@ -1055,10 +764,6 @@
|
|||
"type": "macro",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "message",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "while",
|
||||
"named": true
|
||||
|
|
23008
src/parser.c
23008
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue