枕を欹てて聴く

香炉峰の雪は簾を撥げて看る

iv / js ES.next, update for February 27, 2012 Draft

iv / js ES.next parser (my original ES.next parser, see this entry) is updated to follow February 27, 2012 Draft

ArrayComprehension

ArrayComprehension is supported.

[ v * v for (v of [1, 2, 3])];

to

[
  {
    "type": "ExpressionStatement",
    "expr": {
      "type": "ArrayComprehension",
      "expression": {
        "type": "BinaryExpression",
        "op": "*",
        "left": {
          "type": "Identifier",
          "value": "v"
        },
        "right": {
          "type": "Identifier",
          "value": "v"
        }
      },
      "comprehensions": [
        {
          "type": "ComprehensionBlock",
          "left": {
            "type": "ExpressionStatement",
            "expr": {
              "type": "Identifier",
              "value": "v"
            }
          },
          "right": {
            "type": "Array",
            "sealed": false,
            "items": [
              {
                "type": "Number",
                "value": "1"
              },
              {
                "type": "Number",
                "value": "2"
              },
              {
                "type": "Number",
                "value": "3"
              }
            ]
          }
        }
      ],
      "filter": null
    }
  }
]

and

[ v * v for (v of []) if (true)];

to

[
  {
    "type": "ExpressionStatement",
    "expr": {
      "type": "ArrayComprehension",
      "expression": {
        "type": "BinaryExpression",
        "op": "*",
        "left": {
          "type": "Identifier",
          "value": "v"
        },
        "right": {
          "type": "Identifier",
          "value": "v"
        }
      },
      "comprehensions": [
        {
          "type": "ComprehensionBlock",
          "left": {
            "type": "ExpressionStatement",
            "expr": {
              "type": "Identifier",
              "value": "v"
            }
          },
          "right": {
            "type": "Array",
            "sealed": false,
            "items": []
          }
        }
      ],
      "filter": {
        "type": "True"
      }
    }
  }
]

for-of Statement

for-of Statement is supported.

for (var i of []) print(i);

to

[
  {
    "type": "ForOfStatement",
    "init": {
      "type": "VariableStatement",
      "body": [
        {
          "type": "Declaration",
          "key": {
            "type": "Identifier",
            "value": "i"
          }
        }
      ]
    },
    "enumerable": {
      "type": "Array",
      "sealed": false,
      "items": []
    },
    "body": {
      "type": "ExpressionStatement",
      "expr": {
        "type": "FuncCall",
        "target": {
          "type": "Identifier",
          "value": "print"
        },
        "args": [
          {
            "type": "Identifier",
            "value": "i"
          }
        ]
      }
    }
  }
]

GeneratorComprehension

GeneratorComprehension is supported

(print(v) for (v of [1, 2, 3]));

to

[
  {
    "type": "ExpressionStatement",
    "expr": {
      "type": "GeneratorComprehension",
      "expression": {
        "type": "FuncCall",
        "target": {
          "type": "Identifier",
          "value": "print"
        },
        "args": [
          {
            "type": "Identifier",
            "value": "v"
          }
        ]
      },
      "comprehensions": [
        {
          "type": "ComprehensionBlock",
          "left": {
            "type": "ExpressionStatement",
            "expr": {
              "type": "Identifier",
              "value": "v"
            }
          },
          "right": {
            "type": "Array",
            "sealed": false,
            "items": [
              {
                "type": "Number",
                "value": "1"
              },
              {
                "type": "Number",
                "value": "2"
              },
              {
                "type": "Number",
                "value": "3"
              }
            ]
          }
        }
      ],
      "filter": null
    }
  }
]

let or const declaration in for statement

let or const declaration in for statement is supported.

for (let i of [1, 2, 3]);

to

[
  {
    "type": "ForOfStatement",
    "init": {
      "type": "LetDeclaration",
      "body": [
        {
          "type": "Declaration",
          "key": {
            "type": "Identifier",
            "value": "i"
          }
        }
      ]
    },
    "enumerable": {
      "type": "Array",
      "sealed": false,
      "items": [
        {
          "type": "Number",
          "value": "1"
        },
        {
          "type": "Number",
          "value": "2"
        },
        {
          "type": "Number",
          "value": "3"
        }
      ]
    },
    "body": {
      "type": "EmptyStatement"
    }
  }
]

GeneratorExpression

GeneratorExpression is supported.

(function* generator() { });

to

[
  {
    "type": "ExpressionStatement",
    "expr": {
      "type": "GeneratorExpression",
      "kind": "EXP",
      "params": [],
      "body": [],
      "name": "generator"
    }
  }
]

GeneratorExpression direct property

GeneratorExpression direct property is supported.

({
  *generator() { }
});

to

[
  {
    "type": "ExpressionStatement",
    "expr": {
      "type": "Object",
      "sealed": false,
      "values": [
        {
          "key": "generator",
          "val": {
            "type": "GeneratorExpression",
            "kind": "EXP",
            "params": [],
            "body": []
          }
        }
      ],
      "accessors": []
    }
  }
]

NOTE

  • GeneratorDeclaration is not supported because of no BNF entry
  • YieldDeclaration is not supported because of no BNF entry
  • Only for-of style ComprehensionFor is allowed (reject for-in style) because of BNF

というわけで

どうでしょう, ES.next engine書いてもいいんですよ, id:teramako さん!!