Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Beginning of Line specification in XText Grammar(Beginning of Line specification in XText Grammar)
Beginning of Line specification in XText Grammar [message #662533] Thu, 31 March 2011 01:34 Go to next message
Abhir Joshi is currently offline Abhir JoshiFriend
Messages: 1
Registered: September 2010
Location: Austin, TX
Junior Member
Hi,

Is there a way to specify the Beginning of Line in an XText rule?

The single line comment uses "('\r'? '\n')?" for End of Line. But there is no such special character which we can use to match for beginning of line. I suppose we will need some support from the XText grammar syntax for this.


Abhir
Re: Beginning of Line specification in XText Grammar [message #662563 is a reply to message #662533] Thu, 31 March 2011 07:06 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

as far as I know, there is no out of the box support for this.

Alex
Re: Beginning of Line specification in XText Gr ammar [message #662591 is a reply to message #662533] Thu, 31 March 2011 08:41 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You can do things like adding "synthetic" tokens by writing an external
lexer using antlr. The integration of an external lexer is supported, you
"just" have to write this lexer.
Mwe2 uses one, and you can find an example in cloudsmith/geppetto at
github. Neither has support for a start of line, but shows how the parts
fit together.

An alternative to using tokens for start of line, and may be easier is to
let the lexer keep track of this, and instead base recognition of other
tokens based on if it is "first on line". This way you avoid cluttering the
grammar with this knowledge.

This is done with predicates in the lexer. There are examples in both the
mwe and geppetto external lexers.

- henrik
Abhir Joshi <abhir.joshi@gmail.com> wrote:
> Hi,
>
> Is there a way to specify the Beginning of Line in an XText rule?
>
> The single line comment uses "('\r'? '\n')?" for End of Line. But there
> is no such special character which we can use to match for beginning of
> line. I suppose we will need some support from the XText grammar syntax for this.
>
>
> Abhir


--
- henrik
Previous Topic:Parsing comments
Next Topic:XtextBuilder - StackOverflowError
Goto Forum:
  


Current Time: Fri Mar 29 01:11:53 GMT 2024

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

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

Back to the top