Skip to content

Commit

Permalink
explain parser and add test case for escaped comment delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jan 6, 2020
1 parent dd8fa7f commit e8d6cb7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/moon-browser/dist/moon-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@
parser.sequence([parser.character("/"), parser.many1(parser.or(parser.and(parser.character("\\"), parser.not(["\n"])), parser.not(["/", "\n"]))), parser.character("/")]), grammar.comment, grammar.value, grammar.node, grammar.nodeData, grammar.nodeDataChildren, // Allow failed regular expression or view parses to be interpreted as
// operators.
parser.character("/"), parser.character("<"), // Anything up to a comment, regular expression, string, parenthetical,
// array, object, or view.
// array, object, or view. Only matches to the opening bracket of a view
// because the view parsers do not require an expression to finish
// parsing before consuming the closing bracket. Parentheticals, arrays,
// and objects, however, parse expressions before their closing
// delimiter, depending on the expression parser to stop before it.
parser.many1(parser.not(["/", "#", "\"", "'", "`", "(", ")", "[", "]", "{", "}", "<"]))]))(input, index);
},
main: function main(input, index) {
Expand Down
6 changes: 5 additions & 1 deletion packages/moon-compiler/dist/moon-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@
parser.sequence([parser.character("/"), parser.many1(parser.or(parser.and(parser.character("\\"), parser.not(["\n"])), parser.not(["/", "\n"]))), parser.character("/")]), grammar.comment, grammar.value, grammar.node, grammar.nodeData, grammar.nodeDataChildren, // Allow failed regular expression or view parses to be interpreted as
// operators.
parser.character("/"), parser.character("<"), // Anything up to a comment, regular expression, string, parenthetical,
// array, object, or view.
// array, object, or view. Only matches to the opening bracket of a view
// because the view parsers do not require an expression to finish
// parsing before consuming the closing bracket. Parentheticals, arrays,
// and objects, however, parse expressions before their closing
// delimiter, depending on the expression parser to stop before it.
parser.many1(parser.not(["/", "#", "\"", "'", "`", "(", ")", "[", "]", "{", "}", "<"]))]))(input, index);
},
main: function main(input, index) {
Expand Down
6 changes: 5 additions & 1 deletion packages/moon-compiler/src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ const grammar = {
parser.character("<"),

// Anything up to a comment, regular expression, string, parenthetical,
// array, object, or view.
// array, object, or view. Only matches to the opening bracket of a view
// because the view parsers do not require an expression to finish
// parsing before consuming the closing bracket. Parentheticals, arrays,
// and objects, however, parse expressions before their closing
// delimiter, depending on the expression parser to stop before it.
parser.many1(parser.not(["/", "#", "\"", "'", "`", "(", ")", "[", "]", "{", "}", "<"])),
]))(input, index),
main: (input, index) => parser.and(grammar.expression, parser.EOF)(input, index)
Expand Down
2 changes: 1 addition & 1 deletion packages/moon-compiler/test/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ test("generate with multiline comments", () => {
});

test("generate with moon comments outside of node", () => {
assertGenerate(`console.log(# comment # "hello moon")`, "console.log(/* comment */ \"hello moon\")");
assertGenerate(`console.log(# comment\\# # "hello moon")`, "console.log(/* comment\\# */ \"hello moon\")");
});

test("generate with moon comments inside node", () => {
Expand Down

0 comments on commit e8d6cb7

Please sign in to comment.