diff --git a/notcl.js b/notcl.js index cc74a75..1642ff1 100644 --- a/notcl.js +++ b/notcl.js @@ -21,8 +21,40 @@ var Notcl = (() => { 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( + 0, + Peg.Choose( + Peg.Map(Brace, (text) => `{${text}}`), + Peg.Map(Peg.Regex(/[^{}]+/y), ([text]) => text) + ) + ), + Peg.Regex(/\}/y) + ), + ([_left, fragments, _right]) => fragments.join("") + ); + /** + * @type {Peg.Pattern} + */ + function Brace(source, index) { + // Thunk to allow Brace to recurse + return BracePattern(source, index); + } + const Word = Peg.Map( - Peg.Sequence(PreWordWhitespace, BasicWord), + Peg.Sequence( + PreWordWhitespace, + Peg.Choose( + Peg.Map(BracePattern, (text) => ({ + text, + })), + BasicWord + ) + ), ([_, word]) => word );