Skip to content

Grammar does not support field selectors / subscripts on general expressions #119

@DenSinH

Description

@DenSinH

Currently, expressions like these are not parsed by the grammar:

s_fbMyFunctionBlock.m_Get(s_nIdx).p_bValue

even though they are perfectly valid. Just try here: https://www.lark-parser.org/ide/
with example code:

FUNCTION_BLOCK FB_Test

s_bTest := s_fbMyFunctionBlock.m_Get(s_nIdx).p_bValue;

END_FUNCTION_BLOCK

and the current iec.lark grammar. It will fail:

lark.exceptions.UnexpectedCharacters: No terminal matches ';' in the current parser context, at line 3 col 54

fbMyFunctionBlock.m_Get(s_nIdx).p_bValue;
                                        ^
Expected one of: 
	* DEREFERENCED
	* LPAR
	* LSQB
	* DOT

expecting a chained function call.

If you replace

field_selector: [ DEREFERENCED ] "." ( variable_name | INTEGER )

multi_element_variable: variable_name ( subscript_list | field_selector )+

with

field_selector: [ DEREFERENCED ] "." ( variable_name | INTEGER )

multi_element_variable: expression ( subscript_list | field_selector )+

the code does parse (which is expected), but this implies modifications in MultiElementVariable, which may have a lot of implications elsewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggrammar

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions