@@ -14,6 +14,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
14
14
const EMPTY = "text" ;
15
15
const UNDEF = "error" ;
16
16
const REDEF = "variable-3" ;
17
+ const SUPPRESS = "text" ;
17
18
const FAIL = "error" ;
18
19
19
20
const defName = / [ a - z A - Z ] [ a - z A - Z 0 - 9 _ \- ' ] * /
@@ -23,14 +24,14 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
23
24
const numconst = / \d + /
24
25
25
26
function expectDefOrTerm ( stream , state ) {
26
- return expectDef ( stream , state )
27
- || ( state . debug ? null : expectTerm ( stream , state ) ) ;
27
+ if ( stream . match ( / . * = / , false ) ) return expectDef ( stream , state ) ;
28
+ else return expectTerm ( stream , state ) ;
28
29
}
29
30
30
31
function expectDef ( stream , state ) {
31
32
const name = ( stream . match ( defName ) || [ ] ) [ 0 ] ;
32
33
state . f = expectAssign ;
33
- if ( ! name || ! ( / [ = \s ] / . test ( stream . peek ( ) ) || stream . eol ( ) ) ) return null ;
34
+ if ( ! name || ! ( stream . match ( / \s * = / , false ) ) ) return null ;
34
35
const res = [ ] ;
35
36
if ( state . defined . includes ( name ) ) res . push ( REDEF ) ;
36
37
state . defined . push ( name ) ;
@@ -81,7 +82,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
81
82
if ( ! res ) return null ;
82
83
if ( state . bound . some ( v => v . includes ( res ) ) ) return BOUND ;
83
84
if ( state . defined . includes ( res ) ) return PREDEF ;
84
- return state . debug ? UNDEF : "text" ;
85
+ return UNDEF ;
85
86
}
86
87
87
88
function number ( stream , state ) {
@@ -103,12 +104,12 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
103
104
104
105
function onFail ( stream , state ) {
105
106
stream . match ( / [ ^ \s ] * / ) ;
106
- return FAIL
107
+ return FAIL ;
107
108
}
108
109
109
110
return {
110
111
startState : function ( ) { return {
111
- f : expectDefOrTerm ,
112
+ f : expectDef ,
112
113
depth : [ ] ,
113
114
defined : [ ] ,
114
115
bound : [ [ ] ] ,
@@ -136,13 +137,15 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
136
137
}
137
138
if ( stream . sol ( ) && state . depth . length === 0 ) {
138
139
state . bound = [ [ ] ] ;
139
- state . f = expectDefOrTerm ;
140
+ state . f = expectDef ;
140
141
}
141
- return state . f ( stream , state ) || onFail ( stream , state ) ;
142
+ const res = state . f ( stream , state )
143
+ || ( state . debug ? null : expectDefOrTerm ( stream , state ) )
144
+ || onFail ( stream , state ) ;
145
+ return ! state . debug && res == FAIL ? SUPPRESS : res ;
142
146
} ,
143
147
144
148
indent : function ( state , textAfter ) {
145
- console . log ( state . depth ) ;
146
149
if ( ! state . depth . length ) return 0 ;
147
150
return state . depth [ state . depth . length - 1 ] + 2 ;
148
151
} ,
0 commit comments