Reputation: 170805
I have the following grammar:
grammar ru.focusmedia.fire.idl.IDL with org.eclipse.xtext.xbase.Xbase
generate idl "http://www.focusmedia.ru/fire/idl/IDL"
Model:
'package' package=QualifiedName
imports+=Import*
typeDefs+=TypeDef+;
...
So the string asd
should fail to parse, as should anything not starting with package
. I expected ParseHelper.parse("asd")
to throw an exception or to return null
, but it does neither. How do I recognize that parsing failed?
Upvotes: 1
Views: 256
Reputation: 6729
You can query the resource that contains the parse result for errors by means of Resource#getErrors. Something like resultFromParseHelper.eResource().getErrors()
should do the trick.
Using junit:
Assert.assertEquals(result.eResource().getErrors().toString,0,result.eResource().getErrors().size)
Upvotes: 4