-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Hi there!
First of all, WOW! This project is awesome!
I just happened to stumble across this project recently. I'm tinkering with a linter for SEL (Schweitzer Engineering Laboratories) RTAC projects. The SEL RTAC uses CODESYS, so there's some intricacies that I need to handle in the different XML formatting. I had been working on my own Lark grammar until I stumbled across this work, and now, it seems sensible to leverage the great work you've already produced, and contribute where possible.
I've built logic that's capable of breaking down the RTAC XML to its constituent declaration and implementation sections (separately) and I'm wondering if you might be able to suggest a good way to interact with these components. For example, I have a section of implementation code as follows:
// Default return value to TRUE
SerializeJson := TRUE;
// Set to Root of Structure
Root();
SerializeJson := SerializeJson AND _serializedContent.Recycle();
// Set up Initial States for Indices
lastLevel := Current.LEVEL;
outerType := Current.JSON_TYPE;
And using a little Python as follows:
def lark_61131_implementation(**kwargs):
"""Generate Lark Parser for 61131 Implementation Sections."""
return lark.Lark.open(
'iec.lark',
rel_to=__file__,
parser='earley',
maybe_placeholders=True,
propagate_positions=True,
**kwargs
)
...
parser = lark_61131_implementation()
print(parser.parse(interface).pretty()) # `interface` is a string of the aforementioned 61131Ultimately, that gives me a nice Lark error:
Traceback (most recent call last):
File "/home/joestan/Documents/selint/selint/core/lexer/__init__.py", line 155, in <module>
print(parser.parse(interface).pretty())
File "/home/joestan/.local/lib/python3.8/site-packages/lark/lark.py", line 625, in parse
return self.parser.parse(text, start=start, on_error=on_error)
File "/home/joestan/.local/lib/python3.8/site-packages/lark/parser_frontends.py", line 96, in parse
return self.parser.parse(stream, chosen_start, **kw)
File "/home/joestan/.local/lib/python3.8/site-packages/lark/parsers/earley.py", line 266, in parse
to_scan = self._parse(lexer, columns, to_scan, start_symbol)
File "/home/joestan/.local/lib/python3.8/site-packages/lark/parsers/xearley.py", line 146, in _parse
to_scan = scan(i, to_scan)
File "/home/joestan/.local/lib/python3.8/site-packages/lark/parsers/xearley.py", line 119, in scan
raise UnexpectedCharacters(stream, i, text_line, text_column, {item.expect.name for item in to_scan},
lark.exceptions.UnexpectedCharacters: No terminal matches 'S' in the current parser context, at line 3 col 1
SerializeJson := TRUE;
^
Expected one of:
* PROGRAM
* TYPE
* PROPERTY
* FUNCTION
* FUNCTION_BLOCK
* ACTION
* METHOD
* VAR_GLOBALBefore I go diving back into the grammar, I thought it might behoove me to ask exactly how these strings are intended to be parsed according to the grammar file you've provided. Should I be combining declaration and implementation into a single block? Are there other concepts you think I might be overlooking?
Thank you so much for your time!