@@ -156,23 +156,34 @@ CodeMirror.defineMode("clojure", function (options) {
156156 var specialForm = createLookupMap ( specialForms ) ;
157157 var coreSymbol = createLookupMap ( coreSymbols ) ;
158158 var hasBodyParameter = createLookupMap ( haveBodyParameter ) ;
159- var numberLiteral = / ^ [ + \- ] ? \d + (?: (?: N | (?: [ e E ] [ + \- ] ? \d + ) ) | (?: \. ? \d * (?: M | (?: [ e E ] [ + \- ] ? \d + ) ) ? ) | \/ \d + | [ x X ] [ 0 - 9 a - f A - F ] + | r [ 0 - 9 a - z A - Z ] + ) ? / ;
160- var symbolCharacter = / [ ! # $ & ' * + \- . \/ : < = > ? _ | \w \xa1 - \uffff ] / ;
159+ var delimiter = / ^ (?: [ \\ \[ \] \s " ( ) , ; @ ^ ` { } ~ ] | $ ) / ;
160+ var numberLiteral = / ^ (?: [ + \- ] ? \d + (?: (?: N | (?: [ e E ] [ + \- ] ? \d + ) ) | (?: \. ? \d * (?: M | (?: [ e E ] [ + \- ] ? \d + ) ) ? ) | \/ \d + | [ x X ] [ 0 - 9 a - f A - F ] + | r [ 0 - 9 a - z A - Z ] + ) ? (? = [ \\ \[ \] \s " # ' ( ) , ; @ ^ ` { } ~ ] | $ ) ) / ;
161+ var characterLiteral = / ^ (?: \\ (?: b a c k s p a c e | f o r m f e e d | n e w l i n e | r e t u r n | s p a c e | t a b | o [ 0 - 7 ] { 3 } | u [ 0 - 9 A - F a - f ] { 4 } | x [ 0 - 9 A - F a - f ] { 4 } | .) ? (? = [ \\ \[ \] \s " ( ) , ; @ ^ ` { } ~ ] | $ ) ) / ;
162+
163+ // simple-namespace := /^[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*/
164+ // simple-symbol := /^(?:\/|[^\\\/\[\]\d\s"#'(),;@^`{}~][^\\\[\]\s"(),;@^`{}~]*)/
165+ // qualified-symbol := (<simple-namespace>(<.><simple-namespace>)*</>)?<simple-symbol>
166+ var qualifiedSymbol = / ^ (?: (?: [ ^ \\ \/ \[ \] \d \s " # ' ( ) , ; @ ^ ` { } ~ ] [ ^ \\ \[ \] \s " ( ) , ; @ ^ ` { } ~ ] * (?: \. [ ^ \\ \/ \[ \] \d \s " # ' ( ) , ; @ ^ ` { } ~ ] [ ^ \\ \[ \] \s " ( ) , ; @ ^ ` { } ~ ] * ) * \/ ) ? (?: \/ | [ ^ \\ \/ \[ \] \d \s " # ' ( ) , ; @ ^ ` { } ~ ] [ ^ \\ \[ \] \s " ( ) , ; @ ^ ` { } ~ ] * ) * (? = [ \\ \[ \] \s " ( ) , ; @ ^ ` { } ~ ] | $ ) ) / ;
161167
162168 function base ( stream , state ) {
163169 if ( stream . eatSpace ( ) ) return [ "space" , null ] ;
164170 if ( stream . match ( numberLiteral ) ) return [ null , "number" ] ;
165-
166- var ch = stream . next ( ) ;
167-
168- if ( ch === "\\" ) { stream . next ( ) ; readSymbol ( stream ) ; return [ null , "string-2" ] ; }
169- if ( ch === '"' ) return ( state . tokenize = inString ) ( stream , state ) ;
170- if ( is ( ch , / [ ( \[ { ] / ) ) return [ "open" , "bracket" ] ;
171- if ( is ( ch , / [ ) \] } ] / ) ) return [ "close" , "bracket" ] ;
172- if ( ch === ";" ) { stream . skipToEnd ( ) ; return [ "space" , "comment" ] ; }
173- if ( is ( ch , / [ # ' @ ^ ` ~ ] / ) ) return [ null , "meta" ] ;
174-
175- var symbol = readSymbol ( stream ) ;
171+ if ( stream . match ( characterLiteral ) ) return [ null , "string-2" ] ;
172+ if ( stream . eat ( / ^ " / ) ) return ( state . tokenize = inString ) ( stream , state ) ;
173+ if ( stream . eat ( / ^ [ ( \[ { ] / ) ) return [ "open" , "bracket" ] ;
174+ if ( stream . eat ( / ^ [ ) \] } ] / ) ) return [ "close" , "bracket" ] ;
175+ if ( stream . eat ( / ^ ; / ) ) { stream . skipToEnd ( ) ; return [ "space" , "comment" ] ; }
176+ if ( stream . eat ( / ^ [ # ' @ ^ ` ~ ] / ) ) return [ null , "meta" ] ;
177+
178+ var matches = stream . match ( qualifiedSymbol ) ;
179+ var symbol = matches && matches [ 0 ] ;
180+
181+ if ( ! symbol ) {
182+ // advance stream by at least one character so we don't get stuck.
183+ stream . next ( ) ;
184+ stream . eatWhile ( function ( c ) { return ! is ( c , delimiter ) ; } ) ;
185+ return [ null , "error" ] ;
186+ }
176187
177188 if ( symbol === "comment" && state . lastToken === "(" )
178189 return ( state . tokenize = inComment ) ( stream , state ) ;
@@ -187,7 +198,7 @@ CodeMirror.defineMode("clojure", function (options) {
187198 var escaped = false , next ;
188199
189200 while ( next = stream . next ( ) ) {
190- if ( next === '"' && ! escaped ) { state . tokenize = base ; break ; }
201+ if ( next === "\"" && ! escaped ) { state . tokenize = base ; break ; }
191202 escaped = ! escaped && next === "\\" ;
192203 }
193204
@@ -211,17 +222,6 @@ CodeMirror.defineMode("clojure", function (options) {
211222 return [ "space" , "comment" ] ;
212223 }
213224
214- function readSymbol ( stream ) {
215- var ch ;
216-
217- while ( ch = stream . next ( ) ) {
218- if ( ch === "\\" ) stream . next ( ) ;
219- else if ( ! is ( ch , symbolCharacter ) ) { stream . backUp ( 1 ) ; break ; }
220- }
221-
222- return stream . current ( ) ;
223- }
224-
225225 function createLookupMap ( words ) {
226226 var obj = { } ;
227227
0 commit comments