Add support for gnatprep directives
They can be folded
This commit is contained in:
parent
39697ddca8
commit
7fe1b1edb4
48
grammar.js
48
grammar.js
|
|
@ -120,6 +120,8 @@ module.exports = grammar({
|
|||
|
||||
identifier: $ =>
|
||||
/[a-zA-Z\u{80}-\u{10FFFF}][0-9a-zA-Z_\u{80}-\u{10FFFF}]*/u,
|
||||
gnatprep_identifier: $ =>
|
||||
/\$[a-zA-Z\u{80}-\u{10FFFF}][0-9a-zA-Z_\u{80}-\u{10FFFF}]*/u,
|
||||
comment: $ => token(seq('--', /.*/)),
|
||||
string_literal: $ => token(/"(""|[^"])*"/),
|
||||
character_literal: $ => token(/'.'/),
|
||||
|
|
@ -129,6 +131,11 @@ module.exports = grammar({
|
|||
/[0-9]+#[0-9a-fA-F._-]+#([eE][+-]?[0-9_]+)?/,
|
||||
)
|
||||
),
|
||||
git_conflict_mark: $ => choice(
|
||||
token(seq(reservedWord('<<<<<<<'), /.*/)),
|
||||
token(seq(reservedWord('>>>>>>>'), /.*/)),
|
||||
token(seq(reservedWord('======='), /.*/)),
|
||||
),
|
||||
relational_operator: $ => choice('=', '/=', '<', '<=', '>', '>='),
|
||||
binary_adding_operator: $ => choice('+', '-', '&'),
|
||||
unary_adding_operator: $ => choice('+', '-'),
|
||||
|
|
@ -137,6 +144,7 @@ module.exports = grammar({
|
|||
|
||||
_name_not_function_call: $ => choice( // RM 4.1
|
||||
$.identifier,
|
||||
$.gnatprep_identifier,
|
||||
$.selected_component,
|
||||
$._attribute_reference,
|
||||
$.qualified_expression,
|
||||
|
|
@ -1329,6 +1337,7 @@ module.exports = grammar({
|
|||
_declarative_item_pragma: $ => choice(
|
||||
$._declarative_item,
|
||||
$.pragma_g,
|
||||
$.gnatprep_declarative_if_statement,
|
||||
),
|
||||
|
||||
// Although it doesn't add any new character, we keep this rule as an
|
||||
|
|
@ -2020,6 +2029,7 @@ module.exports = grammar({
|
|||
),
|
||||
_compound_statement: $ => choice(
|
||||
$.if_statement,
|
||||
$.gnatprep_if_statement,
|
||||
$.case_statement,
|
||||
$.loop_statement,
|
||||
$.block_statement,
|
||||
|
|
@ -2194,6 +2204,44 @@ module.exports = grammar({
|
|||
reservedWord('then'),
|
||||
field('statements', $._sequence_of_statements),
|
||||
),
|
||||
gnatprep_declarative_if_statement: $ => seq(
|
||||
reservedWord('#if'),
|
||||
field('condition', $.expression),
|
||||
reservedWord('then'),
|
||||
$.non_empty_declarative_part,
|
||||
repeat(seq(
|
||||
reservedWord('#elsif'),
|
||||
field('condition', $.expression),
|
||||
reservedWord('then'),
|
||||
$.non_empty_declarative_part,
|
||||
)),
|
||||
optional(seq(
|
||||
reservedWord('#else'),
|
||||
$.non_empty_declarative_part,
|
||||
)),
|
||||
reservedWord('#end'),
|
||||
reservedWord('if'),
|
||||
';',
|
||||
),
|
||||
gnatprep_if_statement: $ => seq(
|
||||
reservedWord('#if'),
|
||||
field('condition', $.expression),
|
||||
reservedWord('then'),
|
||||
field('statements', $._sequence_of_statements),
|
||||
repeat(seq(
|
||||
reservedWord('#elsif'),
|
||||
field('condition', $.expression),
|
||||
reservedWord('then'),
|
||||
field('statements', $._sequence_of_statements),
|
||||
)),
|
||||
optional(seq(
|
||||
reservedWord('#else'),
|
||||
field('else_statements', $._sequence_of_statements),
|
||||
)),
|
||||
reservedWord('#end'),
|
||||
reservedWord('if'),
|
||||
';',
|
||||
),
|
||||
exit_statement: $ => seq( // ARM 5.7
|
||||
reservedWord('exit'),
|
||||
field('loop_name', optional($._name)),
|
||||
|
|
|
|||
|
|
@ -8,4 +8,6 @@
|
|||
(block_statement)
|
||||
(if_statement)
|
||||
(loop_statement)
|
||||
(gnatprep_declarative_if_statement)
|
||||
(gnatprep_if_statement)
|
||||
] @fold
|
||||
|
|
|
|||
|
|
@ -126,6 +126,10 @@
|
|||
|
||||
(raise_statement "with" @exception)
|
||||
|
||||
(gnatprep_declarative_if_statement) @preproc
|
||||
(gnatprep_if_statement) @preproc
|
||||
(gnatprep_identifier) @preproc
|
||||
|
||||
(subprogram_declaration "is" @keyword.function "abstract" @keyword.function)
|
||||
(aspect_specification "with" @keyword.function)
|
||||
|
||||
|
|
|
|||
469
src/grammar.json
469
src/grammar.json
|
|
@ -13,6 +13,10 @@
|
|||
"type": "PATTERN",
|
||||
"value": "[a-zA-Z\\u{80}-\\u{10FFFF}][0-9a-zA-Z_\\u{80}-\\u{10FFFF}]*"
|
||||
},
|
||||
"gnatprep_identifier": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\$[a-zA-Z\\u{80}-\\u{10FFFF}][0-9a-zA-Z_\\u{80}-\\u{10FFFF}]*"
|
||||
},
|
||||
"comment": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
|
|
@ -59,6 +63,95 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"git_conflict_mark": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[<<][<<][<<][<<][<<][<<][<<]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "<<<<<<<"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": ".*"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[>>][>>][>>][>>][>>][>>][>>]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": ">>>>>>>"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": ".*"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[==][==][==][==][==][==][==]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "======="
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": ".*"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"relational_operator": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
|
|
@ -150,6 +243,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "gnatprep_identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "selected_component"
|
||||
|
|
@ -7785,6 +7882,10 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "pragma_g"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "gnatprep_declarative_if_statement"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -8306,13 +8407,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"_exception_handler_list": {
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "exception_handler"
|
||||
}
|
||||
},
|
||||
"formal_part": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
|
@ -10076,8 +10170,11 @@
|
|||
"value": "exception"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_exception_handler_list"
|
||||
"name": "exception_handler"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -12326,6 +12423,10 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "if_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "gnatprep_if_statement"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "case_statement"
|
||||
|
|
@ -13666,6 +13767,358 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"gnatprep_declarative_if_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][iI][fF]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#if"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "condition",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[tT][hH][eE][nN]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "then"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "non_empty_declarative_part"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][eE][lL][sS][iI][fF]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#elsif"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "condition",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[tT][hH][eE][nN]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "then"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "non_empty_declarative_part"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][eE][lL][sS][eE]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#else"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "non_empty_declarative_part"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][eE][nN][dD]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#end"
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[iI][fF]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "if"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
"gnatprep_if_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][iI][fF]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#if"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "condition",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[tT][hH][eE][nN]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "then"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "statements",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sequence_of_statements"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][eE][lL][sS][iI][fF]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#elsif"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "condition",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[tT][hH][eE][nN]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "then"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "statements",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sequence_of_statements"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][eE][lL][sS][eE]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#else"
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "else_statements",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_sequence_of_statements"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[##][eE][nN][dD]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "#end"
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": 2,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[iI][fF]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"named": false,
|
||||
"value": "if"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
"exit_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
92757
src/parser.c
92757
src/parser.c
File diff suppressed because it is too large
Load Diff
55
test/corpus/preprocessor.txt
Normal file
55
test/corpus/preprocessor.txt
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
================================================================================
|
||||
Preprocess-if (GNAT)
|
||||
================================================================================
|
||||
|
||||
procedure P is
|
||||
#if not CHECKING_MODE then
|
||||
pragma Suppress (Access_Checks);
|
||||
#end if;
|
||||
begin
|
||||
null;
|
||||
end;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(subprogram_body
|
||||
(procedure_specification
|
||||
(identifier))
|
||||
(non_empty_declarative_part
|
||||
(gnatprep_declarative_if_statement
|
||||
(expression
|
||||
(term
|
||||
(factor_not
|
||||
(identifier))))
|
||||
(non_empty_declarative_part
|
||||
(pragma_g
|
||||
(identifier)
|
||||
(pragma_argument_association
|
||||
(expression
|
||||
(term
|
||||
(identifier))))))))
|
||||
(handled_sequence_of_statements
|
||||
(null_statement)))))
|
||||
|
||||
================================================================================
|
||||
Preprocess substitution (GNAT)
|
||||
================================================================================
|
||||
|
||||
package P is
|
||||
Flavour : constant F := $FLAVOR;
|
||||
end;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(package_specification
|
||||
(identifier)
|
||||
(object_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(expression
|
||||
(term
|
||||
(gnatprep_identifier)))))))
|
||||
|
|
@ -543,9 +543,9 @@ end;
|
|||
(term
|
||||
(target_name)))))))))))))
|
||||
|
||||
=======
|
||||
================================================================================
|
||||
if-expressions
|
||||
=======
|
||||
================================================================================
|
||||
|
||||
procedure P is
|
||||
begin
|
||||
|
|
@ -553,7 +553,7 @@ begin
|
|||
S := new String'(if N /= "" then N else "12");
|
||||
end;
|
||||
|
||||
-----
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
|
|
@ -606,9 +606,9 @@ end;
|
|||
(term
|
||||
(string_literal)))))))))))))
|
||||
|
||||
=======
|
||||
================================================================================
|
||||
Re-raise
|
||||
=======
|
||||
================================================================================
|
||||
|
||||
procedure P is
|
||||
begin
|
||||
|
|
@ -620,7 +620,7 @@ exception
|
|||
raise;
|
||||
end;
|
||||
|
||||
------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user