Code Monkey home page Code Monkey logo

subscript's Issues

How to implement assignment operator (=)?

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?

Import doesn't work (node, jest)

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';

Typescript support?

It will be great if this library supports typescript by exposing typescript typings.

Math.* support?

Would be nice to have the typical Math functions available, or is this out of scope of this project?

is async supported?

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

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.