fsource
fsource copied to clipboard
Parser fails at INCLUDE statements
Hi, I tried to run the parser on (part of) this package, and got the following error:
> fsource parse ref-calc.v1.6.f --fixed-form
ref-calc.v1.6.f:42:7: parser error: malformed statement inside program
|
| INCLUDE "PARAM"
| ^~~~~~~
The ref-calc.v1.6.f file begins:
program leed
C include parameter statements for dimensions etc
INCLUDE "PARAM"
C set unchangeable constants
INCLUDE "GLOBAL"
Am I missing some option to run the parser on the entire project in a way that would make the INCLUDE statements work, or is this simply not implemented yet?
No, this is not implemented yet. Thanks for the pointer!
Would this be added to _DECLARATION_HANDLERS and STMT_HANDLERS in parser.py? Typically it's found in the declaration section but INCLUDE can show up almost anywhere - see https://www.ibm.com/docs/en/xffbg/121.141?topic=descriptions-include
I managed to patch around the error by adding
def include_stmt(tokens):
expect(tokens, 'include')
ignore_stmt(tokens)
return tokens.produce('include_stmt')
(based on data_stmt())
then added
'include': include_stmt,
to both _DECLARATION_HANDLERS and STMT_HANDLERS
This is admittedly a partial effort; it doesn't attempt to implement INCLUDE but does avoid the error and adds include_stmt to the AST.
Hmm, the problem is that the standard specifies that include is not a statement at all -- it is called "include line" and is much closer in spirit to a preprocessor statement. I think it would therefore be better to treat it as preprocessor statement.
That's reasonable; that's the interpretation I remember from looking at the spec. I approached this from a "how do I make this error stop" perspective rather than a "how do I accurately interpret this entity" perspective so there's likely a better (standards-compliant) way of handling this.