summaryrefslogtreecommitdiffstats
path: root/parser.y
diff options
context:
space:
mode:
authorNicolas Williams <nico@cryptonector.com>2015-05-25 13:16:45 -0500
committerNicolas Williams <nico@cryptonector.com>2015-05-25 13:34:07 -0500
commit11f084f9a71ac5feacb563096aa68deb57a3bc41 (patch)
tree662b96b45a75b9279c49a6c331ef00fe84bd6851 /parser.y
parent454a9dc042969231377e3a5a66a79e8b9d046ae4 (diff)
Keywords should be OK as object keys (fix #794)
With this change it's now OK to use keywords as object keys like so: {if:0}
Diffstat (limited to 'parser.y')
-rw-r--r--parser.y64
1 files changed, 62 insertions, 2 deletions
diff --git a/parser.y b/parser.y
index 00d097c9..029b879d 100644
--- a/parser.y
+++ b/parser.y
@@ -108,6 +108,7 @@ struct lexer_param;
%type <blk> Exp Term MkDict MkDictPair ExpD ElseBody QQString
%type <blk> FuncDef FuncDefs String Import Imports Param Params
%type <blk> Arg Args Module
+%type <literal> Keyword
%{
#include "lexer.h"
struct lexer_param {
@@ -735,6 +736,62 @@ Exp {
$$ = gen_lambda($1);
}
+Keyword:
+"as" {
+ $$ = jv_string("as");
+} |
+"def" {
+ $$ = jv_string("def");
+} |
+"module" {
+ $$ = jv_string("module");
+} |
+"import" {
+ $$ = jv_string("import");
+} |
+"if" {
+ $$ = jv_string("if");
+} |
+"then" {
+ $$ = jv_string("then");
+} |
+"else" {
+ $$ = jv_string("else");
+} |
+"elif" {
+ $$ = jv_string("elif");
+} |
+"reduce" {
+ $$ = jv_string("reduce");
+} |
+"foreach" {
+ $$ = jv_string("foreach");
+} |
+"end" {
+ $$ = jv_string("end");
+} |
+"and" {
+ $$ = jv_string("and");
+} |
+"or" {
+ $$ = jv_string("or");
+} |
+"try" {
+ $$ = jv_string("try");
+} |
+"catch" {
+ $$ = jv_string("catch");
+} |
+"label" {
+ $$ = jv_string("label");
+} |
+"break" {
+ $$ = jv_string("break");
+} |
+"__loc__" {
+ $$ = jv_string("__loc__");
+}
+
MkDict:
%empty {
$$=gen_noop();
@@ -743,10 +800,13 @@ MkDict:
| MkDictPair ',' MkDict { $$=block_join($1, $3); }
| error ',' MkDict { $$ = $3; }
-MkDictPair
-: IDENT ':' ExpD {
+MkDictPair:
+IDENT ':' ExpD {
$$ = gen_dictpair(gen_const($1), $3);
}
+| Keyword ':' ExpD {
+ $$ = gen_dictpair(gen_const($1), $3);
+ }
| String ':' ExpD {
$$ = gen_dictpair($1, $3);
}