* @function CartoCSS.prototype.getParser * @description 获取 CartoCSS 解析器。
(env)
| 70 | * @description 获取 CartoCSS 解析器。 |
| 71 | */ |
| 72 | getParser(env) { |
| 73 | var input, // LeSS input string |
| 74 | i, // current index in `input` |
| 75 | j, // current chunk |
| 76 | temp, // temporarily holds a chunk's state, for backtracking |
| 77 | memo, // temporarily holds `i`, when backtracking |
| 78 | furthest, // furthest index the parser has gone to |
| 79 | chunks, // chunkified input |
| 80 | current, // index of current chunk, in `input` |
| 81 | parser; |
| 82 | |
| 83 | var that = this; |
| 84 | |
| 85 | // This function is called after all files |
| 86 | // have been imported through `@import`. |
| 87 | var finish = function () {//NOSONAR |
| 88 | //所有文件导入完成之后调用 |
| 89 | }; |
| 90 | |
| 91 | function save() { |
| 92 | temp = chunks[j]; |
| 93 | memo = i; |
| 94 | current = i; |
| 95 | } |
| 96 | |
| 97 | function restore() { |
| 98 | chunks[j] = temp; |
| 99 | i = memo; |
| 100 | current = i; |
| 101 | } |
| 102 | |
| 103 | function sync() { |
| 104 | if (i > current) { |
| 105 | chunks[j] = chunks[j].slice(i - current); |
| 106 | current = i; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | // |
| 111 | // Parse from a token, regexp or string, and move forward if match |
| 112 | // |
| 113 | function _match(tok) { |
| 114 | var match, length, c, endIndex; |
| 115 | |
| 116 | // Non-terminal |
| 117 | if (tok instanceof Function) { |
| 118 | return tok.call(parser.parsers); |
| 119 | // Terminal |
| 120 | // Either match a single character in the input, |
| 121 | // or match a regexp in the current chunk (chunk[j]). |
| 122 | } else if (typeof(tok) === 'string') { |
| 123 | match = input.charAt(i) === tok ? tok : null; |
| 124 | length = 1; |
| 125 | sync(); |
| 126 | } else { |
| 127 | sync(); |
| 128 | |
| 129 | match = tok.exec(chunks[j]); |