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
|
||||
reservedWord('others'),
|
||||
list_of('|', $._name_for_component_choice),
|
||||
list_of('|', prec.dynamic(1, $._name_for_component_choice)),
|
||||
),
|
||||
_aggregate: $ => choice( // RM 4.3
|
||||
$.record_aggregate,
|
||||
|
|
@ -1148,7 +1148,7 @@ module.exports = grammar({
|
|||
),
|
||||
discrete_choice_list: $ => list_of('|', $.discrete_choice),
|
||||
discrete_choice: $ => choice( // ARM 3.8.1
|
||||
$.expression,
|
||||
prec.dynamic(1, $.expression),
|
||||
$._subtype_indication,
|
||||
$.range_g,
|
||||
reservedWord('others'),
|
||||
|
|
|
|||
|
|
@ -3618,8 +3618,12 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_name_for_component_choice"
|
||||
"type": "PREC_DYNAMIC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_name_for_component_choice"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
|
|
@ -3631,8 +3635,12 @@
|
|||
"value": "|"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_name_for_component_choice"
|
||||
"type": "PREC_DYNAMIC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_name_for_component_choice"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -6491,8 +6499,12 @@
|
|||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
"type": "PREC_DYNAMIC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
},
|
||||
{
|
||||
"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
|
||||
|
|
@ -36,10 +36,127 @@ end;
|
|||
(case_statement_alternative
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(identifier)))
|
||||
(expression
|
||||
(term
|
||||
(identifier)))))
|
||||
(null_statement))
|
||||
(case_statement_alternative
|
||||
(discrete_choice_list
|
||||
(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)))))))
|
||||
|
|
|
|||
|
|
@ -394,12 +394,16 @@ end record;
|
|||
(variant
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(identifier)))
|
||||
(expression
|
||||
(term
|
||||
(identifier)))))
|
||||
(component_list))
|
||||
(variant
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(identifier)))
|
||||
(expression
|
||||
(term
|
||||
(identifier)))))
|
||||
(component_list
|
||||
(component_declaration
|
||||
(identifier)
|
||||
|
|
@ -452,7 +456,9 @@ variants 2
|
|||
(variant
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(identifier)))
|
||||
(expression
|
||||
(term
|
||||
(identifier)))))
|
||||
(component_list
|
||||
(component_declaration
|
||||
(identifier)
|
||||
|
|
|
|||
|
|
@ -405,9 +405,13 @@ end;
|
|||
(case_statement_alternative
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(character_literal))
|
||||
(expression
|
||||
(term
|
||||
(character_literal))))
|
||||
(discrete_choice
|
||||
(character_literal)))
|
||||
(expression
|
||||
(term
|
||||
(character_literal)))))
|
||||
(null_statement)))))))
|
||||
|
||||
================================================================================
|
||||
|
|
|
|||
|
|
@ -146,14 +146,18 @@ end P;
|
|||
(array_component_association
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(identifier)))
|
||||
(expression
|
||||
(term
|
||||
(identifier)))))
|
||||
(expression
|
||||
(term
|
||||
(numeric_literal))))
|
||||
(array_component_association
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(identifier)))
|
||||
(expression
|
||||
(term
|
||||
(identifier)))))
|
||||
(expression
|
||||
(term
|
||||
(numeric_literal)))))))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user