MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / tokenize

Function tokenize

src/lib/libc_preprocessor.js:88–113  ·  view source on GitHub ↗

* @param {string} exprString * @param {(number|boolean)=} keepWhitespace Optional, can be omitted. Defaults to false.

(exprString, keepWhitespace)

Source from the content-addressed store, hash-verified

86 * @param {(number|boolean)=} keepWhitespace Optional, can be omitted. Defaults to false.
87 */
88 function tokenize(exprString, keepWhitespace) {
89 var out = [], len = exprString.length;
90 for (var i = 0; i <= len; ++i) {
91 var kind = classifyChar(exprString, i);
92 if (kind == 2/*0-9*/ || kind == 3/*a-z*/) { // a character or a number
93 for (var j = i+1; j <= len; ++j) {
94 var kind2 = classifyChar(exprString, j);
95 if (kind2 != kind && (kind2 != 2/*0-9*/ || kind != 3/*a-z*/)) { // parse number sequence "423410", and identifier sequence "FOO32BAR"
96 out.push(exprString.substring(i, j));
97 i = j-1;
98 break;
99 }
100 }
101 } else if (kind == 1/*operator symbol*/) {
102 // Lookahead for two-character operators.
103 var op2 = exprString.slice(i, i + 2);
104 if (['<=', '>=', '==', '!=', '&&', '||'].includes(op2)) {
105 out.push(op2);
106 ++i;
107 } else {
108 out.push(exprString[i]);
109 }
110 }
111 }
112 return out;
113 }
114
115 // Expands preprocessing macros on substring str[lineStart...lineEnd]
116 /**

Callers 1

expandMacrosFunction · 0.85

Calls 3

classifyCharFunction · 0.85
sliceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected