MCPcopy Create free account
hub / github.com/apache/cloudstack / lex

Function lex

tools/ngui/static/js/lib/angular.js:5802–6032  ·  view source on GitHub ↗
(text, csp)

Source from the content-addressed store, hash-verified

5800var ESCAPE = {"n":"\n", "f":"\f", "r":"\r", "t":"\t", "v":"\v", "'":"'", '"':'"'};
5801
5802function lex(text, csp){
5803 var tokens = [],
5804 token,
5805 index = 0,
5806 json = [],
5807 ch,
5808 lastCh = ':'; // can start regexp
5809
5810 while (index < text.length) {
5811 ch = text.charAt(index);
5812 if (is('"\'')) {
5813 readString(ch);
5814 } else if (isNumber(ch) || is('.') && isNumber(peek())) {
5815 readNumber();
5816 } else if (isIdent(ch)) {
5817 readIdent();
5818 // identifiers can only be if the preceding char was a { or ,
5819 if (was('{,') && json[0]=='{' &&
5820 (token=tokens[tokens.length-1])) {
5821 token.json = token.text.indexOf('.') == -1;
5822 }
5823 } else if (is('(){}[].,;:')) {
5824 tokens.push({
5825 index:index,
5826 text:ch,
5827 json:(was(':[,') && is('{[')) || is('}]:,')
5828 });
5829 if (is('{[')) json.unshift(ch);
5830 if (is('}]')) json.shift();
5831 index++;
5832 } else if (isWhitespace(ch)) {
5833 index++;
5834 continue;
5835 } else {
5836 var ch2 = ch + peek(),
5837 fn = OPERATORS[ch],
5838 fn2 = OPERATORS[ch2];
5839 if (fn2) {
5840 tokens.push({index:index, text:ch2, fn:fn2});
5841 index += 2;
5842 } else if (fn) {
5843 tokens.push({index:index, text:ch, fn:fn, json: was('[,:') && is('+-')});
5844 index += 1;
5845 } else {
5846 throwError("Unexpected next character ", index, index+1);
5847 }
5848 }
5849 lastCh = ch;
5850 }
5851 return tokens;
5852
5853 function is(chars) {
5854 return chars.indexOf(ch) != -1;
5855 }
5856
5857 function was(chars) {
5858 return chars.indexOf(lastCh) != -1;
5859 }

Callers 1

parserFunction · 0.85

Calls 10

isFunction · 0.85
readStringFunction · 0.85
isNumberFunction · 0.85
peekFunction · 0.85
readNumberFunction · 0.85
isIdentFunction · 0.85
readIdentFunction · 0.85
wasFunction · 0.85
isWhitespaceFunction · 0.85
throwErrorFunction · 0.85

Tested by

no test coverage detected