diff --git a/src/ast.js b/src/ast.js index 11c52a1..1264103 100644 --- a/src/ast.js +++ b/src/ast.js @@ -43,6 +43,7 @@ exports.BooleanLiteral = makeNodeConstructor("booleanLiteral", ["value"]); exports.ObjectLiteral = makeNodeConstructor("objectLiteral", ["pairs"]); exports.ArrayLiteral = makeNodeConstructor("arrayLiteral", ["items"]); exports.FunctionLiteral = makeNodeConstructor("functionLiteral", ["args", "statements"]); +exports.ThisVariable = makeNodeConstructor("thisVariable", ["keyword"]); exports.Variable = makeNodeConstructor("variable", ["identifier"]); exports.Invocation = makeNodeConstructor("invocation", ["expression", "args"]); exports.Refinement = makeNodeConstructor("refinement", ["expression", "key"]); diff --git a/src/parser.js b/src/parser.js index 66364ac..91b9698 100644 --- a/src/parser.js +++ b/src/parser.js @@ -443,9 +443,9 @@ var arrayLiteral = function (input) { return p(input); }; -var variable = decorate(identifier, function (i) { - return AST.Variable(i); -}); +var thisVariable = decorate(keyword("this"), AST.ThisVariable); + +var variable = decorate(identifier, AST.Variable); var functionLiteral = function (input) { var args = parens(sepBy(symbol(","), identifier)); @@ -506,6 +506,7 @@ var expr = function (input) { objectLiteral, arrayLiteral, functionLiteral, + thisVariable, variable, parens(expr) ]); diff --git a/test/parser_test.js b/test/parser_test.js index d58f9cc..6018327 100644 --- a/test/parser_test.js +++ b/test/parser_test.js @@ -143,6 +143,7 @@ testParser("'abc'", { stringLiteral: "abc" }, parser.expr); testParser('"abc"', { stringLiteral: "abc" }, parser.expr); testParser("true", { booleanLiteral: true }, parser.expr); testParser("false", { booleanLiteral: false }, parser.expr); +testParser("this", { thisVariable: "this" }, parser.expr); testParser("{}", { objectLiteral: [] }, parser.expr); testParser("{x: 2}", { objectLiteral: [["x", { numberLiteral: 2 }]] }, parser.expr); testParser('{"x": 2}', { objectLiteral: [["x", { numberLiteral: 2 }]] }, parser.expr);