From c42d9ade392bbc6d1bbad25c326ef8de2a43b425 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Tue, 25 Jul 2017 17:46:31 +0200 Subject: [PATCH] Allow whitespace surrounding the root tag, empty arrays and tuples, and literal backslashes in strings --- src/drv.pegjs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/drv.pegjs b/src/drv.pegjs index 6dc18cd..4020db6 100644 --- a/src/drv.pegjs +++ b/src/drv.pegjs @@ -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 = '\\"'