(cm, pos, precise, asArray)
| 6769 | |
| 6770 | // Utility for getTokenAt and getLineTokens |
| 6771 | function takeToken(cm, pos, precise, asArray) { |
| 6772 | function getObj(copy) { |
| 6773 | return {start: stream.start, end: stream.pos, |
| 6774 | string: stream.current(), |
| 6775 | type: style || null, |
| 6776 | state: copy ? copyState(doc.mode, state) : state}; |
| 6777 | } |
| 6778 | |
| 6779 | var doc = cm.doc, mode = doc.mode, style; |
| 6780 | pos = clipPos(doc, pos); |
| 6781 | var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise); |
| 6782 | var stream = new StringStream(line.text, cm.options.tabSize), tokens; |
| 6783 | if (asArray) tokens = []; |
| 6784 | while ((asArray || stream.pos < pos.ch) && !stream.eol()) { |
| 6785 | stream.start = stream.pos; |
| 6786 | style = readToken(mode, stream, state); |
| 6787 | if (asArray) tokens.push(getObj(true)); |
| 6788 | } |
| 6789 | return asArray ? tokens : getObj(); |
| 6790 | } |
| 6791 | |
| 6792 | // Run the given mode's parser over a line, calling f for each token. |
| 6793 | function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) { |
no test coverage detected