Permalink
Browse files

Implement relaxed reserved word usage.

  • Loading branch information...
1 parent 55a4afc commit a79b6263024ea41df5fecafd90d1ddd8997f38cf @zaach zaach committed Jul 20, 2010
Showing with 1,162 additions and 1,010 deletions.
  1. +42 −9 lib/harmony/grammar.jiy
  2. +331 −331 lib/harmony/parser.js
  3. +42 −9 lib/js/grammar.jiy
  4. +306 −306 lib/js/parser.js
  5. +37 −9 lib/objj/grammar.jiy
  6. +346 −346 lib/objj/parser.js
  7. +33 −0 tests/parser/expressions.js
  8. +25 −0 tests/parser/literals.js
@@ -5,6 +5,39 @@
%%
+IdentifierName
+ : IDENT
+ | NULLTOKEN
+ | TRUETOKEN
+ | FALSETOKEN
+ | BREAK
+ | CASE
+ | CATCH
+ | CONTINUE
+ | DEBUGGER
+ | DEFAULT
+ | DELETETOKEN
+ | DO
+ | ELSE
+ | FINALLY
+ | FOR
+ | FUNCTION
+ | IF
+ | INTOKEN
+ | INSTANCEOF
+ | NEW
+ | RETURN
+ | SWITCH
+ | THIS
+ | THROW
+ | TRY
+ | TYPEOF
+ | VAR
+ | VOIDTOKEN
+ | WHILE
+ | WITH
+ ;
+
Literal
: NULLTOKEN
{{ $$ = yy.Node('LiteralExpr', {type: 'null', value: null}); }}
@@ -33,17 +66,17 @@ RegularExpressionLiteralBegin
;
Property
- : IDENT ':' AssignmentExpr
+ : IdentifierName ':' AssignmentExpr
{{ $$ = yy.Node('DataProp', {name:String($1)}, $3); }}
| STRING ':' AssignmentExpr
{{ $$ = yy.Node('DataProp', {name:String($1)}, $3); }}
| NUMBER ':' AssignmentExpr
{{ $$ = yy.Node('DataProp', {name:Number($1)}, $3); }}
- | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE
- {{ if ($1 !== 'get' && $1 !== 'set') throw 'Parse error, invalid set/get.'; // TODO: use jison ABORT when supported
+ | IDENT IdentifierName '(' ')' OPENBRACE FunctionBody CLOSEBRACE
+ {{ if ($1 !== 'get' && $1 !== 'set') throw new Error('Parse error, invalid set/get.'); // TODO: use jison ABORT when supported
$$ = yy.Node('GetterSetterProp', {name:String($2), op:String($1)}, yy.Node('ParamDecl', {})).appendList($FunctionBody); }}
- | IDENT IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
- {{ if ($1 !== 'get' && $1 !== 'set') throw 'Parse error, invalid set/get.'; // TODO: use jison ABORT when supported
+ | IDENT IdentifierName '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
+ {{ if ($1 !== 'get' && $1 !== 'set') throw new Error('Parse error, invalid set/get.'); // TODO: use jison ABORT when supported
$$ = yy.Node('GetterSetterProp', {name:String($2), op:String($1)}, yy.Node('ParamDecl', {}).appendList($FormalParameterList)).appendList($FunctionBody); }}
;
@@ -113,7 +146,7 @@ MemberExpr
| FunctionExpr
| MemberExpr '[' Expr ']'
{{ $$ = yy.Node('MemberExpr',{brackets:true},$1,$3); }}
- | MemberExpr '.' IDENT
+ | MemberExpr '.' IdentifierName
{{ $$ = yy.Node('MemberExpr',{brackets:false},$1,yy.Node('LiteralExpr', {type: 'string', value: String($3)})); }}
| NEW MemberExpr Arguments
{{ $$ = yy.Node('NewExpr',{},$MemberExpr).appendList($Arguments); }}
@@ -123,7 +156,7 @@ MemberExprNoBF
: PrimaryExprNoBrace
| MemberExprNoBF '[' Expr ']'
{{ $$ = yy.Node('MemberExpr',{brackets:true},$1,$3); }}
- | MemberExprNoBF '.' IDENT
+ | MemberExprNoBF '.' IdentifierName
{{ $$ = yy.Node('MemberExpr',{brackets:false},$1,yy.Node('LiteralExpr', {type: 'string', value: String($3)})); }}
| NEW MemberExpr Arguments
{{ $$ = yy.Node('NewExpr',{},$MemberExpr).appendList($Arguments); }}
@@ -152,7 +185,7 @@ CallExpr
{{ $$ = yy.Node('CallExpr',{},$1).appendList($2); }}
| CallExpr '[' Expr ']'
{{ $$ = yy.Node('MemberExpr',{brackets:true},$1,$3); }}
- | CallExpr '.' IDENT
+ | CallExpr '.' IdentifierName
{{ $$ = yy.Node('MemberExpr',{brackets:false},$1,yy.Node('LiteralExpr', {type: 'string', value: String($3)})); }}
;
@@ -167,7 +200,7 @@ CallExprNoBF
{{ $$ = yy.Node('CallExpr',{},$1).appendList($2); }}
| CallExprNoBF '[' Expr ']'
{{ $$ = yy.Node('MemberExpr',{brackets:true},$1,$3); }}
- | CallExprNoBF '.' IDENT
+ | CallExprNoBF '.' IdentifierName
{{ $$ = yy.Node('MemberExpr',{brackets:false},$1,yy.Node('LiteralExpr', {type: 'string', value: String($3)})); }}
;
Oops, something went wrong. Retry.

0 comments on commit a79b626

Please sign in to comment.