2

In PEG.js I have the following rule

label  = l:[a-zA-Z\$\#\% ]*  { return word(l); } 
block  = "[" l:label "]" { return l; }
option = "\n"* key:block value:label "\n"? {return {key : value}; } 

If it parses [hello] world it results in:

{"key": "world"}.

I would like it to return

{"hello": "world"}.

Is this possible? How can I make sure the object key accepts a dynamic value.

Phrogz
  • 296,393
  • 112
  • 651
  • 745
Tessmore
  • 1,054
  • 1
  • 9
  • 23
  • See also: http://stackoverflow.com/questions/6500573/dynamic-keys-for-object-literals-in-javascript – Phrogz Feb 21 '14 at 16:33

1 Answers1

3

Change

… { return {key : value}; }

to

… { var o={}; o[key]=value; return o; }
Phrogz
  • 296,393
  • 112
  • 651
  • 745