-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow variables with the include tag #75
Comments
What is allowed in a Jekyll Only simple variable lookup like this:
or a full-blown
|
Sure, so can we be compatible with Jekyll? Happy to work on it on the weekend, just wanted to get the green light. |
Yeah, in that case the tree rewriting needs to be modified from: // parser grammar
include_tag
: TagStart Include ( {this.flavor == Flavor.JEKYLL}?=>
file_name_as_str TagEnd -> ^(INCLUDE file_name_as_str ^(WITH ))
| a=Str (With b=Str)? TagEnd -> ^(INCLUDE $a ^(WITH $b?))
)
; to something like this: // parser grammar
include_tag
: TagStart Include ( {this.flavor == Flavor.JEKYLL}?=>
file_name_or_output TagEnd -> ^(INCLUDE file_name_or_output ^(WITH ))
| a=Str (With b=Str)? TagEnd -> ^(INCLUDE ^(FILE_NAME_OR_OUTPUT ... ) ^(WITH $b?))
)
;
file_name_or_output
: ... -> ^(FILE_NAME_OR_OUTPUT ... )
; And the tree walker grammar will then alse need to be modified into something like this: // tree walker grammar
include_tag returns [LNode node]
: ^(INCLUDE ^(FILE_NAME_OR_OUTPUT ... ) ^(WITH (with=Str)?))
...
;
Of course, a PR is more than welcome! The tree-walking and -rewriting can be a bit confusing in ANTLR v3. Not surprising Terence dropped it in ANTLR v4. Let me know if I can be of assistance. |
@jvanzyl this is probably trickier than I had thought. The lexer keeps track of a boolean Since we're now trying to support There are 2 options:
Number 2 is not much more work than number 1 (the current Nodes can be re-used, I only need to write a new Walker/Visitor). And it's not at all sure that I can get ANTLR3's lexer to cooperate without some nasty hacks (and probably taking a noticeable performance hit for larger scripts). ANTLR4's parser and (most noticeable) its lexer are quite a bit more powerful compared to the v3 version. So, I'll go and create a v4 grammar and visitor to replace the old v3 stuff (and being backwards compatible, of course!). But it won't be ready in a couple of days (I have little dev-time at the moment). |
See: #76 |
I just got around to trying this (sorry it's so late), and this appears to be allowed in Jekyll but will not parse with Liqp:
Shall I make a new issue? |
I've just got back from 2 weeks Scotland, hence the delayed response. No problemo @jvanzyl, and yes, please create a new issue for this. |
We have a layout that works in Jekyll where there is an include that uses a variable defined in the front-matter to select which navigation to include. Here's an example:
Seems like the ANTRL grammar needs to be altered to allow
{{XXX}}
, and do a variable lookup in the include tag.The text was updated successfully, but these errors were encountered: