Skip to content

Boolean literals are parsed as identifiers #108

@alajovic

Description

@alajovic

Description of the issue

Boolean literals end up being parsed as IDENTIFIER terminals rather than boolean_literal instances.

Steps to reproduce

Write the following source to test.txt:

VAR_GLOBAL
variable : BOOL := TRUE;
END_VAR

Run

blark parse --print-tree test.txt

Expected result

The string TRUE gets parsed as a boolean literal:

iec_source
  global_var_declarations
    [... non-relevant part of the output omitted ...]
                            unary_expression
                              None
                              constant
                                boolean_literal TRUE

Actual result

The string TRUE gets parsed as an identifier. Note that the full meaning of the TRUE in the output below is, in lark's notation, Token('IDENTIFIER', 'TRUE').

iec_source
  global_var_declarations
    [... non-relevant part of the output omitted ...]
                            unary_expression
                              None
                              variable_name
                                TRUE
                                None

Additional information

I am able to get the expected parse result by increasing the priority of the constant rule in the grammar, i.e., by replacing this line:

constant: time_literal

with this:

constant.1: time_literal

Please let me know if this seems a sensible solution. I will gladly prepare a PR if you agree.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions