dy / subscript Goto Github PK
View Code? Open in Web Editor NEWFast and tiny expression evaluator with minimal syntax.
License: ISC License
Fast and tiny expression evaluator with minimal syntax.
License: ISC License
I'm trying (desperatly ๐ข) to implement an assignment operator. I'd like to be able to update my context with the result of expressions.
This is what I have:
binary('=', 0);
operator('=', (left: any, right: any) => (ctx: any) => {
// Make sure the left side is a variable reference
if (typeof left !== 'string') {
throw new Error('Left side of assignment must be a variable name');
}
// Evaluate the right side in the context
right = compile(right);
const value = right(ctx);
// Assign the value in the context
ctx[left] = value;
// Return the value
return value;
});
It works for simple expressions like
contextVar = anotherContextVar
But as soon as I use a more complicated expression like
contextVar = anotherContextVar + 2
it fails since my right varible will get an array of values ๐คทโโ๏ธ. I feel I'm making a simple mistake here, but I can't seem to figure it out.
Any suggestions?
I have a Nx repository.
The import in TypeScript/Node code works, but the build is broken.
The import in Jest Scripts didn't work at all, no matter what I tried:
/var/www/example/node_modules/subscript/justin.js:2
import { skip, cur, idx, err, expr } from './parse.js'
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import jstin from 'subscript/justin.js';
It will be great if this library supports typescript by exposing typescript typings.
Would be nice to have the typical Math functions available, or is this out of scope of this project?
nice work!
I was wondering if there is an approach that would handle async?
let fn = createFn('a + b(3)')
fn({ a: 2,b:x=>Promise.resolve(x)}) // 5
also, it isn't clear why github repo uses createFn
and npm uses script
in the first example
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.