diff --git a/notcl.js b/notcl.js index 1642ff1..05478f3 100644 --- a/notcl.js +++ b/notcl.js @@ -6,34 +6,34 @@ */ var Notcl = (() => { - const InterCommandWhitespace = Peg.Regex(/\s+/y); + const { AtLeast, Choose, End, Map, Regex, Sequence } = Peg; - const Comment = Peg.Regex(/#.*\n/y); + const InterCommandWhitespace = Regex(/\s+/y); - const PreCommand = Peg.AtLeast( - 0, - Peg.Choose(InterCommandWhitespace, Comment) - ); + const Comment = Regex(/#.*\n/y); - const PreWordWhitespace = Peg.Regex(/[^\S\n;]*/y); + const PreCommand = AtLeast(0, Choose(InterCommandWhitespace, Comment)); - const BasicWord = Peg.Map(Peg.Regex(/[^\s;]+/y), ([word]) => ({ + const PreWordWhitespace = Regex(/[^\S\n;]*/y); + + const BasicWord = Map(Regex(/[^\s;]+/y), ([word]) => ({ text: word, })); // WIP, need to be able to escape braces correctly // WIP, error if anything after closing brace - const BracePattern = Peg.Map( - Peg.Sequence( - Peg.Regex(/\{/y), - Peg.AtLeast( + + const BracePattern = Map( + Sequence( + Regex(/\{/y), + AtLeast( 0, - Peg.Choose( - Peg.Map(Brace, (text) => `{${text}}`), - Peg.Map(Peg.Regex(/[^{}]+/y), ([text]) => text) + Choose( + Map(Brace, (text) => `{${text}}`), + Map(Regex(/[^{}]+/y), ([text]) => text) ) ), - Peg.Regex(/\}/y) + Regex(/\}/y) ), ([_left, fragments, _right]) => fragments.join("") ); @@ -45,11 +45,11 @@ var Notcl = (() => { return BracePattern(source, index); } - const Word = Peg.Map( - Peg.Sequence( + const Word = Map( + Sequence( PreWordWhitespace, - Peg.Choose( - Peg.Map(BracePattern, (text) => ({ + Choose( + Map(BracePattern, (text) => ({ text, })), BasicWord @@ -58,16 +58,13 @@ var Notcl = (() => { ([_, word]) => word ); - const CommandTerminator = Peg.Sequence( + const CommandTerminator = Sequence( PreWordWhitespace, - Peg.Choose( - /** @type {Peg.Pattern} */ (Peg.Regex(/[\n;]/y)), - Peg.End - ) + Choose(/** @type {Peg.Pattern} */ (Regex(/[\n;]/y)), End) ); - const Command = Peg.Map( - Peg.Sequence(PreCommand, Peg.AtLeast(0, Word), CommandTerminator), + const Command = Map( + Sequence(PreCommand, AtLeast(0, Word), CommandTerminator), ([_padding, words, _end]) => words );