@@ -31,19 +31,37 @@ CodeMirror.defineMode("sieve", function(config) {
3131 state . tokenize = tokenString ( ch ) ;
3232 return state . tokenize ( stream , state ) ;
3333 }
34-
35- if ( ch === "{" )
36- {
37- state . _indent ++ ;
34+
35+ if ( ch == "(" ) {
36+ state . _indent . push ( "(" ) ;
37+ // add virtual angel wings so that editor behaves...
38+ // ...more sane incase of broken brackets
39+ state . _indent . push ( "{" ) ;
3840 return null ;
3941 }
4042
41- if ( ch === "}" )
42- {
43- state . _indent -- ;
43+ if ( ch === "{" ) {
44+ state . _indent . push ( "{" ) ;
4445 return null ;
4546 }
47+
48+ if ( ch == ")" ) {
49+ state . _indent . pop ( ) ;
50+ state . _indent . pop ( ) ;
51+ }
4652
53+ if ( ch === "}" ) {
54+ state . _indent . pop ( ) ;
55+ return null ;
56+ }
57+
58+ if ( ch == "," )
59+ return null ;
60+
61+ if ( ch == ";" )
62+ return null ;
63+
64+
4765 if ( / [ { } \( \) , ; ] / . test ( ch ) )
4866 return null ;
4967
@@ -62,7 +80,7 @@ CodeMirror.defineMode("sieve", function(config) {
6280 return "operator" ;
6381 }
6482
65- stream . eatWhile ( / [ \w \$ _ ] / ) ;
83+ stream . eatWhile ( / \w / ) ;
6684 var cur = stream . current ( ) ;
6785
6886 // "text:" *(SP / HTAB) (hash-comment / CRLF)
@@ -79,6 +97,8 @@ CodeMirror.defineMode("sieve", function(config) {
7997
8098 if ( atoms . propertyIsEnumerable ( cur ) )
8199 return "atom" ;
100+
101+ return null ;
82102 }
83103
84104 function tokenMultiLineString ( stream , state )
@@ -135,7 +155,7 @@ CodeMirror.defineMode("sieve", function(config) {
135155 startState : function ( base ) {
136156 return { tokenize : tokenBase ,
137157 baseIndent : base || 0 ,
138- _indent : 0 } ;
158+ _indent : [ ] } ;
139159 } ,
140160
141161 token : function ( stream , state ) {
@@ -146,7 +166,14 @@ CodeMirror.defineMode("sieve", function(config) {
146166 } ,
147167
148168 indent : function ( state , textAfter ) {
149- return state . baseIndent + state . _indent * indentUnit ;
169+ var length = state . _indent . length ;
170+ if ( textAfter && ( textAfter [ 0 ] == "}" ) )
171+ length -- ;
172+
173+ if ( length < 0 )
174+ length = 0 ;
175+
176+ return length * indentUnit ;
150177 } ,
151178
152179 electricChars : "}"
0 commit comments