Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Extracting keywords from grammar for highlighting
Extracting keywords from grammar for highlighting [message #649150] Mon, 17 January 2011 17:21 Go to next message
Eclipse UserFriend
I have replaced the default ITokenScanner by my own RuleBasedScanner. One thing that the RuleBasedScanner needs is a list of tokens from the grammar. I thought it would be nice if I automatically extract that information from the grammar. So I added a IGrammarAccess field to my derived scanner.

	@Inject
	private IGrammarAccess grammarAccess;


From there, I can get at the rules and the tokens.

However, now during startup Guice is complaining (I suspect it has something to do with circular dependencies but I'm not sure.)

java.lang.NullPointerException
	at com.sigasi.xtext.ui.VHDLLangTokenScanner.getKeywords(VHDLLangTokenScanner.java:134)
	at com.sigasi.xtext.ui.VHDLLangTokenScanner.<init>(VHDLLangTokenScanner.java:78)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:530)
...


Any suggestions to get at the grammar would be greatly appreciated.
Re: Extracting keywords from grammar for highlighting [message #649168 is a reply to message #649150] Mon, 17 January 2011 19:30 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mark,

I'd assume from the stacktrace that the keywords are extracted in the
constructor. However, field injection will be done after the constructor
has finished. You may want to use a custom constructor that takes the
grammar access as a parameter and is annotated with @Inject. Guice will
pick this one instead of the default constructor to create an instance
of the given type.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 17.01.11 23:21, schrieb Mark Christiaens:
> I have replaced the default ITokenScanner by my own RuleBasedScanner.
> One thing that the RuleBasedScanner needs is a list of tokens from the
> grammar. I thought it would be nice if I automatically extract that
> information from the grammar. So I added a IGrammarAccess field to my
> derived scanner.
>
> @Inject
> private IGrammarAccess grammarAccess;
>
>
> From there, I can get at the rules and the tokens.
> However, now during startup Guice is complaining (I suspect it has
> something to do with circular dependencies but I'm not sure.)
>
>
> java.lang.NullPointerException
> at
> com.sigasi.xtext.ui.VHDLLangTokenScanner.getKeywords(VHDLLan gTokenScanner.java:134)
>
> at
> com.sigasi.xtext.ui.VHDLLangTokenScanner.<init>(VHDLLangTokenScanner.java:78)
>
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Nativ e Method)
> at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(Native ConstructorAccessorImpl.java:57)
>
> at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(De legatingConstructorAccessorImpl.java:45)
>
> at java.lang.reflect.Constructor.newInstance(Constructor.java:5 30)
> ..
>
>
> Any suggestions to get at the grammar would be greatly appreciated.
Re: Extracting keywords from grammar for highlighting [message #649216 is a reply to message #649168] Tue, 18 January 2011 04:08 Go to previous message
Eclipse UserFriend
Beautiful! Works like a charm. Thanks.

I really like that in Xtext I have a model that describes the grammar. Very useful.
---
Mark Christiaens
Discover the Future of VHDL Design
Go to www.sigasi.com
Previous Topic:meaning of brackets in dsl
Next Topic:Xpand scanning files in sub-directories
Goto Forum:
  


Current Time: Sun Jul 27 15:21:48 EDT 2025

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

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

Back to the top