0

let's say we have this in cofeescript

obj = 
 one:
  one: 11
  two: 12
 two: 2
 three:
  four: 34

and that compiles to

var obj = {
   one: { one: 11, two: 12 },
   two: 2,
   three: { four: 34 }
}

so let's say I have this PEG.js grammar

start = expr

vvn = f:[a-z]+
        { return f.join(""); }

spc = [' ''\t''\n']*

number =
    f:([1-9][0-9]*) { return f.join(""); }

string =
    f:[a-z]+ { return f.join(""); }


value =
    spc f:vvn spc ':' spc s:value spc
        { return { var : f, value : s }; }
    / number / string


expr = 
    spc f:vvn spc '=' s:value+
        { return { var: f, value: s} }

that grammar does the half thing, if you want test it on online PEG parser and the two variable is defined 2 times in the same scope instead of going under the first one variable. How can i check if 2 lines have the same space left side so I add them on same scope?

Theofilos Mouratidis
  • 1,146
  • 12
  • 32
  • we don't have these in our grammar. We rewrite our implicit objects (and calls) to have them js-like. – Ven Jul 07 '13 at 17:32
  • that's a grammar made now to somehow get an actual object written in coffeescript to turn it into javascript with a function I will make after, I just can't figure out how the left space difference works in parsing...EDIT: oh thanks – Theofilos Mouratidis Jul 07 '13 at 21:50
  • 1
    Implicit calls/objects are dealt with [here](https://github.com/jashkenas/coffee-script/blob/master/src/rewriter.coffee#L137). – Ven Jul 07 '13 at 22:13
  • possible duplicate of [Return key, value object with dynamic key name](http://stackoverflow.com/questions/21583283/return-key-value-object-with-dynamic-key-name) – Paul Sweatte Oct 13 '14 at 22:22
  • @PaulSweatte not at all, figured out that grammars' expression power can't describe indents with different scopes – Theofilos Mouratidis Oct 16 '14 at 19:38

0 Answers0