What characters can be operators in JavaScript using Esprima?

256 views Asked by At

From the previous question I learned how to extend JavaScript language to support more operators (created by me).

There @Benjamin used Esprima and created # operator. Using Esprima we can do the following:

esprima.parse("10 # 2")

That returns this object:

{
    "type": "Program",
    "body": [
        {
            "type": "ExpressionStatement",
            "expression": {
                "type": "BinaryExpression",
                "operator": "#",
                "left": {
                    "type": "Literal",
                    "value": 10,
                    "raw": "10"
                },
                "right": {
                    "type": "Literal",
                    "value": 2,
                    "raw": "2"
                }
            }
        }
    ]
}

But if I replace # with it throws this error:

Error: Line 1: Unexpected token ILLEGAL

Why is # supported and not? Would it be possible to support unicode characters when parsing a string like "2 ∘ 3"?

Is there any way to force Esprima to accept unicode characters?

0

There are 0 answers