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:
Uy Ha 2021-06-27 21:20:09 +02:00
parent 1669ad95a0
commit e3dfc2cdca
10 changed files with 8828 additions and 15893 deletions

View file

@ -6,8 +6,8 @@ message([[]])
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (bracket_argument)) (argument (bracket_argument))
) )
) )
@ -20,8 +20,8 @@ message([[an argument]])
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (bracket_argument)) (argument (bracket_argument))
) )
) )
@ -34,8 +34,8 @@ message([[first argument]] [[second argument]])
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (bracket_argument)) (argument (bracket_argument))
(argument (bracket_argument)) (argument (bracket_argument))
) )
@ -52,8 +52,8 @@ message(
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (bracket_argument)) (argument (bracket_argument))
(argument (bracket_argument)) (argument (bracket_argument))
) )
@ -69,8 +69,8 @@ with line break
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (bracket_argument)) (argument (bracket_argument))
) )
) )
@ -85,8 +85,8 @@ with line break ]==]
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (bracket_argument)) (argument (bracket_argument))
) )
) )

View file

@ -17,8 +17,9 @@ message(STATUS #[[Some comment]] "comment is next" #[[Some comment]])
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (unquoted_argument))
(bracket_comment) (bracket_comment)
(argument (quoted_argument (quoted_element))) (argument (quoted_argument (quoted_element)))
(bracket_comment) (bracket_comment)
@ -39,15 +40,16 @@ Line comment [comment]
=================================== ===================================
Message with Line comment [comment] Message with Line comment [comment]
=================================== ===================================
message(STATUS # Some line comment message(STATUS #Some line comment
message #Some other line comment message #Some other line comment
) )
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (unquoted_argument))
(line_comment) (line_comment)
(argument (unquoted_argument)) (argument (unquoted_argument))
(line_comment) (line_comment)

View file

@ -79,7 +79,10 @@ endif()
(if) (if)
(argument (unquoted_argument)) (argument (unquoted_argument))
) )
(message_command (message)) (normal_command
(identifier)
(argument (unquoted_argument))
)
(endif_command (endif)) (endif_command (endif))
) )
) )

View file

