What characters can be operators in JavaScript using Esprima?

a 夏天 提交于 2019-12-12 16:16:57

问题


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?

来源:https://stackoverflow.com/questions/21239254/what-characters-can-be-operators-in-javascript-using-esprima

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!