Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Antlr version
Antlr version [message #1694827] Fri, 08 May 2015 09:09 Go to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
Hello.

Which version of antlr 3 does XText uses?
Re: Antlr version [message #1694976 is a reply to message #1694827] Mon, 11 May 2015 07:28 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
It's a patched version of Antlr 3.2.1 to allow to run with Java8, too.

Why do you ask?

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Antlr version [message #1694977 is a reply to message #1694976] Mon, 11 May 2015 07:36 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
I planned to implement a custom lexer and wanted to avoid using features of antlr not supported by the version XText uses.
Re: Antlr version [message #1695028 is a reply to message #1694977] Mon, 11 May 2015 13:12 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
Could you outline the reason why you need a custom lexer or is that
beyond this question?

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Re: Antlr version [message #1695041 is a reply to message #1695028] Mon, 11 May 2015 14:39 Go to previous messageGo to next message
Anakreontas Mentis is currently offline Anakreontas MentisFriend
Messages: 85
Registered: October 2014
Member
The DSL I'm working on contains sections with different lexing rules. Keywords of one section might be identifiers in another one. My first approach was to include lexer modes in a custom lexer. This does not work since modes are not supported in Antlr3. The second approach was to disable some lexer rules based on a predicate. However, I discovered that syntax highlighting is disabled for keywords that are not described as literal strings in the parser even when I do not use a custom lexer.

For example if I change a rule in the parser:
Field : 'field' ',' ...
to
Field : T_FIELD T_COMMA
where T_FIELD is a lexer rule defined as
T_FIELD : 'field' ;

keyword field is no longer highlighted and the lexer rule is case sensitive even though I have set the parser fragment option:
fragment = org.eclipse.xtext.generator.parser.antlr.ex.rt.AntlrGeneratorFragment {
options = {
ignoreCase = true
//backtrackLexer = true
}
}

In a custom lexer the case sensitive matching would work but I do not want to lose syntax highlighting.

Finally I settled for the sub-optimal solution where I define a parser for both languages that recognizes as keywords the union of keywords applicable to each language.
Re: Antlr version [message #1695282 is a reply to message #1695041] Wed, 13 May 2015 09:52 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3109
Registered: July 2009
Senior Member
If you need to use keywords as identifiers in some parts of the grammar,
the recommend approach is to use datatype rules:

ValidID: ID | 'keyword';

ValidIDInAnotherGrammarPart: ID | 'keyword2';

Best,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Find help at http://xtext.itemis.com or xtext(@)itemis.com
Blog: zarnekow.blogspot.com
Twitter: @szarnekow
Google+: https://www.google.com/+SebastianZarnekow
Previous Topic:Validation in Xtext
Next Topic:code gen. /no duplicate
Goto Forum:
  


Current Time: Sat May 08 12:42:18 GMT 2021

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

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

Back to the top