GithubHelp home page GithubHelp logo

Comments (8)

tategakibunko avatar tategakibunko commented on September 9, 2024 1

Ok, we tested default filter only as jg_default.

I've added example/samples/filter_default.{jingoo, expected}.

from jingoo.

sagotch avatar sagotch commented on September 9, 2024 1

Seems a little bit hackish but if it works it is better than without the hack, thanks for taking care of this 👍

But this issue highlight another question:

Should jingoo:

  1. rely on a reserved keywords list
  2. or should we be able to define some macro/functions which use a name wich is a keyword otherwise.

i.e. should this be allowed?

{% function switch (b) %}{{ not b }}{% endfunction %}

{{ switch (true) }}

I think that 2 would be preferable and should be pretty easy to achieve but I did not try to implement it (yet?).

from jingoo.

tategakibunko avatar tategakibunko commented on September 9, 2024

Fortunately, the only difference between default(in switch case statement) and default(as filter) is that only latter is followed by LPAREN.

So I've treated the default filter as special ApplyExpr in jg_parser.mly.

ddb49e4

All test work fine, but if there is something wrong, point it to me.

from jingoo.

tategakibunko avatar tategakibunko commented on September 9, 2024

Hmm, my fix doesn't work in set statement...

{{ set baz = default('baz', null) }}

It causes

Jingoo.Jg_types.SyntaxError("Error line 3, col 6, token set ()")

from jingoo.

tategakibunko avatar tategakibunko commented on September 9, 2024

Sorry, with my quick fix, we'll have to fix everything where ApplyExpr comes up in jg_parlser.mly.

This fix doesn't look good, so I'll revert it.

EDIT:

Oh, my example code was wrong! After fixing, test works fine!

-{{ set baz = default('baz', null) }}{{ baz }}
+{% set baz = default('baz', null) %}{{ baz }}

ba4de0c

from jingoo.

tategakibunko avatar tategakibunko commented on September 9, 2024

Okay, apparently this problem wasn't as easy as I thought it would be.

It would certainly be better to be able to use keywords in functions, macro.

But to use keyword like switch, default in various context, maybe we have to find out whether the token is keyword or identifier in the lexer context after all, but it's too hard task for me.

By the way, the reason I've added this fix in a rough way is that I'm using default filter myself in my web site, haha.

(And maybe many devs are using default filter because it's a useful filter)

from jingoo.

tategakibunko avatar tategakibunko commented on September 9, 2024

I'd like to be able to declare functions that is using keyword in the future, but the default filter seems to have a big impact, so for now, I'm going to release this fix (although which isn't very good).

When you have time, feel free to remove my fix, and implement your own!

from jingoo.

sagotch avatar sagotch commented on September 9, 2024

(And maybe many devs are using default filter because it's a useful filter)

That's how I found the bug :)

I'd like to be able to declare functions that is using keyword in the future, but the default filter seems to have a big impact, so for now, I'm going to release this fix (although which isn't very good).

When you have time, feel free to remove my fix, and implement your own!

I'll try to implement a general fix 👍

from jingoo.

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.