|
52 | 52 | str: 4 // string |
53 | 53 | }; |
54 | 54 |
|
55 | | - var pat = /^(?:([\r\n\t\ ]+)|([~*.,>\)\(])|(string|boolean|null|array|object|number)|(:(?:root|first-child|last-child|only-child))|(:(?:nth-child|nth-last-child|has|expr|val|contains))|(:\w+)|(\"(?:[^\\]|\\[^\"])*\")|(\")|((?:[_a-zA-Z]|[^\0-\0177]|\\[^\r\n\f0-9a-fA-F])(?:[_a-zA-Z0-9\-]|[^\u0000-\u0177]|(?:\\[^\r\n\f0-9a-fA-F]))*))/; |
| 55 | + // The primary lexing regular expression in jsonselect |
| 56 | + var pat = new RegExp( |
| 57 | + "^(?:" + |
| 58 | + // (1) whitespace |
| 59 | + "([\\r\\n\\t\\ ]+)|" + |
| 60 | + // (2) one-char ops |
| 61 | + "([~*,>\\)\\(])|" + |
| 62 | + // (3) types names |
| 63 | + "(string|boolean|null|array|object|number)|" + |
| 64 | + // (4) pseudo classes |
| 65 | + "(:(?:root|first-child|last-child|only-child))|" + |
| 66 | + // (5) pseudo functions |
| 67 | + "(:(?:nth-child|nth-last-child|has|expr|val|contains))|" + |
| 68 | + // (6) bogusly named pseudo something or others |
| 69 | + "(:\\w+)|" + |
| 70 | + // (7) JSON strings |
| 71 | + "\\.(\\\"(?:[^\\\\]|\\\\[^\\\"])*\\\")|" + |
| 72 | + // (8) bogus JSON strings missing a trailing quote |
| 73 | + "(\\\")|" + |
| 74 | + // (9) identifiers (unquoted) |
| 75 | + "\\.((?:[_a-zA-Z]|[^\\0-\\0177]|\\\\[^\\r\\n\\f0-9a-fA-F])(?:[_a-zA-Z0-9\\-]|[^\\u0000-\\u0177]|(?:\\\\[^\\r\\n\\f0-9a-fA-F]))*)" + |
| 76 | + ")" |
| 77 | + ); |
| 78 | + |
| 79 | + // A regular expression for matching "nth expressions" (see grammar, what :nth-child() eats) |
56 | 80 | var nthPat = /^\s*\(\s*(?:([+\-]?)([0-9]*)n\s*(?:([+\-])\s*([0-9]))?|(odd|even)|([+\-]?[0-9]+))\s*\)/; |
57 | 81 | function lex(str, off) { |
58 | 82 | if (!off) off = 0; |
|
66 | 90 | else if (m[4]) a = [off, toks.psc, m[0]]; |
67 | 91 | else if (m[5]) a = [off, toks.psf, m[0]]; |
68 | 92 | else if (m[6]) te("upc"); |
69 | | - else if (m[7]) a = [off, toks.str, jsonParse(m[0])]; |
| 93 | + else if (m[7]) a = [off, toks.str, jsonParse(m[7])]; |
70 | 94 | else if (m[8]) te("ujs"); |
71 | | - else if (m[9]) a = [off, toks.str, m[0].replace(/\\([^\r\n\f0-9a-fA-F])/g,"$1")]; |
| 95 | + else if (m[9]) a = [off, toks.str, m[9].replace(/\\([^\r\n\f0-9a-fA-F])/g,"$1")]; |
72 | 96 | return a; |
73 | 97 | } |
74 | 98 |
|
75 | 99 | // THE EXPRESSION SUBSYSTEM |
76 | 100 |
|
77 | 101 | var exprPat = new RegExp( |
78 | | - // skip and don't capture leading whitespace |
79 | | - "^\\s*(?:" + |
| 102 | + // skip and don't capture leading whitespace |
| 103 | + "^\\s*(?:" + |
80 | 104 | // (1) simple vals |
81 | 105 | "(true|false|null)|" + |
82 | 106 | // (2) numbers |
|
296 | 320 | while (true) { |
297 | 321 | if (l === undefined) { |
298 | 322 | break; |
299 | | - } else if (l[1] === ".") { |
300 | | - l = lex(str, (off = l[0])); |
301 | | - if (!l || l[1] !== toks.str) te("sra"); |
| 323 | + } else if (l[1] === toks.str) { |
302 | 324 | if (s.id) te("nmi"); |
303 | 325 | s.id = l[2]; |
304 | 326 | } else if (l[1] === toks.psc) { |
|
0 commit comments