Skip to content

Commit 35e8137

Browse files
committed
[php mode] Follow up on beb975f
Simplify some things, change a name. Issue #2468
1 parent 0b65050 commit 35e8137

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

mode/php/php.js

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,20 @@
1212
};
1313
}
1414

15-
// Two helper functions for encapsList
16-
function matchFirst(list) {
17-
return function (stream) {
18-
for (var i = 0; i < list.length; ++i)
19-
if (stream.match(list[i][0]))
20-
return list[i][1];
21-
return false;
22-
};
23-
}
15+
// Helper for stringWithEscapes
2416
function matchSequence(list) {
25-
if (list.length == 0) return encapsList;
17+
if (list.length == 0) return stringWithEscapes;
2618
return function (stream, state) {
27-
var result = list[0](stream, state);
28-
if (result !== false) {
19+
var patterns = list[0];
20+
for (var i = 0; i < patterns.length; i++) if (stream.match(patterns[i][0])) {
2921
state.tokenize = matchSequence(list.slice(1));
30-
return result;
31-
}
32-
else {
33-
state.tokenize = encapsList;
34-
return "string";
22+
return patterns[i][1];
3523
}
24+
state.tokenize = stringWithEscapes;
25+
return "string";
3626
};
3727
}
38-
function encapsList(stream, state) {
28+
function stringWithEscapes(stream, state) {
3929
var escaped = false, next, end = false;
4030

4131
if (stream.current() == '"') return "string";
@@ -52,20 +42,18 @@
5242
if (stream.match("[", false)) {
5343
// Match array operator
5444
state.tokenize = matchSequence([
55-
matchFirst([["[", null]]),
56-
matchFirst([
57-
[/\d[\w\.]*/, "number"],
58-
[/\$[a-zA-Z_][a-zA-Z0-9_]*/, "variable-2"],
59-
[/[\w\$]+/, "variable"]
60-
]),
61-
matchFirst([["]", null]])
45+
[["[", null]],
46+
[[/\d[\w\.]*/, "number"],
47+
[/\$[a-zA-Z_][a-zA-Z0-9_]*/, "variable-2"],
48+
[/[\w\$]+/, "variable"]],
49+
[["]", null]]
6250
]);
6351
}
6452
if (stream.match(/\-\>\w/, false)) {
6553
// Match object operator
6654
state.tokenize = matchSequence([
67-
matchFirst([["->", null]]),
68-
matchFirst([[/[\w]+/, "variable"]])
55+
[["->", null]],
56+
[[/[\w]+/, "variable"]]
6957
]);
7058
}
7159
return "variable-2";
@@ -134,7 +122,7 @@
134122
if (!state.phpEncapsStack)
135123
state.phpEncapsStack = [];
136124
state.phpEncapsStack.push(0);
137-
state.tokenize = encapsList;
125+
state.tokenize = stringWithEscapes;
138126
return state.tokenize(stream, state);
139127
},
140128
"{": function(_stream, state) {
@@ -145,7 +133,7 @@
145133
"}": function(_stream, state) {
146134
if (state.phpEncapsStack && state.phpEncapsStack.length > 0)
147135
if (--state.phpEncapsStack[state.phpEncapsStack.length - 1] == 0)
148-
state.tokenize = encapsList;
136+
state.tokenize = stringWithEscapes;
149137
return false;
150138
}
151139
}

0 commit comments

Comments
 (0)