| Want to directly call generated parser [message #554905] |
Tue, 24 August 2010 12:41  |
Rob Messages: 3 Registered: August 2010 |
Junior Member |
|
|
I would like to call the generated parser generated by xtext. In the previous version I was able to use a special workflow file.
With the new mwe2 workflow format I am a bit lost.
I tried creating the parser directly:
fr = new FileReader("scripts/test1.mrk");
LexerProvider lp = new LexerProvider(InternalMarkerLexer.class);
mp.setLexerProvider(lp);
IParseResult ipr = mp.parse(fr);
fr.close();
But I do not know what to do with the TokenDefProvider and the above code bails out with a null pointer exception on that object.
Does somebody have a snippet or suggestion of how to call the generated parser from Java ?
|
|
|
|
|
|
|
|
|
| Re: Want to directly call generated parser [message #554997 is a reply to message #554956] |
Wed, 25 August 2010 02:41  |
Sven Efftinge Messages: 1667 Registered: July 2009 |
Senior Member |
|
|
Am 8/24/10 11:38 PM, schrieb Rob:
> Thanks guys,
>
> With your info I could get it done. This is the snippet that does the
> trick:
>
> Injector injector = new
> MarkerStandaloneSetup().createInjectorAndDoEMFRegistration() ;
> ResourceSet set = injector.getInstance(ResourceSet.class);
>
> URI uri = URI.createFileURI("scripts/test1.mrk");
> Resource res = set.getResource(uri, true);
> Object obj = res.getContents().get(0);
> Model model = (Model) obj;
>
> EList<Diagnostic> syntaxErrors = res.getErrors();
And if you are interested in semantic errors (i.e. validation) as well,
you should use
((XtextResource)res).getResourceServiceProvider().getResourc eValidator().validate(res,.....)
Sven
--
--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
|
|
|
Powered by
FUDForum. Page generated in 0.01700 seconds