Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 287443

Summary: <Language>Parser.java does not use guice injection to create lexer
Product: [Modeling] TMF Reporter: dakshinamurthy.karra
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: minor    
Priority: P3 CC: dakshinamurthy.karra, sebastian.zarnekow, sven.efftinge, voelter
Version: unspecifiedKeywords: helpwanted
Target Milestone: M2   
Hardware: All   
OS: All   
Whiteboard:

Description dakshinamurthy.karra CLA 2009-08-24 10:10:51 EDT
I am trying to use bind a different lexer than the generated InternalMyDslLexer. The generated MyDslParser class creates InternalMyDslLever. It should be using guice to get the lexer.

-- KD
Comment 1 Sebastian Zarnekow CLA 2009-08-24 10:19:52 EDT
Although it may be possible to inject the lexer, it is no option for the parser.
One solution may be to use two template methods for the InternalParser and InternalLexer class. Clients may use their own <Language>Parser subtype and overwrite these template methods.
Comment 2 dakshinamurthy.karra CLA 2009-08-24 10:24:27 EDT
(In reply to comment #1)
> Although it may be possible to inject the lexer, it is no option for the
> parser.

I did not understand this part. Since bindLexer() is available in the runtime module, I assumed that we should be using guice to create the lexer everywhere.

I changed the generated MyDslParser.java as follows and it works.

	@Inject
	private Lexer lexer ;

and then in the parse() function:
			lexer.setCharStream(in);

instead of:

		org.xtext.example.parser.antlr.internal.InternalMyDslLexer lexer = new org.xtext.example.parser.antlr.internal.PythonizedMyDslLexer(in);

-- KD
Comment 3 Sebastian Zarnekow CLA 2009-08-24 10:32:26 EDT
That's right. That's why I said:

> Although it may be possible to inject the lexer, it is no option for the
> parser.

It is possible for the lexer but not for the "InternalParser" as it gets some arguments passed into the constructor, that cannot be injected. However, you are right, the template method for the InternalLexer is not necessary.
Comment 4 dakshinamurthy.karra CLA 2009-08-24 10:41:13 EDT
(In reply to comment #3)

I am trying to implement python type indent/dedent as discussed here:

http://www.eclipse.org/newsportal/article.php?id=1959&group=eclipse.modeling.tmf#1959

All in all the hack works. But I spent couple of hours to figure out that a guice is not used to create the lexer in MyDslParser.java.

I am planning to post it sometime - though I think it is not fit for Xtext proper.

It will be nice if you can leave bindLexer() and use guice to create lexer in MyDslParser. I did not post a patch because it is too simple a change.

-- KD
Comment 5 Sebastian Zarnekow CLA 2009-09-01 12:53:12 EDT
Fixed in HEAD
Comment 6 Karsten Thoms CLA 2017-09-19 15:37:54 EDT
Closing bug which were set to RESOLVED before Eclipse Neon.0.