diff --git a/src/notcl.test.ts b/src/notcl.test.ts index f8cc471..b39cbfa 100644 --- a/src/notcl.test.ts +++ b/src/notcl.test.ts @@ -24,12 +24,16 @@ describe("Parsing Notcl", () => { parse(String.raw`a\ b`) ).toEqual([true, [[{ text: "a" }, { text: "b" }]]])); - it.failing("does split commands on newlines with escaped backslashes", () => + it("does split words on folded newlines", () => + expect( + parse(String.raw`a\ +b`) + ).toEqual([true, [[{ text: "a" }, { text: "b" }]]])); + it("does split commands on newlines with escaped backslashes", () => expect( parse(String.raw`a\\ b`) - ).toEqual([true, [[{ text: "a" }], [{ text: "b" }]]]) - ); + ).toEqual([true, [[{ text: "a\\\\" }], [{ text: "b" }]]])); it("does not split commands on folded newlines with escaped backslashes", () => expect( parse(String.raw`a\\\ diff --git a/src/notcl.ts b/src/notcl.ts index 51fc2ca..dae9522 100644 --- a/src/notcl.ts +++ b/src/notcl.ts @@ -7,22 +7,16 @@ export type Word = { export type Command = Word[]; export type Script = Command[]; -const InterCommandWhitespace = Regex(/\s+/y).expects("whitespace"); - const Comment = Regex(/#[^\n]*/y) .expects("#") .map(() => []); -const PreCommand = AtLeast(0, InterCommandWhitespace); - const PreWordWhitespace = Regex(/[^\S\n;]+/y).expects("whitespace"); const BasicWord = Regex(/(?!\{)[^\s;]+/y) .map(([word]) => ({ text: word })) .expects("BASIC_WORD"); -// WIP, need to be able to escape braces correctly - const Brace: Pattern = Sequence( Regex(/\{/y).expects("{"), AtLeast( @@ -84,7 +78,7 @@ const ERROR_CONTEXT = /(?<=([^\n]{0,50}))([^\n]{0,50})/y; export function parse(code: string): [true, Script] | [false, string] { /* Preprocess */ // fold line endings - code = code.replace(/(?