Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » xtext rules starts at new line(xtext rules starts at new line)
xtext rules starts at new line [message #1744204] Fri, 23 September 2016 10:55 Go to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
Hi,

I have grammar like,

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
greetings+=(Greeting|Greetings)*;

Greeting:
'Hello' name=ID '!';

Greetings:
'Hello2' name=ID '!';

In the runtime editor, editor allowing two statements in single line like,

index.php/fa/27179/0/

But for every statement it should start with new line. How to do that?

I have create NL terminal rule like,

Greeting:
'Hello' name=ID '!' NL+;

Greetings:
'Hello2' name=ID '!' NL+;

terminal NL : ('\r'? '\n')+;

But if the I use this rule wiith statements its showing at last line of the code expecting new line. How to solve if I am at last line then it should not show error?

index.php/fa/27181/0/
  • Attachment: newline.png
    (Size: 0.55KB, Downloaded 1013 times)
  • Attachment: newline2.png
    (Size: 8.22KB, Downloaded 1015 times)

[Updated on: Fri, 23 September 2016 10:56]

Report message to a moderator

Re: xtext rules starts at new line [message #1744220 is a reply to message #1744204] Fri, 23 September 2016 12:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
your grammar says that a greeting has to end with a newline.
if you dont want that you have to state that with the comma separated list pattern


List: (elements+=Element ("," elements+=Element)* )?

in your case

List: (elements+=Element (NL+ elements+=Element)* )?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext rules starts at new line [message #1744231 is a reply to message #1744220] Fri, 23 September 2016 13:44 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I tried llike this

class CustomSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider {
override SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
if(!context.getDefaultMessage().equals("required (...)+ loop did not match anything at input '<EOF>'"))
return new SyntaxErrorMessage(context.getDefaultMessage(), SYNTAX_DIAGNOSTIC);
}

override SyntaxErrorMessage getSyntaxErrorMessage(IValueConverterErrorContext context) {
val ValueConverterException cause = context.getValueConverterException();
if (cause instanceof ValueConverterWithValueException) {
val ValueConverterWithValueException casted = cause as ValueConverterWithValueException;
if (casted.hasRange()) {
return createRangedSyntaxErrorMessage(context, casted.getOffset(), casted.getLength());
}
}
return new SyntaxErrorMessage(context.getDefaultMessage(), SYNTAX_DIAGNOSTIC);
}
}
Problem solved.
Is it a good practice?
Re: xtext rules starts at new line [message #1744235 is a reply to message #1744231] Fri, 23 September 2016 13:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
I think it is a inferior solution

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: xtext rules starts at new line [message #1744238 is a reply to message #1744235] Fri, 23 September 2016 14:15 Go to previous messageGo to next message
Sachin Samaram is currently offline Sachin SamaramFriend
Messages: 271
Registered: April 2016
Senior Member
I will check try your guidelines
Re: xtext rules starts at new line [message #1744548 is a reply to message #1744238] Wed, 28 September 2016 06:55 Go to previous message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
BTW: is there any way to define a rule which accepts the complete rest of the line (in my example starting with "here"):
test=ID context=MyContext "just a string" here starts the text we want to ## have in our variable line_trailer

'test=' test=ID 'context=' context=ID aString=STRING line_trailer=?????????????????
Previous Topic:Unable to use a declaration in assignments and if conditions
Next Topic:Grammar Mixins
Goto Forum:
  


Current Time: Fri Apr 19 05:54:17 GMT 2024

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

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

Back to the top