Giter Club home page Giter Club logo

Comments (7)

bkiers avatar bkiers commented on June 24, 2024

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.

jvanzyl avatar jvanzyl commented on June 24, 2024

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.

bkiers avatar bkiers commented on June 24, 2024

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.

bkiers avatar bkiers commented on June 24, 2024

@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:

  1. rewrite the lexer to handle nested Out/Tags
  2. 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.

bkiers avatar bkiers commented on June 24, 2024

See: #76

from liqp.

jvanzyl avatar jvanzyl commented on June 24, 2024

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.

bkiers avatar bkiers commented on June 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.