Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Dealing with Eclipse XText syntax errors(How and where can I deal with XText-produced syntax errors)
Dealing with Eclipse XText syntax errors [message #1746058] Thu, 20 October 2016 22:23 Go to next message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
I have two questions concerning Xtext-produced syntax errors:

1) Where are these produced by default in the code and how can I override the default text/behavior, etc. In particular I want to change the text produced for a message AND perhaps even turn off the error or remove the error from Eclipse if semantically I determine that it actually is not an error.

2) Going along with #1, I would like to know where in the code (XText or Eclipse) I can programmatically manipulate the "Problems" tab at the bottom of the Eclipse IDE that is running with XText. I may determine that some "error" that Xtext finds according to the grammar is actually not an error, so I would like to catch that in the code somewhere and perhaps remove errors from the Problems list or add different errors to the list such as semantic errors that are found

Can someone please help me see how I can do these two things? I have not been successful at finding any of this in the forums.

Thanks!
Re: Dealing with Eclipse XText syntax errors [message #1746062 is a reply to message #1746058] Fri, 21 October 2016 03:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11311
Registered: July 2009
Senior Member
is this about the messages or the errors. the errors are created by antlr. the messages by ISyntaxErrorMessageProvider

(possible pointers: via org.eclipse.xtext.resource.XtextResource.addSyntaxDiagnostic(List<Diagnostic>, INode) and org.eclipse.xtext.validation.ResourceValidatorImpl.issueFromXtextResourceDiagnostic(Diagnostic, Severity, IAcceptor<Issue>) )
messages about linking erros (cross references that cannot be resolved) are produced by ILinkingDiagnosticMessageProvider

i am not sure if it is a good idea to suppress the messages at all,
cause the error recovery might not work that good as you expect.
and the node model contains errors.
so i wonder why you dont fix the parser in the first place

i cannot say what you exactly need to do to throw away a diagnostic,
maybe returning null works.

(https://www.eclipse.org/forums/index.php/m/1722921/?srch=ISyntaxErrorMessageProvider#msg_1722921 indicates that)



Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com

[Updated on: Fri, 21 October 2016 04:02]

Report message to a moderator

Re: Dealing with Eclipse XText syntax errors [message #1746071 is a reply to message #1746058] Fri, 21 October 2016 09:56 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 746
Registered: July 2009
Location: Hamburg
Senior Member
Ad 2)
The problems view shows all error markers. This is an Eclipse concept, so google for error markers eclipse to get more information. I would not recommend to programmatically remove error markers. For example, if you remove markers for dangling cross-references, some other components relying on a valid model will fail (e.g. a code generator). What kind of errors do you want to delete?

You usually add what you call semantic errors in Xtext by implementing a validator.
This is usually the first extension you make to the language after defining the grammar. Have a look at the Xtext docs for more details.

In addition, we have some provisional API for configurable issue severities, i.e. that the user can decide, whether an encountered issue is an error, a warning, or ignored. You can have a look at how we did that for Xbase: XbaseConfigurableIssueCodes for the registration and XbaseValidationConfigurationBlock for the UI part. Maybe you can derive something that fits your needs.


---
Get professional support from the Xtext committers at www.typefox.io
Re: Dealing with Eclipse XText syntax errors [message #1746323 is a reply to message #1746071] Wed, 26 October 2016 22:52 Go to previous messageGo to next message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
As a first step in dealing with Xtext syntax errors, I have tried to write the code to catch them and perhaps change them (override the default). I am having problems with the Xtend part of this. I wrote the SyntaxErrorMessageProvider with the following code (I copies someone else's getSyntaxErrorMessage just to get it to build--I'll write my own when all builds without error). No errors are shown in this code:

public class DomainSyntaxErrorMessageProvider extends SyntaxErrorMessageProvider
{

public static String INCOMPLETE_UNORDERED_GROUP = "INCOMPLETE_UNORDERED_GROUP";

@Override
public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
if (context.getRecognitionException() instanceof FailedPredicateException) {
return new SyntaxErrorMessage(
"The following elements are necassary for an adapter inctance: Name, Tool and Model",
INCOMPLETE_UNORDERED_GROUP);
}
return super.getSyntaxErrorMessage(context);
}


}

My problem is with the <lang>RuntimeModule.xtend module. It gives me errors. Here it is:

/*
* generated by Xtext 2.10.0
*/
package com.mmm.domainXtext

import org.eclipse.xtext.parser.antlr.ISyntaxErrorMessageProvider

/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*/
class DomainRuntimeModule extends AbstractDomainRuntimeModule {
public Class<? extends ISyntaxErrorMessageProvider> bindISyntaxErrorMessageProvider() {
return DomainSyntaxErrorMessageProvider.class;
}
}

I copies this "registration" type code from other blog messages. I am very novice and I have no idea what the xtend is doing. I get the following errors:

Multiple markers at this line
- mismatched input '.' expecting '}'
- The field DomainSyntaxErrorMessageProvider needs an explicit
type since there is no initialization expression to infer the
type from.
- no viable alternative at input ';'
- The value of the field DomainRuntimeModule.DomainSyntaxErrorMessageProvider
is not used


Any suggestions for what I am doing wrong would be greatly appreciated.

Thanks,
Larry
Re: Dealing with Eclipse XText syntax errors [message #1746326 is a reply to message #1746323] Thu, 27 October 2016 04:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11311
Registered: July 2009
Senior Member
Q' note sure if I get that
Your question is about the binding method xtend syntax ?

def Class<? extends ISyntaxErrorMessageProvider> bindISyntaxErrorMessageProvider() {
return DomainSyntaxErrorMessageProvider
}

I recommend you some reading on xtend syntax


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: Dealing with Eclipse XText syntax errors [message #1746361 is a reply to message #1746326] Thu, 27 October 2016 13:27 Go to previous message
Larry Cousin is currently offline Larry CousinFriend
Messages: 15
Registered: September 2016
Junior Member
Thank-you that worked. Yes, I certainly need to learn more about xtend. Working with Xtext has been an interesting but rigorous process. There is no single place to learn about google injection, Antlr, Xtext, xtend and how they work together. I have the Xtext book, but I have found it to not be a great learning resource if one knows nothing about all this. The Xtext web site was a good start, but I have found that searching the blogs and asking questions has been a better learning avenue.

Xtext is a powerful tool. I have learned that much. By augmenting it with my own custom lexer, I have been able to quickly adapt a very complex Bison grammar into Antlr/Xtext form and parse and process very long DSL programs (12MB in seconds). Learning the tool has been a challenge, but the rewards have been significant.
Previous Topic:[SOLVED] Xtext editor crashes when deployed as part of product
Next Topic:Embeded single line editor
Goto Forum:
  


Current Time: Sun Oct 22 01:07:59 GMT 2017

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

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