| 1 |
function wordObj(words) { |
| 2 |
var o = {}; |
| 3 |
for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true; |
| 4 |
return o; |
| 5 |
} |
| 6 |
var keywords = wordObj([ |
| 7 |
'note', |
| 8 |
'across', |
| 9 |
'when', |
| 10 |
'variant', |
| 11 |
'until', |
| 12 |
'unique', |
| 13 |
'undefine', |
| 14 |
'then', |
| 15 |
'strip', |
| 16 |
'select', |
| 17 |
'retry', |
| 18 |
'rescue', |
| 19 |
'require', |
| 20 |
'rename', |
| 21 |
'reference', |
| 22 |
'redefine', |
| 23 |
'prefix', |
| 24 |
'once', |
| 25 |
'old', |
| 26 |
'obsolete', |
| 27 |
'loop', |
| 28 |
'local', |
| 29 |
'like', |
| 30 |
'is', |
| 31 |
'inspect', |
| 32 |
'infix', |
| 33 |
'include', |
| 34 |
'if', |
| 35 |
'frozen', |
| 36 |
'from', |
| 37 |
'external', |
| 38 |
'export', |
| 39 |
'ensure', |
| 40 |
'end', |
| 41 |
'elseif', |
| 42 |
'else', |
| 43 |
'do', |
| 44 |
'creation', |
| 45 |
'create', |
| 46 |
'check', |
| 47 |
'alias', |
| 48 |
'agent', |
| 49 |
'separate', |
| 50 |
'invariant', |
| 51 |
'inherit', |
| 52 |
'indexing', |
| 53 |
'feature', |
| 54 |
'expanded', |
| 55 |
'deferred', |
| 56 |
'class', |
| 57 |
'Void', |
| 58 |
'True', |
| 59 |
'Result', |
| 60 |
'Precursor', |
| 61 |
'False', |
| 62 |
'Current', |
| 63 |
'create', |
| 64 |
'attached', |
| 65 |
'detachable', |
| 66 |
'as', |
| 67 |
'and', |
| 68 |
'implies', |
| 69 |
'not', |
| 70 |
'or' |
| 71 |
]); |
| 72 |
var operators = wordObj([":=", "and then","and", "or","<<",">>"]); |
| 73 |
|
| 74 |
function chain(newtok, stream, state) { |
| 75 |
state.tokenize.push(newtok); |
| 76 |
return newtok(stream, state); |
| 77 |
} |
| 78 |
|
| 79 |
function tokenBase(stream, state) { |
| 80 |
if (stream.eatSpace()) return null; |
| 81 |
var ch = stream.next(); |
| 82 |
if (ch == '"'||ch == "'") { |
| 83 |
return chain(readQuoted(ch, "string"), stream, state); |
| 84 |
} else if (ch == "-"&&stream.eat("-")) { |
| 85 |
stream.skipToEnd(); |
| 86 |
return "comment"; |
| 87 |
} else if (ch == ":"&&stream.eat("=")) { |
| 88 |
return "operator"; |
| 89 |
} else if (/[0-9]/.test(ch)) { |
| 90 |
stream.eatWhile(/[xXbBCc0-9\.]/); |
| 91 |
stream.eat(/[\?\!]/); |
| 92 |
return "variable"; |
| 93 |
} else if (/[a-zA-Z_0-9]/.test(ch)) { |
| 94 |
stream.eatWhile(/[a-zA-Z_0-9]/); |
| 95 |
stream.eat(/[\?\!]/); |
| 96 |
return "variable"; |
| 97 |
} else if (/[=+\-\/*^%<>~]/.test(ch)) { |
| 98 |
stream.eatWhile(/[=+\-\/*^%<>~]/); |
| 99 |
return "operator"; |
| 100 |
} else { |
| 101 |
return null; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
function readQuoted(quote, style, unescaped) { |
| 106 |
return function(stream, state) { |
| 107 |
var escaped = false, ch; |
| 108 |
while ((ch = stream.next()) != null) { |
| 109 |
if (ch == quote && (unescaped || !escaped)) { |
| 110 |
state.tokenize.pop(); |
| 111 |
break; |
| 112 |
} |
| 113 |
escaped = !escaped && ch == "%"; |
| 114 |
} |
| 115 |
return style; |
| 116 |
}; |
| 117 |
} |
| 118 |
|
| 119 |
export const eiffel = { |
| 120 |
name: "eiffel", |
| 121 |
startState: function() { |
| 122 |
return {tokenize: [tokenBase]}; |
| 123 |
}, |
| 124 |
|
| 125 |
token: function(stream, state) { |
| 126 |
var style = state.tokenize[state.tokenize.length-1](stream, state); |
| 127 |
if (style == "variable") { |
| 128 |
var word = stream.current(); |
| 129 |
style = keywords.propertyIsEnumerable(stream.current()) ? "keyword" |
| 130 |
: operators.propertyIsEnumerable(stream.current()) ? "operator" |
| 131 |
: /^[A-Z][A-Z_0-9]*$/g.test(word) ? "tag" |
| 132 |
: /^0[bB][0-1]+$/g.test(word) ? "number" |
| 133 |
: /^0[cC][0-7]+$/g.test(word) ? "number" |
| 134 |
: /^0[xX][a-fA-F0-9]+$/g.test(word) ? "number" |
| 135 |
: /^([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)$/g.test(word) ? "number" |
| 136 |
: /^[0-9]+$/g.test(word) ? "number" |
| 137 |
: "variable"; |
| 138 |
} |
| 139 |
return style; |
| 140 |
}, |
| 141 |
languageData: { |
| 142 |
commentTokens: {line: "--"} |
| 143 |
} |
| 144 |
}; |
| 145 |
|