Skip to content

Commit 281f132

Browse files
authored
[various modes[ Replace regexp stream.match with string matches
Warning: This works only when the match() call is a StringStream.match(), not if it is a native String.match(). Please carefully review this and make sure this doesn't break anything.
1 parent 4823ade commit 281f132

File tree

16 files changed

+44
-44
lines changed

16 files changed

+44
-44
lines changed

mode/dtd/dtd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ CodeMirror.defineMode("dtd", function(config) {
112112
indent: function(state, textAfter) {
113113
var n = state.stack.length;
114114

115-
if( textAfter.match(/\]\s+|\]/) )n=n-1;
115+
if( textAfter.charAt(0) === ']' )n--;
116116
else if(textAfter.substr(textAfter.length-1, textAfter.length) === ">"){
117117
if(textAfter.substr(0,1) === "<") {}
118118
else if( type == "doindent" && textAfter.length > 1 ) {}

mode/ebnf/ebnf.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
state.stringType = stream.peek();
4242
stream.next(); // Skip quote
4343
state.stack.unshift(stateType._string);
44-
} else if (stream.match(/^\/\*/)) { //comments starting with /*
44+
} else if (stream.match('/*')) { //comments starting with /*
4545
state.stack.unshift(stateType.comment);
4646
state.commentType = commentType.slash;
47-
} else if (stream.match(/^\(\*/)) { //comments starting with (*
47+
} else if (stream.match('(*')) { //comments starting with (*
4848
state.stack.unshift(stateType.comment);
4949
state.commentType = commentType.parenthesis;
5050
}
@@ -69,10 +69,10 @@
6969

7070
case stateType.comment:
7171
while (state.stack[0] === stateType.comment && !stream.eol()) {
72-
if (state.commentType === commentType.slash && stream.match(/\*\//)) {
72+
if (state.commentType === commentType.slash && stream.match('*/')) {
7373
state.stack.shift(); // Clear flag
7474
state.commentType = null;
75-
} else if (state.commentType === commentType.parenthesis && stream.match(/\*\)/)) {
75+
} else if (state.commentType === commentType.parenthesis && stream.match('*)')) {
7676
state.stack.shift(); // Clear flag
7777
state.commentType = null;
7878
} else {
@@ -83,7 +83,7 @@
8383

8484
case stateType.characterClass:
8585
while (state.stack[0] === stateType.characterClass && !stream.eol()) {
86-
if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./))) {
86+
if (!(stream.match(/^[^\]\\]+/) || stream.match('.'))) {
8787
state.stack.shift();
8888
}
8989
}
@@ -168,10 +168,10 @@
168168
}
169169
}
170170

171-
if (stream.match(/^\/\//)) {
171+
if (stream.match('//')) {
172172
stream.skipToEnd();
173173
return "comment";
174-
} else if (stream.match(/return/)) {
174+
} else if (stream.match('return')) {
175175
return "operator";
176176
} else if (stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/)) {
177177
if (stream.match(/(?=[\(.])/)) {

mode/julia/julia.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
8080
// tokenizers
8181
function tokenBase(stream, state) {
8282
// Handle multiline comments
83-
if (stream.match(/^#=/, false)) {
83+
if (stream.match('#=', false)) {
8484
state.tokenize = tokenComment;
8585
return state.tokenize(stream, state);
8686
}
@@ -141,10 +141,10 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
141141
}
142142

143143
if (inArray(state)) {
144-
if (state.lastToken == "end" && stream.match(/^:/)) {
144+
if (state.lastToken == "end" && stream.match(':')) {
145145
return "operator";
146146
}
147-
if (stream.match(/^end/)) {
147+
if (stream.match('end')) {
148148
return "number";
149149
}
150150
}
@@ -201,7 +201,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
201201
}
202202

203203
// Handle Chars
204-
if (stream.match(/^'/)) {
204+
if (stream.match('\'')) {
205205
state.tokenize = tokenChar;
206206
return state.tokenize(stream, state);
207207
}
@@ -263,7 +263,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
263263
state.scopes.push('(');
264264
charsAdvanced += match[1].length;
265265
}
266-
if (currentScope(state) == '(' && stream.match(/^\)/)) {
266+
if (currentScope(state) == '(' && stream.match(')')) {
267267
state.scopes.pop();
268268
charsAdvanced += 1;
269269
if (state.scopes.length <= state.firstParenPos) {
@@ -295,10 +295,10 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
295295
}
296296

297297
function tokenAnnotation(stream, state) {
298-
stream.match(/.*?(?=,|;|{|}|\(|\)|=|$|\s)/);
299-
if (stream.match(/^{/)) {
298+
stream.match(/.*?(?=[,;{}()=\s]|$)/);
299+
if (stream.match('{')) {
300300
state.nestedParameters++;
301-
} else if (stream.match(/^}/) && state.nestedParameters > 0) {
301+
} else if (stream.match('}') && state.nestedParameters > 0) {
302302
state.nestedParameters--;
303303
}
304304
if (state.nestedParameters > 0) {
@@ -310,13 +310,13 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
310310
}
311311

312312
function tokenComment(stream, state) {
313-
if (stream.match(/^#=/)) {
313+
if (stream.match('#=')) {
314314
state.nestedComments++;
315315
}
316316
if (!stream.match(/.*?(?=(#=|=#))/)) {
317317
stream.skipToEnd();
318318
}
319-
if (stream.match(/^=#/)) {
319+
if (stream.match('=#')) {
320320
state.nestedComments--;
321321
if (state.nestedComments == 0)
322322
state.tokenize = tokenBase;
@@ -347,7 +347,7 @@ CodeMirror.defineMode("julia", function(config, parserConf) {
347347
return "string";
348348
}
349349
if (!stream.match(/^[^']+(?=')/)) { stream.skipToEnd(); }
350-
if (stream.match(/^'/)) { state.tokenize = tokenBase; }
350+
if (stream.match('\'')) { state.tokenize = tokenBase; }
351351
return "error";
352352
}
353353

mode/markdown/markdown.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
612612
return getType(state);
613613
}
614614
} else if (ch === ' ') {
615-
if (stream.match(/^~~/, true)) { // Probably surrounded by space
615+
if (stream.match('~~', true)) { // Probably surrounded by space
616616
if (stream.peek() === ' ') { // Surrounded by spaces, ignore
617617
return getType(state);
618618
} else { // Not surrounded by spaces, back up pointer
@@ -711,7 +711,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
711711
}
712712

713713
function footnoteLinkInside(stream, state) {
714-
if (stream.match(/^\]:/, true)) {
714+
if (stream.match(']:', true)) {
715715
state.f = state.inline = footnoteUrl;
716716
if (modeCfg.highlightFormatting) state.formatting = "link";
717717
var returnType = getType(state);

mode/mscgen/mscgen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,15 @@
153153
return "variable";
154154

155155
/* attribute lists */
156-
if (!pConfig.inAttributeList && !!pConfig.attributes && pStream.match(/\[/, true, true)) {
156+
if (!pConfig.inAttributeList && !!pConfig.attributes && pStream.match('[', true, true)) {
157157
pConfig.inAttributeList = true;
158158
return "bracket";
159159
}
160160
if (pConfig.inAttributeList) {
161161
if (pConfig.attributes !== null && pStream.match(wordRegexpBoundary(pConfig.attributes), true, true)) {
162162
return "attribute";
163163
}
164-
if (pStream.match(/]/, true, true)) {
164+
if (pStream.match(']', true, true)) {
165165
pConfig.inAttributeList = false;
166166
return "bracket";
167167
}

mode/oz/oz.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CodeMirror.defineMode("oz", function (conf) {
4545
}
4646

4747
// Special [] keyword
48-
if (stream.match(/(\[])/)) {
48+
if (stream.match('[]')) {
4949
return "keyword"
5050
}
5151

mode/pegjs/pegjs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CodeMirror.defineMode("pegjs", function (config) {
3939
stream.next(); // Skip quote
4040
state.inString = true; // Update state
4141
}
42-
if (!state.inString && !state.inComment && stream.match(/^\/\*/)) {
42+
if (!state.inString && !state.inComment && stream.match('/*')) {
4343
state.inComment = true;
4444
}
4545

@@ -59,7 +59,7 @@ CodeMirror.defineMode("pegjs", function (config) {
5959
return state.lhs ? "property string" : "string"; // Token style
6060
} else if (state.inComment) {
6161
while (state.inComment && !stream.eol()) {
62-
if (stream.match(/\*\//)) {
62+
if (stream.match('*/')) {
6363
state.inComment = false; // Clear flag
6464
} else {
6565
stream.match(/^.[^\*]*/);
@@ -76,7 +76,7 @@ CodeMirror.defineMode("pegjs", function (config) {
7676
stream.next();
7777
state.inCharacterClass = true;
7878
return 'bracket';
79-
} else if (stream.match(/^\/\//)) {
79+
} else if (stream.match('//')) {
8080
stream.skipToEnd();
8181
return "comment";
8282
} else if (state.braced || stream.peek() === '{') {

mode/pug/pug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ CodeMirror.defineMode("pug", function (config) {
261261
}
262262
return 'variable';
263263
}
264-
if (stream.match(/^\+#{/, false)) {
264+
if (stream.match('+#{', false)) {
265265
stream.next();
266266
state.mixinCallAfter = true;
267267
return interpolation(stream, state);

mode/rpm/rpm.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ CodeMirror.defineMode("rpm-spec", function() {
8080

8181
// Macros like '%make_install' or '%attr(0775,root,root)'
8282
if (stream.match(/^%[\w]+/)) {
83-
if (stream.match(/^\(/)) { state.macroParameters = true; }
83+
if (stream.match('(')) { state.macroParameters = true; }
8484
return "keyword";
8585
}
8686
if (state.macroParameters) {
8787
if (stream.match(/^\d+/)) { return "number";}
88-
if (stream.match(/^\)/)) {
88+
if (stream.match(')')) {
8989
state.macroParameters = false;
9090
return "keyword";
9191
}

mode/sass/sass.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ CodeMirror.defineMode("sass", function(config) {
231231
}
232232

233233
if(ch === "@"){
234-
if(stream.match(/@extend/)){
234+
if(stream.match('@extend')){
235235
if(!stream.match(/\s*[\w]/))
236236
dedent(state);
237237
}

0 commit comments

Comments
 (0)