Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Localization in the IParserErrorContext(How to get the exact position of an Error)
Localization in the IParserErrorContext [message #1743679] Sun, 18 September 2016 22:21 Go to next message
Jonathan L. is currently offline Jonathan L.Friend
Messages: 24
Registered: May 2016
Junior Member
Hi,

I got Problems with locating within the IParserErrorContext in the SyntaxErrorMessageProvider.

So I'm wondering if there is some kind of a best practice for this.

I got the following example grammar rule:
Dcl_var:
  'var' type=Type name=ID_VAR;

terminal ID_VAR:
  (('a'..'z') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_')*) | '_';

when I now want to check that the name-feature is wrong, I'm doing this with the following:
if (context.currentNode.semanticElement.eClass.name == "Dcl_var" // getting the violated rule
	&& context?.currentNode?.previousSibling?.semanticElement.eClass.name == "Type") {  //checking that 'name' is wrong and not 'type'
   // code for returning Message
}

In this case this works but not with other rules that are similar.
Is there maybe a way to get the exact position of a terminal rule?
Re: Localization in the IParserErrorContext [message #1743698 is a reply to message #1743679] Mon, 19 September 2016 06:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
The node/context should give you other information e.g. The grammar element for example

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Localization in the IParserErrorContext [message #1743708 is a reply to message #1743698] Mon, 19 September 2016 07:13 Go to previous messageGo to next message
Jonathan L. is currently offline Jonathan L.Friend
Messages: 24
Registered: May 2016
Junior Member
That's what I'm asking for..
The only Information I've found to get out of the context is the one above.

Or is "context.currentNode.semanticElement.eClass.name" already the right way?

My goal would be to get the rule ID_VAR instead of Dcl_var if violated.
Re: Localization in the IParserErrorContext [message #1743710 is a reply to message #1743708] Mon, 19 September 2016 07:45 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
it depends on the rest of your grammar and how the parser interprets the wrong input:

you may have a look

-at the current Nodes grammar element
- at the recognitionException
- ......


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Multiple file support in IDEA plugin
Next Topic:Decision tables in Xtext
Goto Forum:
  


Current Time: Thu Apr 25 11:22:23 GMT 2024

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

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

Back to the top