End of line grammar difficulty [SOLVED] [message #1186656] |
Thu, 14 November 2013 20:33 |
Tom Mealey Messages: 7 Registered: October 2013 |
Junior Member |
|
|
Hello All,
I have a simple language made up of one line statements, necessarily separated by a newline. Here are the relevant segments of the grammar:
Model:
{Model}
EOL*
(includes += Include)*
(elements += TopLevelElement)*
;
Include:
'#include' importURI=STRING EOL+
;
TopLevelElement:
(Macro | Instruction | Label) EOL+
;
EOL:
NEWLINE | SL_COMMENT;
terminal SL_COMMENT:
'//' !('\n'|'\r')* ('\r'? '\n')?;
terminal NEWLINE:
('\r'? '\n');
My grammar implementation almost gives me the behavior I want, but the problem is that it requires an EOL character after the last TopLevelElement. I'd like to be able to not have to enter a newline or comment at the end of every document. Is there a way I can revise my grammar to achieve this?
Thanks,
Tom
[Updated on: Mon, 18 November 2013 16:12] Report message to a moderator
|
|
|
|
Re: End of line grammar difficulty [message #1194633 is a reply to message #1187730] |
Mon, 18 November 2013 16:10 |
Tom Mealey Messages: 7 Registered: October 2013 |
Junior Member |
|
|
I was able to revise my grammar and achieve the behavior I was looking for. For anyone curious, here is what the grammar looks like now:
Model:
{Model}
EOL*
(includes += Include EOL+)*
(elements += TopLevelElement EOL+)*
(elements += TopLevelElement)?
;
Include:
'#include' importURI=STRING
;
TopLevelElement:
(Macro | Instruction | Label)
;
EOL:
NEWLINE | SL_COMMENT;
terminal SL_COMMENT:
'//' !('\n'|'\r')* ('\r'? '\n')?;
terminal NEWLINE:
('\r'? '\n');
[Updated on: Mon, 18 November 2013 16:11] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02922 seconds