From f3a4eb7554105e1a5ce95aff9405b540baee6cb0 Mon Sep 17 00:00:00 2001 From: Kacarott Date: Sat, 19 Feb 2022 12:47:55 +0100 Subject: [PATCH 1/8] Make colouring consistent --- lambdacalc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambdacalc.js b/lambdacalc.js index 6a349e3..196c58a 100644 --- a/lambdacalc.js +++ b/lambdacalc.js @@ -6,7 +6,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { const BRACKETS = "bracket"; const LAMBDA = "keyword"; const DOT = LAMBDA; - const PREDEF = "variable"; + const PREDEF = "text"; const BOUND = "text"; const ARGS = "def"; const HOLE = "atom"; From 604cf3eeb58f604667e35857c6d6f2780fd19c57 Mon Sep 17 00:00:00 2001 From: Kacarott Date: Sat, 19 Feb 2022 12:48:01 +0100 Subject: [PATCH 2/8] Add debug mode --- lambdacalc.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lambdacalc.js b/lambdacalc.js index 196c58a..d9ceda4 100644 --- a/lambdacalc.js +++ b/lambdacalc.js @@ -22,6 +22,11 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { const lamArg = /[a-zA-Z_][a-zA-Z0-9_\-']*|\./ const numconst = /\d+/ + function expectDefOrTerm(stream, state) { + return expectDef(stream, state) + || (state.debug ? null : expectTerm(stream, state)); + } + function expectDef(stream, state) { const name = (stream.match(defName)||[])[0]; state.f = expectAssign; @@ -61,6 +66,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { state.depth.pop(); state.bound.pop(); } + state.f = expectTerm; return BRACKETS; } @@ -75,7 +81,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { if (!res) return null; if (state.bound.some(v=>v.includes(res))) return BOUND; if (state.defined.includes(res)) return PREDEF; - return UNDEF; + return state.debug ? UNDEF : "text"; } function number(stream, state) { @@ -102,16 +108,18 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { return { startState: function () { return { - f: expectDef, + f: expectDefOrTerm, depth: [], defined: [], - bound: [[]] + bound: [[]], + debug: false }; }, copyState: function (s) { return { f: s.f, depth: [...s.depth], defined: [...s.defined], - bound: s.bound.map(v=>[...v]) + bound: s.bound.map(v=>[...v]), + debug: s.debug }; }, token: function(stream, state) { @@ -120,12 +128,14 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { return; } if (stream.peek() === '#') { + if (stream.match(/^#\s*debug\s*$/)) + state.debug = !state.debug; stream.skipToEnd(); return "comment" } if (stream.sol() && state.depth.length === 0) { state.bound = [[]]; - state.f = expectDef; + state.f = expectDefOrTerm; } return state.f(stream, state) || onFail(stream, state); }, From 9dec81aaf786a0df3905a2661d0a73a3933da932 Mon Sep 17 00:00:00 2001 From: Kacarott Date: Sat, 19 Feb 2022 14:16:36 +0100 Subject: [PATCH 3/8] Make debug pragma stricter --- lambdacalc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambdacalc.js b/lambdacalc.js index d9ceda4..5bcbaf6 100644 --- a/lambdacalc.js +++ b/lambdacalc.js @@ -128,7 +128,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { return; } if (stream.peek() === '#') { - if (stream.match(/^#\s*debug\s*$/)) + if (stream.match(/^#debug\s*$/)) state.debug = !state.debug; stream.skipToEnd(); return "comment" From 21624f2a48e4ec0372ae839609de6f9d4512a3ca Mon Sep 17 00:00:00 2001 From: Kacarott Date: Sat, 19 Feb 2022 14:24:37 +0100 Subject: [PATCH 4/8] Stricter whitespace --- lambdacalc.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lambdacalc.js b/lambdacalc.js index 5bcbaf6..4cfeba3 100644 --- a/lambdacalc.js +++ b/lambdacalc.js @@ -123,8 +123,9 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) { }; }, token: function(stream, state) { - if (/\s/.test(stream.peek())) { - stream.eatSpace(); + if (stream.eat(/\t/)) return FAIL; + if (/[ \n]/.test(stream.peek())) { + stream.eatWhile(/[ \n]/); return; } if (stream.peek() === '#') { From ebcbc2d1c3e28a1fc3b707813e0e1b45a9ad2955 Mon Sep 17 00:00:00 2001 From: Kacarott Date: Sat, 19 Feb 2022 14:36:47 +0100 Subject: [PATCH 5/8] Update example --- index.html | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 9fed43d..a4e1079 100644 --- a/index.html +++ b/index.html @@ -31,7 +31,7 @@

From b89d14fc5a03b9b76aa5bee4f5150ff5abc32501 Mon Sep 17 00:00:00 2001 From: Kacarott Date: Sat, 19 Feb 2022 16:55:16 +0100 Subject: [PATCH 8/8] Fix typo --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 18d26c1..c54128c 100644 --- a/index.html +++ b/index.html @@ -50,7 +50,7 @@

(\ f x . f (x x)) # Unbound -some-func = \ local . true non-existant local +some-func = \ local . true non-existent local # Out of scope args other-func = \ x . const (\ scoped-arg . x ()) scoped-arg x @@ -62,7 +62,7 @@

(\ f x . f (x x)) # Unbound - Debug -some-func = \ local . true non-existant local +some-func = \ local . true non-existent local # Out of scope args - Debug other-func = \ x . const (\ scoped-arg . x ()) scoped-arg x