Allow whitespace surrounding the root tag, empty arrays and tuples, and literal backslashes in strings

master
Sven Slootweg 7 years ago
parent 23e8ae960a
commit c42d9ade39

@ -1,5 +1,8 @@
start
= deriveTag
= _ root:deriveTag _ { return root; }
_
= [ \n\r\t]*
value
= deriveTag
@ -8,7 +11,7 @@ value
/ string
multipleItems
= item:value subsequentItems:("," value)* { return [item].concat(subsequentItems.map(subsequentItem => subsequentItem[1])); }
= item:value? subsequentItems:("," value)* { return (item != null) ? [item].concat(subsequentItems.map(subsequentItem => subsequentItem[1])) : []; }
deriveTag
= "Derive(" items:multipleItems ")" { return {type: "deriveTag", items: items}; }
@ -23,8 +26,9 @@ string
= '"' chars:stringCharacter* '"' { return chars.join(""); }
stringCharacter
= !('"' / "\\") char:. { return char; }
/ stringEscapedQuote { return '"'; }
= !('"' / "\\") char:. { return char; } // Prefer a non-backslash character...
/ stringEscapedQuote { return '"'; } // ... then an escaped quotation mark...
/ !('"') char:. { return char; } // ... and finally any other character that doesn't terminate the string.
stringEscapedQuote
= '\\"'

Loading…
Cancel
Save