|
12 | 12 | }; |
13 | 13 | } |
14 | 14 |
|
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 |
24 | 16 | function matchSequence(list) { |
25 | | - if (list.length == 0) return encapsList; |
| 17 | + if (list.length == 0) return stringWithEscapes; |
26 | 18 | 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])) { |
29 | 21 | state.tokenize = matchSequence(list.slice(1)); |
30 | | - return result; |
31 | | - } |
32 | | - else { |
33 | | - state.tokenize = encapsList; |
34 | | - return "string"; |
| 22 | + return patterns[i][1]; |
35 | 23 | } |
| 24 | + state.tokenize = stringWithEscapes; |
| 25 | + return "string"; |
36 | 26 | }; |
37 | 27 | } |
38 | | - function encapsList(stream, state) { |
| 28 | + function stringWithEscapes(stream, state) { |
39 | 29 | var escaped = false, next, end = false; |
40 | 30 |
|
41 | 31 | if (stream.current() == '"') return "string"; |
|
52 | 42 | if (stream.match("[", false)) { |
53 | 43 | // Match array operator |
54 | 44 | 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]] |
62 | 50 | ]); |
63 | 51 | } |
64 | 52 | if (stream.match(/\-\>\w/, false)) { |
65 | 53 | // Match object operator |
66 | 54 | state.tokenize = matchSequence([ |
67 | | - matchFirst([["->", null]]), |
68 | | - matchFirst([[/[\w]+/, "variable"]]) |
| 55 | + [["->", null]], |
| 56 | + [[/[\w]+/, "variable"]] |
69 | 57 | ]); |
70 | 58 | } |
71 | 59 | return "variable-2"; |
|
134 | 122 | if (!state.phpEncapsStack) |
135 | 123 | state.phpEncapsStack = []; |
136 | 124 | state.phpEncapsStack.push(0); |
137 | | - state.tokenize = encapsList; |
| 125 | + state.tokenize = stringWithEscapes; |
138 | 126 | return state.tokenize(stream, state); |
139 | 127 | }, |
140 | 128 | "{": function(_stream, state) { |
|
145 | 133 | "}": function(_stream, state) { |
146 | 134 | if (state.phpEncapsStack && state.phpEncapsStack.length > 0) |
147 | 135 | if (--state.phpEncapsStack[state.phpEncapsStack.length - 1] == 0) |
148 | | - state.tokenize = encapsList; |
| 136 | + state.tokenize = stringWithEscapes; |
149 | 137 | return false; |
150 | 138 | } |
151 | 139 | } |
|
0 commit comments