Add message and its test case

This commit is contained in:
Uy Ha 2021-06-17 23:06:32 +02:00
parent c16b1dfe4b
commit 5047c61bba
10 changed files with 17294 additions and 7072 deletions

View file

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

View file

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

43
corpus/message.txt Normal file
View file

@ -0,0 +1,43 @@
=====================
No argument [message]
=====================
message()
---
(source_file
(message_command
(message)
)
)
=================================
No argument with spaces [message]
=================================
message( )
---
(source_file
(message_command
(message)
)
)
===============================================
Message without argument with newline [message]
===============================================
message(
)
---
(source_file
(message_command
(message)
)
)

View file

@ -1,44 +0,0 @@
=================================================
Command invocation without argument [no_argument]
=================================================
message()
---
(source_file
(normal_command
(identifier)
)
)
=============================================================
Command invocation without argument with spaces [no_argument]
=============================================================
message( )
---
(source_file
(normal_command
(identifier)
)
)
==============================================================
Command invocation without argument with newline [no_argument]
==============================================================
message(
)
---
(source_file
(normal_command
(identifier)
)
)

View file

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

View file

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

View file

@ -1,3 +1,18 @@
commands = [
"if",
"elseif",
"else",
"endif",
"foreach",
"endforeach",
"while",
"endwhile",
"function",
"endfunction",
"macro",
"endmacro",
"message",
];
if_args = [
"1",
"ON",
@ -45,6 +60,22 @@ if_args = [
"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({
name: "cmake",
@ -89,11 +120,30 @@ module.exports = grammar({
endwhile_command: ($) => command($.endwhile, optional(choice($.argument, ...if_args))),
while_loop: ($) => seq($.while_command, repeat($._command_invocation), $.endwhile_command),
function_command: ($) => command($.function, args($.argument)),
endfunction_command: ($) => command($.endfunction, args($.argument)),
function_def: ($) => seq($.function_command, repeat($._command_invocation), $.endfunction_command),
macro_command: ($) => command($.macro, args($.argument)),
endmacro_command: ($) => command($.endmacro, args($.argument)),
macro_def: ($) => seq($.macro_command, repeat($._command_invocation), $.endmacro_command),
message_command: ($) => command($.message, optional(args(choice($.argument, ...message_args)))),
normal_command: ($) => command($.identifier, optional(args($.argument))),
_command_invocation: ($) => choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop),
_command_invocation: ($) =>
choice(
$.normal_command,
$.if_condition,
$.foreach_loop,
$.while_loop,
$.function_def,
$.macro_def,
$.message_command
),
...commandNames("if", "elseif", "else", "endif", "foreach", "endforeach", "while", "endwhile"),
...commandNames(...commands),
identifier: (_) => /[A-Za-z_][A-Za-z0-9_]*/,
integer: (_) => /[+-]*\d+/,
},

View file

@ -2573,6 +2573,578 @@
}
]
},
"function_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "function"
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "BLANK"
}
]
}
]
}
}
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"endfunction_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "endfunction"
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "BLANK"
}
]
}
]
}
}
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"function_def": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "function_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_command_invocation"
}
},
{
"type": "SYMBOL",
"name": "endfunction_command"
}
]
},
"macro_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "macro"
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "BLANK"
}
]
}
]
}
}
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"endmacro_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "endmacro"
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "BLANK"
}
]
}
]
}
}
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"macro_def": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "macro_command"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_command_invocation"
}
},
{
"type": "SYMBOL",
"name": "endmacro_command"
}
]
},
"message_command": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "message"
},
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "STRING",
"value": "FATAL_ERROR"
},
{
"type": "STRING",
"value": "SEND_ERROR"
},
{
"type": "STRING",
"value": "WARNING"
},
{
"type": "STRING",
"value": "AUTHOR_WARNING"
},
{
"type": "STRING",
"value": "DEPRECATION"
},
{
"type": "STRING",
"value": "NOTICE"
},
{
"type": "STRING",
"value": "STATUS"
},
{
"type": "STRING",
"value": "VERBOSE"
},
{
"type": "STRING",
"value": "DEBUG"
},
{
"type": "STRING",
"value": "TRACE"
},
{
"type": "STRING",
"value": "CHECK_START"
},
{
"type": "STRING",
"value": "CHECK_PASS"
},
{
"type": "STRING",
"value": "CHECK_FAIL"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[ \\t]+"
},
{
"type": "PATTERN",
"value": "\\n+"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
},
{
"type": "STRING",
"value": "FATAL_ERROR"
},
{
"type": "STRING",
"value": "SEND_ERROR"
},
{
"type": "STRING",
"value": "WARNING"
},
{
"type": "STRING",
"value": "AUTHOR_WARNING"
},
{
"type": "STRING",
"value": "DEPRECATION"
},
{
"type": "STRING",
"value": "NOTICE"
},
{
"type": "STRING",
"value": "STATUS"
},
{
"type": "STRING",
"value": "VERBOSE"
},
{
"type": "STRING",
"value": "DEBUG"
},
{
"type": "STRING",
"value": "TRACE"
},
{
"type": "STRING",
"value": "CHECK_START"
},
{
"type": "STRING",
"value": "CHECK_PASS"
},
{
"type": "STRING",
"value": "CHECK_FAIL"
}
]
},
{
"type": "BLANK"
}
]
}
]
}
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"normal_command": {
"type": "SEQ",
"members": [
@ -2681,6 +3253,18 @@
{
"type": "SYMBOL",
"name": "while_loop"
},
{
"type": "SYMBOL",
"name": "function_def"
},
{
"type": "SYMBOL",
"name": "macro_def"
},
{
"type": "SYMBOL",
"name": "message_command"
}
]
},
@ -2716,6 +3300,26 @@
"type": "PATTERN",
"value": "[eE][nN][dD][wW][hH][iI][lL][eE]"
},
"function": {
"type": "PATTERN",
"value": "[fF][uU][nN][cC][tT][iI][oO][nN]"
},
"endfunction": {
"type": "PATTERN",
"value": "[eE][nN][dD][fF][uU][nN][cC][tT][iI][oO][nN]"
},
"macro": {
"type": "PATTERN",
"value": "[mM][aA][cC][rR][oO]"
},
"endmacro": {
"type": "PATTERN",
"value": "[eE][nN][dD][mM][aA][cC][rR][oO]"
},
"message": {
"type": "PATTERN",
"value": "[mM][eE][sS][sS][aA][gG][eE]"
},
"identifier": {
"type": "PATTERN",
"value": "[A-Za-z_][A-Za-z0-9_]*"

View file

@ -114,6 +114,25 @@
]
}
},
{
"type": "endfunction_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "endfunction",
"named": true
}
]
}
},
{
"type": "endif_command",
"named": true,
@ -133,6 +152,25 @@
]
}
},
{
"type": "endmacro_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "endmacro",
"named": true
}
]
}
},
{
"type": "endwhile_command",
"named": true,
@ -211,10 +249,88 @@
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "message_command",
"named": true
},
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
},
{
"type": "function_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "function",
"named": true
}
]
}
},
{
"type": "function_def",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "endfunction_command",
"named": true
},
{
"type": "foreach_loop",
"named": true
},
{
"type": "function_command",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "message_command",
"named": true
},
{
"type": "normal_command",
"named": true
@ -269,6 +385,10 @@
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_command",
"named": true
@ -277,6 +397,14 @@
"type": "if_condition",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "message_command",
"named": true
},
{
"type": "normal_command",
"named": true
@ -288,6 +416,91 @@
]
}
},
{
"type": "macro_command",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "argument",
"named": true
},
{
"type": "macro",
"named": true
}
]
}
},
{
"type": "macro_def",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "endmacro_command",
"named": true
},
{
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "macro_command",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "message_command",
"named": true
},
{
"type": "normal_command",
"named": true
},
{
"type": "while_loop",
"named": true
}
]
}
},
{
"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,
@ -368,10 +581,22 @@
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "message_command",
"named": true
},
{
"type": "normal_command",
"named": true
@ -475,10 +700,22 @@
"type": "foreach_loop",
"named": true
},
{
"type": "function_def",
"named": true
},
{
"type": "if_condition",
"named": true
},
{
"type": "macro_def",
"named": true
},
{
"type": "message_command",
"named": true
},
{
"type": "normal_command",
"named": true
@ -534,18 +771,42 @@
"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
@ -562,6 +823,10 @@
"type": "FALSE",
"named": false
},
{
"type": "FATAL_ERROR",
"named": false
},
{
"type": "GREATER",
"named": false
@ -634,6 +899,10 @@
"type": "NOTFOUND",
"named": false
},
{
"type": "NOTICE",
"named": false
},
{
"type": "OFF",
"named": false
@ -654,6 +923,14 @@
"type": "RANGE",
"named": false
},
{
"type": "SEND_ERROR",
"named": false
},
{
"type": "STATUS",
"named": false
},
{
"type": "STREQUAL",
"named": false
@ -682,10 +959,18 @@
"type": "TEST",
"named": false
},
{
"type": "TRACE",
"named": false
},
{
"type": "TRUE",
"named": false
},
{
"type": "VERBOSE",
"named": false
},
{
"type": "VERSION_EQUAL",
"named": false
@ -706,6 +991,10 @@
"type": "VERSION_LESS_EQUAL",
"named": false
},
{
"type": "WARNING",
"named": false
},
{
"type": "Y",
"named": false
@ -754,10 +1043,18 @@
"type": "endforeach",
"named": true
},
{
"type": "endfunction",
"named": true
},
{
"type": "endif",
"named": true
},
{
"type": "endmacro",
"named": true
},
{
"type": "endwhile",
"named": true
@ -766,6 +1063,10 @@
"type": "foreach",
"named": true
},
{
"type": "function",
"named": true
},
{
"type": "identifier",
"named": true
@ -774,6 +1075,14 @@
"type": "if",
"named": true
},
{
"type": "macro",
"named": true
},
{
"type": "message",
"named": true
},
{
"type": "while",
"named": true

23232
src/parser.c

File diff suppressed because it is too large Load diff