(cm, pos, precise, asArray)
| 6794 | |
| 6795 | // Utility for getTokenAt and getLineTokens |
| 6796 | function takeToken(cm, pos, precise, asArray) { |
| 6797 | function getObj(copy) { |
| 6798 | return {start: stream.start, end: stream.pos, |
| 6799 | string: stream.current(), |
| 6800 | type: style || null, |
| 6801 | state: copy ? copyState(doc.mode, state) : state}; |
| 6802 | } |
| 6803 | |
| 6804 | var doc = cm.doc, mode = doc.mode, style; |
| 6805 | pos = clipPos(doc, pos); |
| 6806 | var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise); |
| 6807 | var stream = new StringStream(line.text, cm.options.tabSize), tokens; |
| 6808 | if (asArray) tokens = []; |
| 6809 | while ((asArray || stream.pos < pos.ch) && !stream.eol()) { |
| 6810 | stream.start = stream.pos; |
| 6811 | style = readToken(mode, stream, state); |
| 6812 | if (asArray) tokens.push(getObj(true)); |
| 6813 | } |
| 6814 | return asArray ? tokens : getObj(); |
| 6815 | } |
| 6816 | |
| 6817 | // Run the given mode's parser over a line, calling f for each token. |
| 6818 | function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) { |
no test coverage detected