@@ -22,6 +22,11 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
2222 const lamArg = / [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ \- ' ] * | \. /
2323 const numconst = / \d + /
2424
25+ function expectDefOrTerm ( stream , state ) {
26+ return expectDef ( stream , state )
27+ || ( state . debug ? null : expectTerm ( stream , state ) ) ;
28+ }
29+
2530 function expectDef ( stream , state ) {
2631 const name = ( stream . match ( defName ) || [ ] ) [ 0 ] ;
2732 state . f = expectAssign ;
@@ -61,6 +66,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
6166 state . depth . pop ( ) ;
6267 state . bound . pop ( ) ;
6368 }
69+ state . f = expectTerm ;
6470 return BRACKETS ;
6571 }
6672
@@ -75,7 +81,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
7581 if ( ! res ) return null ;
7682 if ( state . bound . some ( v => v . includes ( res ) ) ) return BOUND ;
7783 if ( state . defined . includes ( res ) ) return PREDEF ;
78- return UNDEF ;
84+ return state . debug ? UNDEF : "text" ;
7985 }
8086
8187 function number ( stream , state ) {
@@ -102,16 +108,18 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
102108
103109 return {
104110 startState : function ( ) { return {
105- f : expectDef ,
111+ f : expectDefOrTerm ,
106112 depth : [ ] ,
107113 defined : [ ] ,
108- bound : [ [ ] ]
114+ bound : [ [ ] ] ,
115+ debug : false
109116 } ; } ,
110117 copyState : function ( s ) { return {
111118 f : s . f ,
112119 depth : [ ...s . depth ] ,
113120 defined : [ ...s . defined ] ,
114- bound : s . bound . map ( v => [ ...v ] )
121+ bound : s . bound . map ( v => [ ...v ] ) ,
122+ debug : s . debug
115123 } ; } ,
116124
117125 token : function ( stream , state ) {
@@ -120,12 +128,14 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
120128 return ;
121129 }
122130 if ( stream . peek ( ) === '#' ) {
131+ if ( stream . match ( / ^ # \s * d e b u g \s * $ / ) )
132+ state . debug = ! state . debug ;
123133 stream . skipToEnd ( ) ;
124134 return "comment"
125135 }
126136 if ( stream . sol ( ) && state . depth . length === 0 ) {
127137 state . bound = [ [ ] ] ;
128- state . f = expectDef ;
138+ state . f = expectDefOrTerm ;
129139 }
130140 return state . f ( stream , state ) || onFail ( stream , state ) ;
131141 } ,
0 commit comments