Bug 287443 - <Language>Parser.java does not use guice injection to create lexer
Summary: <Language>Parser.java does not use guice injection to create lexer
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: M2   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2009-08-24 10:10 EDT by dakshinamurthy.karra CLA
Modified: 2017-09-19 15:37 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.