Two-layered lexer for templating language


are there existing classes which would help me to create lexer in two phases:
1/ top lexer to locate my language within the outer one
2/ my lang lexer to parse the parts of my language

I'm trying to write support for Latte templating language (part of Nette framework in PHP), which supports injecting the language into several parts of HTML code, for example:
- into curly brackets, e.g. {if $something}
- into html attributes
   - with quotes, e.g. <a n:if="$something">
   - with apostrophes, e.g. <a n:if='$something'>

I thought about writing a LatteTopLexer, which would lex out the whole macros out of HTML, and then LatteLexer to lex just contents of the macros from top lexer. How would this be possible?


评论操作 固定链接

We have a framework for this in IntelliJ IDEA, but unfortunately we don't have an open-source example for its usage. See the following post for some information:

评论操作 固定链接

What a pitty. There is lack of good examples.

I created a LookAhedLexer with this sub-lexer capability:, it may be useful to someone else in the future.