Rearrange grammer
This commit is contained in:
parent
5eb7acd8b1
commit
4b982a64ef
1 changed files with 23 additions and 24 deletions
47
notcl.js
47
notcl.js
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
var Notcl = (() => {
|
||||
const { AtLeast, Choose, End, Regex, Sequence, Use } = Peg;
|
||||
const { AtLeast, Choose, End, Regex, Sequence, Use, Hint } = Peg;
|
||||
|
||||
const InterCommandWhitespace = Regex(/\s+/y).expects("whitespace");
|
||||
|
||||
|
@ -34,38 +34,37 @@ var Notcl = (() => {
|
|||
),
|
||||
Regex(/\}/y).expects("}")
|
||||
).map(([_left, fragments, _right]) => fragments.join(""));
|
||||
|
||||
const Word = Choose(
|
||||
BasicWord,
|
||||
Brace.map((text) => ({ text }))
|
||||
);
|
||||
|
||||
const CommandTerminator = Choose(
|
||||
/** @type {Peg.Pattern<unknown>} */ (Regex(/[\n;]/y)).expects(
|
||||
"NEWLINE | ;"
|
||||
),
|
||||
End()
|
||||
);
|
||||
const CommandTerminator = Regex(/[\n;]/y).expects("NEWLINE | ;");
|
||||
|
||||
/** @type {Peg.Pattern<Notcl.Command>} */
|
||||
const Command = Choose(
|
||||
CommandTerminator.map(() => []),
|
||||
Sequence(
|
||||
Word,
|
||||
AtLeast(
|
||||
0,
|
||||
Sequence(PreWordWhitespace, Word).map(([_padding, word]) => word)
|
||||
),
|
||||
Choose(
|
||||
Sequence(PreWordWhitespace, Word).expects("whitespace"),
|
||||
Sequence(AtLeast(0, PreWordWhitespace), CommandTerminator).expects(";")
|
||||
)
|
||||
).map(([word, moreWords, _end]) => [word].concat(moreWords))
|
||||
).expects("COMMAND");
|
||||
const Command = Sequence(
|
||||
Word,
|
||||
AtLeast(
|
||||
0,
|
||||
Sequence(PreWordWhitespace, Word).map(([, word]) => word)
|
||||
),
|
||||
AtLeast(0, PreWordWhitespace)
|
||||
).map(([word, moreWords]) => [word].concat(moreWords));
|
||||
|
||||
/** @type {Peg.Pattern<Notcl.Script>} */
|
||||
const Script = Sequence(
|
||||
AtLeast(0, Sequence(PreCommand, Command)),
|
||||
Choose(End(), Sequence(PreCommand, Command))
|
||||
).map(([commands, _eof]) => commands.map(([_padding, command]) => command));
|
||||
PreCommand,
|
||||
AtLeast(0, Command),
|
||||
AtLeast(
|
||||
0,
|
||||
Sequence(CommandTerminator, PreCommand, Command).map(
|
||||
([, , command]) => command
|
||||
)
|
||||
),
|
||||
AtLeast(0, PreCommand),
|
||||
Choose(End(), Hint(Command))
|
||||
).map(([, command, moreCommands]) => command.concat(moreCommands));
|
||||
|
||||
const ERROR_CONTEXT = /(?<=([^\n]{0,50}))([^\n]{0,50})/y;
|
||||
|
||||
|
|
Loading…
Reference in a new issue