AdaCore / libadalang

Ada semantic analysis library.
https://www.adacore.com
Other
147 stars 42 forks source link

Opt seems to be missing in some rules #946

Closed stephe-ada-guru closed 2 years ago

stephe-ada-guru commented 2 years ago

Consider this rule from libadalang grammar.py:

sub_object_decl=ObjectDecl(
    A.defining_id_list,
    ":",
    Aliased(res("aliased")),
    Constant("constant"),
    Opt(A.mode),
    A.type_expr,
    cut(),
    Opt(":=", A.expr),
    Opt(A.renaming_clause),
    A.aspect_spec,
    ";"
),

The corresponding EBNF declaration in the Ada Language Reference Manual Annex P is:

 object_declaration ::= 
     defining_identifier_list : [aliased] [constant]  subtype_indication [:= expression] [aspect_specification] ;

In the LRM, 'aliased' and 'constant' are optional, but in libadalang they appear to be not optional; they are not enclosed in Opt().

There are several other occurrences of this issue.

How does the parser know that 'aliased' and 'constant' are optional here?

pmderodat commented 2 years ago

Aliased and Constant nodes are known to Langkit as “boolean nodes”, for which parsers are special: in Constant("constant"), a ConstantPresent node is created when the parser finds a constant token, and a ConstantAbsent node is created otherwise (in both cases, the parser succeeds). So in practice they are optional (as you can see when asking Libadalang to parse V : T; with the sub_object_decl parsing rule.