dcollien / expressionparser Goto Github PK
View Code? Open in Web Editor NEWParse simple expressions, in a language of your own description
Parse simple expressions, in a language of your own description
In the Readme.md under the heading Custom Language it's described how to evaluate an expression (with new ExpressionParser(arithmeticLanguage).evaluateExpression(expr)
).
However I can't get this to work. Looking in the code I can't even see any evaluateExpression.
Have I misunderstood something, or is the documentation faulty?
Does this lib use any internal cache in order to boost performance, when asked to evaluate the same expression many times?
Ideally, I would like to have method .compileExpression() which will return function from given string expression argument.
I am using expression-parser in combination with jsonpath-plus library to parse json paths and read the data out of a json object based on the term returned. Here is what my parser code looks like:
export function initialiseParser(workerObject: WokerObjectType): ExpressionParser {
return init(formula, (term: string) => {
if (term === '$NULL') {
return '$NULL';
} else if (term.startsWith('$VALUE:')) {
const [, key] = term.split('$VALUE:');
return getJsonData({ path: key, json: workerObject }) ?? '$NULL';
} else {
return '$NULL';
}
});
}
I am trying to parse the below expression:
$VALUE:Worker_Data.Employment_Data.Worker_Job_Data[?(@.attributes['wd:Primary_Job'] === '1')].Position_Data.Business_Site_Summary_Data.Name
When running this through the parser, I can see the term evaluates to .Position_Data.Business_Site_Summary_Data.Name
. The result I would like to achieve is to get out the full expression: Worker_Data.Employment_Data.Worker_Job_Data[?(@.attributes['wd:Primary_Job'] === '1')].Position_Data.Business_Site_Summary_Data.Name
.
My gut feeling is that the formula language is recognizing the '[]' and parses it at something else but looking through the docs I am unclear as to what.
I wonder is someone could shed some light on this for me? If formula uses []
for something else, how can I escape the character when using it in the expression? Also open to other solutions. Please let me know if more details are required.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.