Comments (7)
What is allowed in a Jekyll {% include ... %}
?
Only simple variable lookup like this:
'{{' id ('.' id)* '}}'
or a full-blown output
like this:
'{{' expr filter* '}}'
from liqp.
Sure, so can we be compatible with Jekyll? Happy to work on it on the weekend, just wanted to get the green light.
from liqp.
Sure, so can we be compatible with Jekyll?
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)?))
...
;
Happy to work on it on the weekend, just wanted to get the green light.
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.
from liqp.
@jvanzyl this is probably trickier than I had thought. The lexer keeps track of a boolean inTag
whenever it sees a {{
or {%
and produces tokens based on that flag.
Since we're now trying to support {{ ... }}
in an include, that means the a flag isn't sufficient anymore (there's a tag in a tag now). Changing the flag into a stack that keeps track level of nesting didn't work: ANTLR3's lexer couldn't handle the lexer rules and their predicates.
There are 2 options:
- rewrite the lexer to handle nested
Out
/Tag
s - replace the ANTLR3 grammar with an ANTLR4 grammar
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).
from liqp.
See: #76
from liqp.
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:
Exception in thread "main" java.lang.RuntimeException: could not parse input: {% include wmt/html-head.html %}
<div class="wrap">
{% include wmt/header.html %}
<div class="margin-bottom-20"></div>
<div class="container">
{{content}}
</div><!-- END container -->
</div><!-- END wrap -->
{% include wmt/footer.html %}
Shall I make a new issue?
from liqp.
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.
from liqp.
Related Issues (20)
- Upgrade ANTLR HOT 11
- Template errors not being stored when using liquid for loops HOT 2
- Support for Liquid's Layouts HOT 3
- Integer and Float Comparisons After Using Times Filter HOT 15
- How to modify default renderer HOT 1
- Shaded jar should exclude non-ANTLR dependencies HOT 2
- Support for `liquid` tag HOT 1
- expression errors ignored in _some_ cases HOT 1
- Template parse is deprecated HOT 3
- Issues with the new release. HOT 2
- != working as == HOT 2
- Is Template (render) thread safe? HOT 2
- when text contains UNICODE characters the parsing fails HOT 1
- Parser error "Invalid Tag: 'liquid'" HOT 2
- Support Instant datetime pattern
- Support for Instant, LocalDateTime date pattern HOT 1
- BlockNode Map render issue: String.valueOf(Map<?,?>) returns '=' instead of ':' as delimiter HOT 12
- Strict typing enforcement cannot be fully disabled HOT 3
- Applying strip_html filter to escaped html will unescape the string HOT 6
- Variable Name with Hyphen Misinterpreted in Conditional Statements HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liqp.