Start matching {braces} and nested braces
This commit is contained in:
parent
88497965b3
commit
9333357e44
1 changed files with 33 additions and 1 deletions
34
notcl.js
34
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<string>}
|
||||
*/
|
||||
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
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue