Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Whitespace issue with nested blocks
Whitespace issue with nested blocks [message #1849836] Fri, 04 February 2022 06:53 Go to next message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 352
Registered: July 2009
Senior Member
Hello,
I am trying to build a rather small grammar that allows nested segments. First I tried to do it with BEGIN...AND to make it whitespace-aware, but failed to get it working in the first attempt. Hence, I switched back to brackets.

This works fine except that the closing bracket of a nested block does not allow whitespace / indentation.

Here is the relevant part of the grammar:
Segment:
    'segment' subject=Subject
    '{'
    body=SegmentBody
    NL+
    WS* '}'
;

SegmentBody: {SegmentBody}
    (rules+=Rule (NL+ rules+=Rule)*)+
    (segments+=Segment (segments+=Segment)*)?
;


This works fine:

segment Element {
    Abc is Def
    segment ChildElement {
        Abc is Def
}
}


But this does not:

segment Element {
    Abc is Def
    segment ChildElement {
        Abc is Def
    }      <-- no viable input at '}'
}


Can't understand why it does not allow the space chars since I explicitly allowed them using
WS* '}'


What am I missing?

Thanks for your assistance.

[Updated on: Fri, 04 February 2022 06:54]

Report message to a moderator

Re: Whitespace issue with nested blocks [message #1849960 is a reply to message #1849836] Wed, 09 February 2022 20:46 Go to previous messageGo to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 250
Registered: May 2012
Senior Member
What do your terminals look like? Is your WS terminal hidden (ie stripped out and ignored)? Maybe there's a sneaky residual WS token handling from your previous synthetic BEGIN white space experiments?
Re: Whitespace issue with nested blocks [message #1849961 is a reply to message #1849960] Wed, 09 February 2022 21:13 Go to previous message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 352
Registered: July 2009
Senior Member
No "hidden" statement in my grammar, but I have this defined:
with org.eclipse.xtext.common.Terminals
which includes
hidden(WS, ML_COMMENT, SL_COMMENT)

In my grammar there are only these lines:
terminal NL: ('\r'? '\n');
//override terminal WS: (' '|'\t'|'\r'|'\n')+;


Do I need to add
hidden(WS)
explicitly to my parser rules?
Previous Topic:Cascading Xtext Generators
Next Topic:XBase Imports with Cross References to Another File
Goto Forum:
  


Current Time: Mon Oct 03 03:02:47 GMT 2022

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

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

Back to the top