(cm, pos, precise, asArray)
| 6564 | |
| 6565 | // Utility for getTokenAt and getLineTokens |
| 6566 | function takeToken(cm, pos, precise, asArray) { |
| 6567 | function getObj(copy) { |
| 6568 | return {start: stream.start, end: stream.pos, |
| 6569 | string: stream.current(), |
| 6570 | type: style || null, |
| 6571 | state: copy ? copyState(doc.mode, state) : state}; |
| 6572 | } |
| 6573 | |
| 6574 | var doc = cm.doc, mode = doc.mode, style; |
| 6575 | pos = clipPos(doc, pos); |
| 6576 | var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise); |
| 6577 | var stream = new StringStream(line.text, cm.options.tabSize), tokens; |
| 6578 | if (asArray) tokens = []; |
| 6579 | while ((asArray || stream.pos < pos.ch) && !stream.eol()) { |
| 6580 | stream.start = stream.pos; |
| 6581 | style = readToken(mode, stream, state); |
| 6582 | if (asArray) tokens.push(getObj(true)); |
| 6583 | } |
| 6584 | return asArray ? tokens : getObj(); |
| 6585 | } |
| 6586 | |
| 6587 | // Run the given mode's parser over a line, calling f for each token. |
| 6588 | function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) { |
no test coverage detected
searching dependent graphs…