Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [XText] a standalone Java application that parses text to model
[XText] a standalone Java application that parses text to model [message #45761] Thu, 28 May 2009 07:52 Go to next message
Eclipse UserFriend
Hi,
Would you please show an example standalone Java application that parses text to model using the parser generated by XText?
Thanks.
Michael.
Re: [XText] a standalone Java application that parses text to model [message #45791 is a reply to message #45761] Thu, 28 May 2009 08:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi Michael,

please try something like this:

ISetup setup = new MyLanguageStandaloneSetup();
Injector injector = setup.createInjectorAndDoEMFRegistration();
XtextResourceSet rs = injector.getInstance(XtextResourceSet.class);
rs.setClasspathURIContext(getClass());

IResourceFactory resourceFactory =
injector.getInstance(IResourceFactory.class);
XtextResource resource =
(XtextResource) resourceFactory.createResource(uri);
rs.getResources().add(resource);

InputStream in = ... // your "text" goes here
resource.load(in, null);
EcoreUtil.resolveAll(resource);

if (!resource.getErrors().isEmpty())
// resource is erroneous ..

EObject model = resource.getParseResult().getRootASTElement();


Hope that helps,
Sebastian




Am 28.05.2009 13:52 Uhr, schrieb Michael:
> Hi,
> Would you please show an example standalone Java application that parses
> text to model using the parser generated by XText?
> Thanks.
> Michael.
Re: [XText] a standalone Java application that parses text to model [message #45820 is a reply to message #45791] Thu, 28 May 2009 08:37 Go to previous message
Eclipse UserFriend
Oops, forget to mention a small detail, please find it below:

Am 28.05.2009 14:31 Uhr, schrieb Sebastian Zarnekow:
> Hi Michael,
>
> please try something like this:
>
> ISetup setup = new MyLanguageStandaloneSetup();
> Injector injector = setup.createInjectorAndDoEMFRegistration();
> XtextResourceSet rs = injector.getInstance(XtextResourceSet.class);
> rs.setClasspathURIContext(getClass());
>
> IResourceFactory resourceFactory =
> injector.getInstance(IResourceFactory.class);
URI uri = URI.create(..); // uri of your resource, may be fictional
> XtextResource resource =
> (XtextResource) resourceFactory.createResource(uri);
> rs.getResources().add(resource);
>
> InputStream in = ... // your "text" goes here
> resource.load(in, null);
> EcoreUtil.resolveAll(resource);
>
> if (!resource.getErrors().isEmpty())
> // resource is erroneous ..
>
> EObject model = resource.getParseResult().getRootASTElement();
>
>
> Hope that helps,
> Sebastian
>
>
>
>
> Am 28.05.2009 13:52 Uhr, schrieb Michael:
>> Hi,
>> Would you please show an example standalone Java application that parses
>> text to model using the parser generated by XText?
>> Thanks.
>> Michael.
>
Previous Topic:Xtext and error recovery in block-level statements
Next Topic:[XText] Outline is slow on scrolling
Goto Forum:
  


Current Time: Wed May 07 21:29:02 EDT 2025

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

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

Back to the top