Skip to content

Error Parsing Custom Type Declaration #26

Closed
@Philipp1297

Description

@Philipp1297

Description

I encountered an issue when parsing a type declaration in a Structured Text (ST) file. The declaration is as follows:

TYPE T_INTERLOCK : WORD; 
END_TYPE

However, when attempting to parse it using the current configuration, I receive the following error:

Error parsing node T_INTERLOCK in file test_files\baselib\BaseLibProj\BaseLib\POUs\HMI\Datentypen\T_INTERLOCK.TcDUT
(None:1:24: Expected '.' or '\s' or '//' or '(*(.|\n)?*)' or '{' or 'END_TYPE' => 'OCK : WORD; END_TYP')

Steps Taken:

I tried modifying the st_declaration.tx grammar in an attempt to accommodate this type declaration by adding or adjusting the TypeDef rule as follows:

TypeDef:
    comments*=CommentAny?                
    'TYPE'
    name=ID                             
    ('EXTENDS' extends=AnyType)?  
    ':'  
    CommentAny* 
    type=AnyType
    ';'?
    CommentAny* 
    'END_TYPE'
;

AnyType:
    TypeStruct | TypeUnion | TypeEnum | StringType | Fqn | 'WORD'
;

However, making these changes requires modifying the source code, and I’m wondering if there's a better approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions