MCPcopy Index your code
hub / github.com/feiyu563/PrometheusAlert / tokenBaseInner

Function tokenBaseInner

static/plugins/codemirror/mode/python/python.js:101–181  ·  view source on GitHub ↗
(stream, state, inFormat)

Source from the content-addressed store, hash-verified

99 }
100
101 function tokenBaseInner(stream, state, inFormat) {
102 if (stream.eatSpace()) return null;
103
104 // Handle Comments
105 if (!inFormat && stream.match(/^#.*/)) return "comment";
106
107 // Handle Number Literals
108 if (stream.match(/^[0-9\.]/, false)) {
109 var floatLiteral = false;
110 // Floats
111 if (stream.match(/^[\d_]*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
112 if (stream.match(/^[\d_]+\.\d*/)) { floatLiteral = true; }
113 if (stream.match(/^\.\d+/)) { floatLiteral = true; }
114 if (floatLiteral) {
115 // Float literals may be "imaginary"
116 stream.eat(/J/i);
117 return "number";
118 }
119 // Integers
120 var intLiteral = false;
121 // Hex
122 if (stream.match(/^0x[0-9a-f_]+/i)) intLiteral = true;
123 // Binary
124 if (stream.match(/^0b[01_]+/i)) intLiteral = true;
125 // Octal
126 if (stream.match(/^0o[0-7_]+/i)) intLiteral = true;
127 // Decimal
128 if (stream.match(/^[1-9][\d_]*(e[\+\-]?[\d_]+)?/)) {
129 // Decimal literals may be "imaginary"
130 stream.eat(/J/i);
131 // TODO - Can you have imaginary longs?
132 intLiteral = true;
133 }
134 // Zero by itself with no other piece of number.
135 if (stream.match(/^0(?![\dx])/i)) intLiteral = true;
136 if (intLiteral) {
137 // Integer literals may be "long"
138 stream.eat(/L/i);
139 return "number";
140 }
141 }
142
143 // Handle Strings
144 if (stream.match(stringPrefixes)) {
145 var isFmtString = stream.current().toLowerCase().indexOf('f') !== -1;
146 if (!isFmtString) {
147 state.tokenize = tokenStringFactory(stream.current(), state.tokenize);
148 return state.tokenize(stream, state);
149 } else {
150 state.tokenize = formatStringFactory(stream.current(), state.tokenize);
151 return state.tokenize(stream, state);
152 }
153 }
154
155 for (var i = 0; i < operators.length; i++)
156 if (stream.match(operators[i])) return "operator"
157
158 if (stream.match(delimiters)) return "punctuation";

Callers 2

tokenBaseFunction · 0.85
tokenNestedExprFunction · 0.85

Calls 2

formatStringFactoryFunction · 0.85
tokenStringFactoryFunction · 0.70

Tested by

no test coverage detected