MCPcopy
hub / github.com/witheve/Eve / takeToken

Function takeToken

src/codemirror.js:6796–6815  ·  view source on GitHub ↗
(cm, pos, precise, asArray)

Source from the content-addressed store, hash-verified

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) {

Callers 1

codemirror.jsFile · 0.85

Calls 6

eolMethod · 0.95
clipPosFunction · 0.85
getLineFunction · 0.85
getStateBeforeFunction · 0.85
readTokenFunction · 0.85
getObjFunction · 0.85

Tested by

no test coverage detected