(states, config)
| 92 | } |
| 93 | |
| 94 | function tokenFunction(states, config) { |
| 95 | return function(stream, state) { |
| 96 | if (state.pending) { |
| 97 | var pend = state.pending.shift(); |
| 98 | if (state.pending.length == 0) state.pending = null; |
| 99 | stream.pos += pend.text.length; |
| 100 | return pend.token; |
| 101 | } |
| 102 | |
| 103 | if (state.local) { |
| 104 | if (state.local.end && stream.match(state.local.end)) { |
| 105 | var tok = state.local.endToken || null; |
| 106 | state.local = state.localState = null; |
| 107 | return tok; |
| 108 | } else { |
| 109 | var tok = state.local.mode.token(stream, state.localState), m; |
| 110 | if (state.local.endScan && (m = state.local.endScan.exec(stream.current()))) |
| 111 | stream.pos = stream.start + m.index; |
| 112 | return tok; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | var curState = states[state.state]; |
| 117 | for (var i = 0; i < curState.length; i++) { |
| 118 | var rule = curState[i]; |
| 119 | var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex); |
| 120 | if (matches) { |
| 121 | if (rule.data.next) { |
| 122 | state.state = rule.data.next; |
| 123 | } else if (rule.data.push) { |
| 124 | (state.stack || (state.stack = [])).push(state.state); |
| 125 | state.state = rule.data.push; |
| 126 | } else if (rule.data.pop && state.stack && state.stack.length) { |
| 127 | state.state = state.stack.pop(); |
| 128 | } |
| 129 | |
| 130 | if (rule.data.mode) |
| 131 | enterLocalMode(config, state, rule.data.mode, rule.token); |
| 132 | if (rule.data.indent) |
| 133 | state.indent.push(stream.indentation() + config.indentUnit); |
| 134 | if (rule.data.dedent) |
| 135 | state.indent.pop(); |
| 136 | if (matches.length > 2) { |
| 137 | state.pending = []; |
| 138 | for (var j = 2; j < matches.length; j++) |
| 139 | if (matches[j]) |
| 140 | state.pending.push({text: matches[j], token: rule.token[j - 1]}); |
| 141 | stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0)); |
| 142 | return rule.token[0]; |
| 143 | } else if (rule.token && rule.token.join) { |
| 144 | return rule.token[0]; |
| 145 | } else { |
| 146 | return rule.token; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | stream.next(); |
| 151 | return null; |
no test coverage detected
searching dependent graphs…