Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to detect parse errors when loading from ResourceSet?
How to detect parse errors when loading from ResourceSet? [message #1391675] Tue, 01 July 2014 08:34 Go to next message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
Hey!

I have a slight Problem with Xtext 2.6.0 (and possibly all other versions Wink):

I have some code to read my model files and put them all together on one big bunch. it looks like this currently:

	/**
	 * Loads the model from a set of spread out recources,
	 * resolving all Proxies and patching the model
	 */
	def load(ModelResourceProvider provider) {
		var fcnt = 0

		for (URI uri : provider.resources) {

			// fill up resource set.
			val rsrc = resourceSet.getResource(uri, true);
			for(item : rsrc.warnings) {
				log.warn(uri.lastSegment + ":" + item.line + ":" + item.column + ": " + item.message)
			}
			
			val diag = Diagnostician.INSTANCE.validate(rsrc.contents.get(0));

			switch (diag.severity) {
				case Diagnostic.ERROR: {
					log.error(uri.lastSegment + " contains errors:")
					diag.children.logIt
				}
				case Diagnostic.WARNING: {
					log.warn(uri.lastSegment + " contains warnings:")
					diag.children.logIt
				}
			}

			fcnt += 1
		}

		for (Resource r : resourceSet.resources) {
			EcoreUtil2.resolveLazyCrossReferences(r, null);
		}

		contents = resourceSet.resources.map(r|r.allContents.toIterable).flatten.filter(TopLevelElement)
		packages = resourceSet.resources.map(r|r.allContents.toIterable).flatten.filter(Package)
		patcher.patch(contents)
	}


my files look somewhat like this:

package dbtest;

abstract persistent AbstractContExt {
	directed connection [*] to ContInt2 int2 [0..1];
}


which loads fine, yields no warnings, all is well Smile but... when i put a syntax error in there:

package dbtest;

abstract persistent AbstractContExt {
	an error;
	directed connection [*] to ContInt2 int2 [0..1];
}


the code /still/ loads the file fine (!?@!). I just get an empty AbstractContExt instance... what is going on here? Which kind of "give me errors" switch did I miss?

Thanks a lot in advance Smile
Re: How to detect parse errors when loading from ResourceSet? [message #1391719 is a reply to message #1391675] Tue, 01 July 2014 09:51 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
Hi,

> val rsrc = resourceSet.getResource(uri, true);
> for(item : rsrc.warnings) {
> log.warn(uri.lastSegment + ":" + item.line + ":" +
> item.column + ": " + item.message)
> }

Did you try to look in rsrc.errors? I'm no Xtext expert though...

Felix
Re: How to detect parse errors when loading from ResourceSet? [message #1391768 is a reply to message #1391719] Tue, 01 July 2014 11:40 Go to previous message
Markus Duft is currently offline Markus DuftFriend
Messages: 148
Registered: February 2013
Senior Member
haha, seems today is not my day. code completion cheated on me - i was looking for .errors but could only find .warnings (why? idk... Neutral ) however of course it's there and it works as expected. thanks Smile
Previous Topic:Problem using the Xtext serializer
Next Topic:Adding a terminal makes UI editor fail?
Goto Forum:
  


Current Time: Sat Apr 20 06:15:58 GMT 2024

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

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

Back to the top