Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Stop lexing and parsing at first error?
icon5.gif  Stop lexing and parsing at first error? [message #646445] Fri, 24 December 2010 10:23 Go to next message
Andreas Semt is currently offline Andreas SemtFriend
Messages: 3
Registered: December 2010
Junior Member
Greetings everybody,

Is it possible with Xtext 1.0.1 to tell the underlying ANTLR to stop
the lexing and parsing process at the first detected error?

At least it is possible with a standalone ANTLR, as discussed here:
http:// stackoverflow.com/questions/2445008/how-to-get-antlr-3-2-to- exit-upon-first-error.

Thanks for any help and Happy Christmas!


Best regards,
Andreas Semt
Re: Stop lexing and parsing at first error? [message #646452 is a reply to message #646445] Fri, 24 December 2010 11:44 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

why would you want that (i.e. what do you want to achieve)? If you are in an editor context, you often have partial models and losing all functionality because of a single parse error is not very user friendly.
If you have workflows that generate someting from a model, many components have a flag telling them to stop on errors.

Alex
Re: Stop lexing and parsing at first error? [message #646491 is a reply to message #646452] Sat, 25 December 2010 13:34 Go to previous messageGo to next message
Andreas Semt is currently offline Andreas SemtFriend
Messages: 3
Registered: December 2010
Junior Member
Hello Alexander,

Quote:
why would you want that (i.e. what do you want to achieve)?


The problem I see is, that a user of the DSL in the editor makes one single error (for example forgetting to type a required symbol) and gets a whole bunch of markers shown, indicating other, unrelated errors. That behavior is IMHO not very user friendly, especially for untrained users.

So why not:
- stop the lexing and parsing process at the first error,
- show only this single error to the user,
- let the user correct this error,
- restart the lexing and parsing process.

Quote:
If you are in an editor context, you often have partial models and losing all functionality because of a single parse error is not very user friendly.


Perhaps you are right, however two much shown subsequent errors caused by a single 'real' error may be to much information to handle for an untrained user.


Best regards,
Andreas Semt
Re: Stop lexing and parsing at first error? [message #646505 is a reply to message #646491] Sat, 25 December 2010 21:37 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
The generated ANTLR parser already does quite a bit of error recovery. In general, good error recovery is one of the hardest parts of the parser. So, I'd expect to see some unrelated errors
but the rest of the DSL text shouldn't be red unless your grammar happens to be really susceptible for that.


Re: Stop lexing and parsing at first error? [message #646549 is a reply to message #646491] Mon, 27 December 2010 20:34 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

adding to Meinte's comment as to error recovery, I could imagine that
users might well get frustrated, if they are forced to correct one
"stupid" error ("you are not allowed to write 'a' here") after the other
before getting feedback about model parts that they are really
interested in. (Imagine your intended behaviour in a java editor)

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: Stop lexing and parsing at first error? [message #646626 is a reply to message #646549] Wed, 29 December 2010 12:17 Go to previous messageGo to next message
Andreas Semt is currently offline Andreas SemtFriend
Messages: 3
Registered: December 2010
Junior Member
Hello Meinte, Alexander,

@Alexander:
Quote:
adding to Meinte's comment as to error recovery, I could imagine that
users might well get frustrated, if they are forced to correct one
"stupid" error ("you are not allowed to write 'a' here") after the other
before getting feedback about model parts that they are really
interested in. (Imagine your intended behaviour in a java editor)


The problem with the feedback about model parts you describe is not a concern for me, because the evaluation of the parsed input plus the instantiated semantic model happens in a separate step out of the editor in my case. So the job of the editor is mainly to ensure a valid syntax of the simple DSL (some small semantical checks also happens in the editor).

So i attempt to answer my own question:
It's not possible to tell the underlying, through ANTLR generated parser to stop the lexing and parsing process at the first detected error. Is that correct?

By all means thanks for the discussion!


Best regards,
Andreas Semt
Re: Stop lexing and parsing at first error? [message #646847 is a reply to message #646626] Sat, 01 January 2011 11:43 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

sorry, an answer from a couple of das ago seems not to have made it, so
here it is again (somewhat condensed).

1. Stopping lexing does not make sense.
2. What is the parser supposed to do with the document that remains
unparsed after the first error.
3. Creating the markers should cause a performance problem, so the
document could be parsed completely and all errors created, but you
don't show them all.
(If this is not correct in your case, file an enhancement request
containing a reproducible example)

In order to achieve the "filtering" of the errors, I did the following
in a sample project. Bind my own XtextResource implementation in the
RuntimeModule:

@Override
public Class<? extends XtextResource> bindXtextResource() {
return MyXtextResource.class;
}


override the getError method in that implementation removing every but
the first error
@Override
public EList<Diagnostic> getErrors() {
EList<Diagnostic> result = super.getErrors();
if(result!=null &&result.size()>1){
for (int i = 1; i < result.size(); i++) {
result.remove(i);
}
}
return result;
}

Maybe something similar is working for you as well.

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Previous Topic:crossreference to other file
Next Topic:oaw -> XText howto?
Goto Forum:
  


Current Time: Fri Apr 26 05:16:03 GMT 2024

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

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

Back to the top