Correct parsing of discrete_choice expressions.
The existing grammar was causing simple expressions to be incorrectly parsed as a subtype indication. This change raises the precedence for a discrete choice expression to address that issue. Updated the test corpus to reflect the parsing correction. Additional test cases were added for discrete choice.
This commit is contained in:
parent
0f572c4dcc
commit
f21f13afe0
|
|
@ -704,7 +704,7 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
component_choice_list: $ => choice( // RM 4.3.1
|
component_choice_list: $ => choice( // RM 4.3.1
|
||||||
reservedWord('others'),
|
reservedWord('others'),
|
||||||
list_of('|', $._name_for_component_choice),
|
list_of('|', prec.dynamic(1, $._name_for_component_choice)),
|
||||||
),
|
),
|
||||||
_aggregate: $ => choice( // RM 4.3
|
_aggregate: $ => choice( // RM 4.3
|
||||||
$.record_aggregate,
|
$.record_aggregate,
|
||||||
|
|
@ -1148,7 +1148,7 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
discrete_choice_list: $ => list_of('|', $.discrete_choice),
|
discrete_choice_list: $ => list_of('|', $.discrete_choice),
|
||||||
discrete_choice: $ => choice( // ARM 3.8.1
|
discrete_choice: $ => choice( // ARM 3.8.1
|
||||||
$.expression,
|
prec.dynamic(1, $.expression),
|
||||||
$._subtype_indication,
|
$._subtype_indication,
|
||||||
$.range_g,
|
$.range_g,
|
||||||
reservedWord('others'),
|
reservedWord('others'),
|
||||||
|
|
|
||||||
|
|
@ -3618,8 +3618,12 @@
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "PREC_DYNAMIC",
|
||||||
"name": "_name_for_component_choice"
|
"value": 1,
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_name_for_component_choice"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT",
|
"type": "REPEAT",
|
||||||
|
|
@ -3631,8 +3635,12 @@
|
||||||
"value": "|"
|
"value": "|"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "PREC_DYNAMIC",
|
||||||
"name": "_name_for_component_choice"
|
"value": 1,
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_name_for_component_choice"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -6491,8 +6499,12 @@
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "PREC_DYNAMIC",
|
||||||
"name": "expression"
|
"value": 1,
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expression"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
|
|
|
||||||
68165
src/parser.c
68165
src/parser.c
File diff suppressed because it is too large
Load Diff
|
|
@ -1,5 +1,5 @@
|
||||||
================================================================================
|
================================================================================
|
||||||
Discrete Choices and characters
|
Discrete Choice expression
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
declare
|
declare
|
||||||
|
|
@ -36,10 +36,127 @@ end;
|
||||||
(case_statement_alternative
|
(case_statement_alternative
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(identifier)))
|
(expression
|
||||||
|
(term
|
||||||
|
(identifier)))))
|
||||||
(null_statement))
|
(null_statement))
|
||||||
(case_statement_alternative
|
(case_statement_alternative
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(character_literal)))
|
(expression
|
||||||
|
(term
|
||||||
|
(character_literal)))))
|
||||||
|
(null_statement)))))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
Discrete Choice subtype indication
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
declare
|
||||||
|
Value : Integer := 5;
|
||||||
|
begin
|
||||||
|
case Value is
|
||||||
|
when Integer range 1 .. Integer'Last => null;
|
||||||
|
when Integer range 0 .. 0 => null;
|
||||||
|
when others => null;
|
||||||
|
end case;
|
||||||
|
end;
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
(compilation
|
||||||
|
(compilation_unit
|
||||||
|
(block_statement
|
||||||
|
(non_empty_declarative_part
|
||||||
|
(object_declaration
|
||||||
|
name: (identifier)
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal)))))
|
||||||
|
(handled_sequence_of_statements
|
||||||
|
(case_statement
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
name: (identifier)))
|
||||||
|
(case_statement_alternative
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(range_constraint
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
(numeric_literal))
|
||||||
|
(term
|
||||||
|
name: (identifier)
|
||||||
|
name: (tick)
|
||||||
|
name: (attribute_designator
|
||||||
|
(identifier)))))))
|
||||||
|
(null_statement))
|
||||||
|
(case_statement_alternative
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(range_constraint
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
(numeric_literal))
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))
|
||||||
|
(null_statement))
|
||||||
|
(case_statement_alternative
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice))
|
||||||
|
(null_statement)))))))
|
||||||
|
|
||||||
|
================================================================================
|
||||||
|
Discrete Choice range
|
||||||
|
================================================================================
|
||||||
|
|
||||||
|
declare
|
||||||
|
Value : Character := 'A';
|
||||||
|
begin
|
||||||
|
case Value is
|
||||||
|
when 'a' .. 'z' => null;
|
||||||
|
when 'A' .. 'Z' => null;
|
||||||
|
when others => null;
|
||||||
|
end case;
|
||||||
|
end;
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
(compilation
|
||||||
|
(compilation_unit
|
||||||
|
(block_statement
|
||||||
|
(non_empty_declarative_part
|
||||||
|
(object_declaration
|
||||||
|
name: (identifier)
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
name: (character_literal)))))
|
||||||
|
(handled_sequence_of_statements
|
||||||
|
(case_statement
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
name: (identifier)))
|
||||||
|
(case_statement_alternative
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
name: (character_literal))
|
||||||
|
(term
|
||||||
|
name: (character_literal)))))
|
||||||
|
(null_statement))
|
||||||
|
(case_statement_alternative
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
name: (character_literal))
|
||||||
|
(term
|
||||||
|
name: (character_literal)))))
|
||||||
|
(null_statement))
|
||||||
|
(case_statement_alternative
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice))
|
||||||
(null_statement)))))))
|
(null_statement)))))))
|
||||||
|
|
|
||||||
|
|
@ -394,12 +394,16 @@ end record;
|
||||||
(variant
|
(variant
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(identifier)))
|
(expression
|
||||||
|
(term
|
||||||
|
(identifier)))))
|
||||||
(component_list))
|
(component_list))
|
||||||
(variant
|
(variant
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(identifier)))
|
(expression
|
||||||
|
(term
|
||||||
|
(identifier)))))
|
||||||
(component_list
|
(component_list
|
||||||
(component_declaration
|
(component_declaration
|
||||||
(identifier)
|
(identifier)
|
||||||
|
|
@ -452,7 +456,9 @@ variants 2
|
||||||
(variant
|
(variant
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(identifier)))
|
(expression
|
||||||
|
(term
|
||||||
|
(identifier)))))
|
||||||
(component_list
|
(component_list
|
||||||
(component_declaration
|
(component_declaration
|
||||||
(identifier)
|
(identifier)
|
||||||
|
|
|
||||||
|
|
@ -405,9 +405,13 @@ end;
|
||||||
(case_statement_alternative
|
(case_statement_alternative
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(character_literal))
|
(expression
|
||||||
|
(term
|
||||||
|
(character_literal))))
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(character_literal)))
|
(expression
|
||||||
|
(term
|
||||||
|
(character_literal)))))
|
||||||
(null_statement)))))))
|
(null_statement)))))))
|
||||||
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
|
||||||
|
|
@ -146,14 +146,18 @@ end P;
|
||||||
(array_component_association
|
(array_component_association
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(identifier)))
|
(expression
|
||||||
|
(term
|
||||||
|
(identifier)))))
|
||||||
(expression
|
(expression
|
||||||
(term
|
(term
|
||||||
(numeric_literal))))
|
(numeric_literal))))
|
||||||
(array_component_association
|
(array_component_association
|
||||||
(discrete_choice_list
|
(discrete_choice_list
|
||||||
(discrete_choice
|
(discrete_choice
|
||||||
(identifier)))
|
(expression
|
||||||
|
(term
|
||||||
|
(identifier)))))
|
||||||
(expression
|
(expression
|
||||||
(term
|
(term
|
||||||
(numeric_literal)))))))
|
(numeric_literal)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user