| 36 | // Tokenizers |
| 37 | |
| 38 | function tokenBase(stream, state) { |
| 39 | var ch = stream.next(); |
| 40 | if (tokenHooks[ch]) { |
| 41 | var result = tokenHooks[ch](stream, state); |
| 42 | if (result !== false) return result; |
| 43 | } |
| 44 | if (ch == "@") { |
| 45 | stream.eatWhile(/[\w\\\-]/); |
| 46 | return ret("def", stream.current()); |
| 47 | } else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) { |
| 48 | return ret(null, "compare"); |
| 49 | } else if (ch == "\"" || ch == "'") { |
| 50 | state.tokenize = tokenString(ch); |
| 51 | return state.tokenize(stream, state); |
| 52 | } else if (ch == "#") { |
| 53 | stream.eatWhile(/[\w\\\-]/); |
| 54 | return ret("atom", "hash"); |
| 55 | } else if (ch == "!") { |
| 56 | stream.match(/^\s*\w*/); |
| 57 | return ret("keyword", "important"); |
| 58 | } else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) { |
| 59 | stream.eatWhile(/[\w.%]/); |
| 60 | return ret("number", "unit"); |
| 61 | } else if (ch === "-") { |
| 62 | if (/[\d.]/.test(stream.peek())) { |
| 63 | stream.eatWhile(/[\w.%]/); |
| 64 | return ret("number", "unit"); |
| 65 | } else if (stream.match(/^-[\w\\\-]+/)) { |
| 66 | stream.eatWhile(/[\w\\\-]/); |
| 67 | if (stream.match(/^\s*:/, false)) |
| 68 | return ret("variable-2", "variable-definition"); |
| 69 | return ret("variable-2", "variable"); |
| 70 | } else if (stream.match(/^\w+-/)) { |
| 71 | return ret("meta", "meta"); |
| 72 | } |
| 73 | } else if (/[,+>*\/]/.test(ch)) { |
| 74 | return ret(null, "select-op"); |
| 75 | } else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) { |
| 76 | return ret("qualifier", "qualifier"); |
| 77 | } else if (/[:;{}\[\]\(\)]/.test(ch)) { |
| 78 | return ret(null, ch); |
| 79 | } else if ((ch == "u" && stream.match(/rl(-prefix)?\(/)) || |
| 80 | (ch == "d" && stream.match("omain(")) || |
| 81 | (ch == "r" && stream.match("egexp("))) { |
| 82 | stream.backUp(1); |
| 83 | state.tokenize = tokenParenthesized; |
| 84 | return ret("property", "word"); |
| 85 | } else if (/[\w\\\-]/.test(ch)) { |
| 86 | stream.eatWhile(/[\w\\\-]/); |
| 87 | return ret("property", "word"); |
| 88 | } else { |
| 89 | return ret(null, null); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | function tokenString(quote) { |
| 94 | return function(stream, state) { |