@@ -6,7 +6,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
6
6
const BRACKETS = "bracket" ;
7
7
const LAMBDA = "keyword" ;
8
8
const DOT = LAMBDA ;
9
- const PREDEF = "variable " ;
9
+ const PREDEF = "text " ;
10
10
const BOUND = "text" ;
11
11
const ARGS = "def" ;
12
12
const HOLE = "atom" ;
@@ -22,6 +22,11 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
22
22
const lamArg = / [ a - z A - Z _ ] [ a - z A - Z 0 - 9 _ \- ' ] * | \. /
23
23
const numconst = / \d + /
24
24
25
+ function expectDefOrTerm ( stream , state ) {
26
+ return expectDef ( stream , state )
27
+ || ( state . debug ? null : expectTerm ( stream , state ) ) ;
28
+ }
29
+
25
30
function expectDef ( stream , state ) {
26
31
const name = ( stream . match ( defName ) || [ ] ) [ 0 ] ;
27
32
state . f = expectAssign ;
@@ -61,6 +66,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
61
66
state . depth . pop ( ) ;
62
67
state . bound . pop ( ) ;
63
68
}
69
+ state . f = expectTerm ;
64
70
return BRACKETS ;
65
71
}
66
72
@@ -75,7 +81,7 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
75
81
if ( ! res ) return null ;
76
82
if ( state . bound . some ( v => v . includes ( res ) ) ) return BOUND ;
77
83
if ( state . defined . includes ( res ) ) return PREDEF ;
78
- return UNDEF ;
84
+ return state . debug ? UNDEF : "text" ;
79
85
}
80
86
81
87
function number ( stream , state ) {
@@ -102,30 +108,35 @@ CodeMirror.defineMode("lambdacalc", function(_config, modeConfig) {
102
108
103
109
return {
104
110
startState : function ( ) { return {
105
- f : expectDef ,
111
+ f : expectDefOrTerm ,
106
112
depth : [ ] ,
107
113
defined : [ ] ,
108
- bound : [ [ ] ]
114
+ bound : [ [ ] ] ,
115
+ debug : false
109
116
} ; } ,
110
117
copyState : function ( s ) { return {
111
118
f : s . f ,
112
119
depth : [ ...s . depth ] ,
113
120
defined : [ ...s . defined ] ,
114
- bound : s . bound . map ( v => [ ...v ] )
121
+ bound : s . bound . map ( v => [ ...v ] ) ,
122
+ debug : s . debug
115
123
} ; } ,
116
124
117
125
token : function ( stream , state ) {
118
- if ( / \s / . test ( stream . peek ( ) ) ) {
119
- stream . eatSpace ( ) ;
126
+ if ( stream . eat ( / \t / ) ) return FAIL ;
127
+ if ( / [ \n ] / . test ( stream . peek ( ) ) ) {
128
+ stream . eatWhile ( / [ \n ] / ) ;
120
129
return ;
121
130
}
122
131
if ( stream . peek ( ) === '#' ) {
132
+ if ( stream . match ( / ^ # d e b u g / ) )
133
+ state . debug = ! state . debug ;
123
134
stream . skipToEnd ( ) ;
124
135
return "comment"
125
136
}
126
137
if ( stream . sol ( ) && state . depth . length === 0 ) {
127
138
state . bound = [ [ ] ] ;
128
- state . f = expectDef ;
139
+ state . f = expectDefOrTerm ;
129
140
}
130
141
return state . f ( stream , state ) || onFail ( stream , state ) ;
131
142
} ,
0 commit comments