From 88497965b3217634336e503067168e97401118a0 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Sat, 29 Jul 2023 01:45:55 -0400 Subject: [PATCH] Parse Commands with Peg --- notcl.js | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/notcl.js b/notcl.js index 95facf5..cc74a75 100644 --- a/notcl.js +++ b/notcl.js @@ -26,6 +26,19 @@ var Notcl = (() => { ([_, word]) => word ); + const CommandTerminator = Peg.Sequence( + PreWordWhitespace, + Peg.Choose( + /** @type {Peg.Pattern} */ (Peg.Regex(/[\n;]/y)), + Peg.End + ) + ); + + const Command = Peg.Map( + Peg.Sequence(PreCommand, Peg.AtLeast(0, Word), CommandTerminator), + ([_padding, words, _end]) => words + ); + return { /** * Parse out a Notcl script into an easier-to-interpret representation. @@ -39,42 +52,10 @@ var Notcl = (() => { // fold line endings code = code.replace(/(?