@ -7,8 +7,8 @@ message()
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
) )
) )
@ -21,8 +21,8 @@ message( )
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
) )
) )
@ -37,8 +37,8 @@ message(
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
) )
) )
@ -51,15 +51,16 @@ message(STATUS [=[Some argument ]==] ]=] )
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (unquoted_argument))
(argument (bracket_argument)) (argument (bracket_argument))
) )
) )
============================================================= ==============================================================
Message with STATUS and bracket argument and newline [message] Message with STATUS and bracket argument and newline [message]
============================================================= ==============================================================
message(STATUS message(STATUS
[=[Some argument [=[Some argument
@ -68,8 +69,9 @@ message(STATUS
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (unquoted_argument))
(argument (bracket_argument)) (argument (bracket_argument))
) )
) )

View file

@ -6,8 +6,8 @@ message("")
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (quoted_argument)) (argument (quoted_argument))
) )
) )
@ -20,8 +20,8 @@ message("An argument")
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (quoted_argument (quoted_element))) (argument (quoted_argument (quoted_element)))
) )
) )
@ -34,8 +34,8 @@ message("First argument" "Second argument")
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (quoted_argument (quoted_element))) (argument (quoted_argument (quoted_element)))
(argument (quoted_argument (quoted_element))) (argument (quoted_argument (quoted_element)))
) )
@ -50,8 +50,8 @@ with line break")
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (quoted_argument (quoted_element))) (argument (quoted_argument (quoted_element)))
) )
) )
@ -64,8 +64,8 @@ message("${var}")
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (argument
(quoted_argument (quoted_argument
(quoted_element (quoted_element
@ -84,8 +84,8 @@ message("${var} ${var}")
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (argument
(quoted_argument (quoted_argument
(quoted_element (quoted_element

View file

@ -7,8 +7,9 @@ message(STATUS)
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (unquoted_argument))
) )
) )
@ -21,8 +22,8 @@ message(STATUS Hello)
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (unquoted_argument)) (argument (unquoted_argument))
) )
) )
@ -37,9 +38,15 @@ STATUS)
--- ---
(source_file (source_file
(message_command (message)) (normal_command
(message_command (message)) (identifier)
(argument (unquoted_argument))
) )
(normal_command
(identifier)
(argument (unquoted_argument))
)
)
============================================================ ============================================================
Command invocations with escape sequence [unquoted_argument] Command invocations with escape sequence [unquoted_argument]
============================================================ ============================================================
@ -50,8 +57,14 @@ STATUS)
--- ---
(source_file (source_file
(message_command (message)) (normal_command
(message_command (message)) (identifier)
(argument (unquoted_argument))
)
(normal_command
(identifier)
(argument (unquoted_argument))
)
) )
======================================== ========================================
@ -61,8 +74,8 @@ message(${var_ref})
--- ---
(source_file (source_file
(message_command (normal_command
(message) (identifier)
(argument (argument
(unquoted_argument (unquoted_argument
(variable_ref (normal_var (variable))) (variable_ref (normal_var (variable)))

View file

@ -11,69 +11,6 @@ commands = [
"endfunction", "endfunction",
"macro", "macro",
"endmacro", "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({ module.exports = grammar({
@ -103,19 +40,19 @@ module.exports = grammar({
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, /[^\s\n\r()#\"\\]/, $.escape_sequence))), unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, /[^\s\n\r()#\"\\]/, $.escape_sequence))),
if_command: ($) => command($.if, repeat(choice($.argument, ...if_args))), if_command: ($) => command($.if, repeat(choice($.argument))),
elseif_command: ($) => command($.elseif, repeat(choice($.argument, ...if_args))), elseif_command: ($) => command($.elseif, repeat(choice($.argument))),
else_command: ($) => command($.else, optional(choice($.argument, ...if_args))), else_command: ($) => command($.else, optional(choice($.argument))),
endif_command: ($) => command($.endif, optional(choice($.argument, ...if_args))), endif_command: ($) => command($.endif, optional(choice($.argument))),
if_condition: ($) => if_condition: ($) =>
seq($.if_command, repeat(choice($._command_invocation, $.elseif_command, $.else_command)), $.endif_command), 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)), endforeach_command: ($) => command($.endforeach, optional($.argument)),
foreach_loop: ($) => seq($.foreach_command, repeat($._command_invocation), $.endforeach_command), foreach_loop: ($) => seq($.foreach_command, repeat($._command_invocation), $.endforeach_command),
while_command: ($) => command($.while, repeat(choice($.argument, ...if_args))), while_command: ($) => command($.while, repeat(choice($.argument))),
endwhile_command: ($) => command($.endwhile, optional(choice($.argument, ...if_args))), endwhile_command: ($) => command($.endwhile, optional(choice($.argument))),
while_loop: ($) => seq($.while_command, repeat($._command_invocation), $.endwhile_command), while_loop: ($) => seq($.while_command, repeat($._command_invocation), $.endwhile_command),
function_command: ($) => command($.function, repeat($.argument)), function_command: ($) => command($.function, repeat($.argument)),
@ -126,20 +63,10 @@ module.exports = grammar({
endmacro_command: ($) => command($.endmacro, repeat($.argument)), endmacro_command: ($) => command($.endmacro, repeat($.argument)),
macro_def: ($) => seq($.macro_command, repeat($._command_invocation), $.endmacro_command), 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)), normal_command: ($) => command($.identifier, repeat($.argument)),
_command_invocation: ($) => _command_invocation: ($) =>
choice( choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def),
$.normal_command,
$.if_condition,
$.foreach_loop,
$.while_loop,
$.function_def,
$.macro_def,
$.message_command
),
...commandNames(...commands), ...commandNames(...commands),
identifier: (_) => /[A-Za-z_][A-Za-z0-9_]*/, identifier: (_) => /[A-Za-z_][A-Za-z0-9_]*/,

File diff suppressed because it is too large Load diff

View file

@ -241,10 +241,6 @@
"type": "macro_def", "type": "macro_def",
"named": true "named": true
}, },
{
"type": "message_command",
"named": true
},
{ {
"type": "normal_command", "type": "normal_command",
"named": true "named": true
@ -307,10 +303,6 @@
"type": "macro_def", "type": "macro_def",
"named": true "named": true
}, },
{
"type": "message_command",
"named": true
},
{ {
"type": "normal_command", "type": "normal_command",
"named": true "named": true
@ -381,10 +373,6 @@
"type": "macro_def", "type": "macro_def",
"named": true "named": true
}, },
{
"type": "message_command",
"named": true
},
{ {
"type": "normal_command", "type": "normal_command",
"named": true "named": true
@ -447,10 +435,6 @@
"type": "macro_def", "type": "macro_def",
"named": true "named": true
}, },
{
"type": "message_command",
"named": true
},
{ {
"type": "normal_command", "type": "normal_command",
"named": true "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", "type": "normal_command",
"named": true, "named": true,
@ -573,10 +538,6 @@
"type": "macro_def", "type": "macro_def",
"named": true "named": true
}, },
{
"type": "message_command",
"named": true
},
{ {
"type": "normal_command", "type": "normal_command",
"named": true "named": true
@ -692,10 +653,6 @@
"type": "macro_def", "type": "macro_def",
"named": true "named": true
}, },
{
"type": "message_command",
"named": true
},
{ {
"type": "normal_command", "type": "normal_command",
"named": true "named": true
@ -735,254 +692,6 @@
"type": ")", "type": ")",
"named": false "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", "type": "\\n",
"named": false "named": false
@ -1055,10 +764,6 @@
"type": "macro", "type": "macro",
"named": true "named": true
}, },
{
"type": "message",
"named": true
},
{ {
"type": "while", "type": "while",
"named": true "named": true

23008
src/parser.c

File diff suppressed because it is too large Load diff