filtrex | A simple , safe , JavaScript Filter Expression compiler | Runtime Evironment library
kandi X-RAY | filtrex Summary
kandi X-RAY | filtrex Summary
A simple, safe, JavaScript expression engine, allowing end-users to enter arbitrary expressions without p0wning you.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Creates a new filter parser .
- Prepare rules to be applied to tokens .
- Compiles an expression to a node .
- Resolve conflict operation between two op statements
- Highlights an expression .
- layer method implementation
- Mix all types into the prototype
- Apply each row to the result set .
- Build table of items .
- creates random data
filtrex Key Features
filtrex Examples and Code Snippets
Community Discussions
Trending Discussions on filtrex
QUESTION
I'm working on a expression parser made in Jison, which supports basic things like arithmetics, comparisons etc. I want to allow chained comparisons like 1 < a < 10
and x == y != z
. I've already implemented the logic needed to compare multiple values, but I'm strugling with the grammar – Jison keeps grouping the comparisons like (1 < a) < 10
or x == (y != z)
and I can't make it recognize the whole thing as one relation.
This is roughly the grammar I have:
...ANSWER
Answered 2021-Jun-23 at 02:10There are basically two relatively easy solutions to this problem:
Use a cascading grammar instead of precedence declarations.
This makes it relatively easy to write a grammar for chained comparison, and does not really complicate the grammar for binary operators nor for tight-binding unary operators.
You'll find examples of cascading grammars all over the place, including most programming languages. A reasonably complete example is seen in this grammar for C expressions (just look at the grammar up to
constant_expression:
).One of the advantages of cascading grammars is that they let you group operators at the same precedence level into a single non-terminal, as you try to do with comparison operators and as the linked C grammar does with assignment operators. That doesn't work with precedence declarations because precedence can't "see through" a unit production; the actual token has to be visibly part of the rule with declared precedence.
Another advantage is that if you have specific parsing needs for chained operators, you can just write the rule for the chained operators accordingly; you don't have to worry about it interfering with the rest of the grammar.
However, cascading grammars don't really get unary operators right, unless the unary operators are all at the top of the precedence hierarchy. This can be seen in Python, which uses a cascading grammar and has several unary operators low in the precedence hierarchy, such as the
not
operator, leading to the following oddity:
QUESTION
I'm trying to match this syntax:
...ANSWER
Answered 2021-Mar-23 at 10:08That is because the input credit
is not being matched by your CREDIT
rule, but by the ID
rule. The lexer always tries to match as many characters as possible. So, the input credit
can be matched by: ID
, JOURNAL
, EXTID
and CREDIT
. Whenever it happens that multiple rules can match the same characters, the one defined first "wins" (ID
in this case). The lexer does not "listen" to what the parser is trying to match, it operates independently from the parser.
Note that the EXTID
also causes the input -
to be matched by it, causing the MINUS
rule to never be matched.
The solution: place your keywords before the ID
rule inside the grammar:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install filtrex
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page