Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 315581 - Backtracking swallows grammar errors
Summary: Backtracking swallows grammar errors
Status: NEW
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext Backlog (show other bugs)
Version: 1.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P5 major (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 326811
Blocks:
  Show dependency tree
 
Reported: 2010-06-03 09:31 EDT by Henrik Lindberg CLA
Modified: 2012-11-14 04:11 EST (History)
1 user (show)

See Also:
sebastian.zarnekow: indigo+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Henrik Lindberg CLA 2010-06-03 09:31:26 EDT
I have been plagued for a while with getting "the required loop (...)+ at xxx" did not match any input, and have now figured out what I did in my (b3) grammar to trigger this.

With this grammar (where everything in the unordered group is optional):

BeeModel returns build::BeeModel hidden(WS, SL_COMMENT, ML_COMMENT) : {build::BeeModel}
    (imports += Import)*
    ( (functions += Function)  *
    & (concerns += Concern_Named) *
    & (propertySets += PropertySet_Named) *
    & (buildUnits += BuildUnit) *
    & (providers += TopLevelUnitProvider) ?
    & (repositories += Repository) *
    & (defaultProperties = PropertySetDefault) ?
    )?
    ;

If there is anything wrong while parsing the 'Function' rule - say it was given the faulty "function two : 1 + ;" b3 expression I get the "(...)+" error message and it marks the keyword "function". This is really bad when the function has many expressions and deep nesting.

If I however change the grammar to:

BeeModel returns build::BeeModel hidden(WS, SL_COMMENT, ML_COMMENT) : {build::BeeModel}
    (imports += Import) //*
    ( (functions += Function)  //*
    | (concerns += Concern_Named) //*
    | (propertySets += PropertySet_Named) //*
    | (buildUnits += BuildUnit) //*
    | (providers += TopLevelUnitProvider) //?
    | (repositories += Repository) //*
    | (defaultProperties = PropertySetDefault) //?
    )*
    ;

I get the correct error marker on the last '+' sign, and a meaningful error message.
(There are issues with this grammar, as two of the assignments will cause dangling instances as input may overwrite). The former grammar is also what I really want - I want the various statements to be grouped (i.e. all functions should be in one group), but the groups can be in any order. When input is correct, it correctly parses it this way.

This issue basically makes it impossible for me to use unordered groups.
Comment 1 Sebastian Zarnekow CLA 2010-06-17 12:06:55 EDT
Assumingung the following model:

|function someFun() {
  Integer x = 1+
}

and | as current parser offset (a): The parser will try to simulate a function (backtracking == true) and fail at the + sign (b). Afterwards, it will decide that there is no alternative to be choosen at the offset (a) and mark the token with an error. However, the actual error is at offset (b). If the body becomes more complex, it is hard to see why the parser failed with the given input.
Comment 2 Sebastian Zarnekow CLA 2010-08-05 07:39:48 EDT
Since I did not find a way to fix this in SR1, I'll reschedule this one for Indigo.
Comment 3 Sebastian Zarnekow CLA 2010-10-04 04:36:44 EDT
I hope that Antlr 3.2 allows to fix this issue. Added dependency to bug 326811
Comment 4 Sven Efftinge CLA 2012-11-14 04:11:49 EST
Can someone verify if this has been fixed in the meantime?