Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Missing Rule BEGIN in White-space awareness grammar
Missing Rule BEGIN in White-space awareness grammar [message #1839992] Sat, 03 April 2021 07:39 Go to next message
wings cu is currently offline wings cuFriend
Messages: 14
Registered: January 2021
Junior Member
I am working on a white-space awareness grammar like python dsl. I need to use terminal rule NEXT_LINE as the end of one statement. But I found this approach will make the BEGIN-END indent fail to match.
What can I do to fix this problem?
hidden(WS)
Model:
	greetings+=Greeting*;
	
Greeting:
	{Greeting} 'greet' NEXT_LINE
	BEGIN
		(exp+=ID)*
	END
;
terminal BEGIN: 'synthetic:BEGIN';  // increase indentation
terminal END: 'synthetic:END';      // decrease indentation
terminal ID:
    '^'?('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal NEXT_LINE:
	('\n'|'\r')+;
terminal WS:
    (' '|'\t')+;

[Updated on: Thu, 08 April 2021 04:28]

Report message to a moderator

Re: Missing Rule BEGIN in White-space awareness grammar [message #1840464 is a reply to message #1839992] Thu, 15 April 2021 19:29 Go to previous messageGo to next message
Dimo Petroff is currently offline Dimo PetroffFriend
Messages: 16
Registered: November 2018
Junior Member
This looks very odd... you can't indent without going to the next line anyway, so this NEXT_LINE terminal is not necessary in your example... Assuming that this is meant to represent a much more complicated DSL, I would suggest to simply use any whitespace as the delimiter for your statement (i.e. remove the NEXT_LINE rule entirely) and have the formatter apply a new line at the end of the statement (regionFor.keyword("greet").append[newLine]).

If you really want to make a new line semantically relevant in your DSL, then you might have to define NEXT_LINE as 'synthetic:NEXT_LINE' and customise YourDslNameTokenSource to emit it but the problem now is that you'll have to EXPLICITLY specify where a new line is allowed in your grammar... So perhaps your grammar will end up looking like
Model:
	(greetings+=Greeting NEW_LINE?)*;
	
Greeting:
	{Greeting} 'greet' NEXT_LINE
	BEGIN
		(exp+=ID NEW_LINE?)*
	END
	NEW_LINE*
;
Re: Missing Rule BEGIN in White-space awareness grammar [message #1840484 is a reply to message #1840464] Fri, 16 April 2021 08:52 Go to previous message
wings cu is currently offline wings cuFriend
Messages: 14
Registered: January 2021
Junior Member
Yes, actually I have tried to do this way.
Anyway, thank you for replying me.
This project gives me inspiration: https://github.com/martinbaker/fricas2aldor/blob/master/com.euclideanspace.bootSyntax/src/com/euclideanspace/bootSyntax/parser/antlr/EditorTokenSource.java
Previous Topic:How to disable validation when editing in xtext editor?
Next Topic:Bind STRINGValueConverter
Goto Forum:
  


Current Time: Thu Apr 25 23:07:44 GMT 2024

Powered by FUDForum. Page generated in 0.03562 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top