@quirekit/cm-legacy-modes 0.0.0-stage → 0.0.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -2
- package/README.zh-CN.md +28 -0
- package/THIRD_PARTY_NOTICES.md +141 -0
- package/UPSTREAM.json +16 -0
- package/dist/mode/README.md +52 -0
- package/dist/mode/apl.d.ts +2 -0
- package/dist/mode/apl.js +140 -0
- package/dist/mode/asciiarmor.d.ts +2 -0
- package/dist/mode/asciiarmor.js +54 -0
- package/dist/mode/asn1.d.ts +12 -0
- package/dist/mode/asn1.js +190 -0
- package/dist/mode/asterisk.d.ts +2 -0
- package/dist/mode/asterisk.js +186 -0
- package/dist/mode/brainfuck.d.ts +2 -0
- package/dist/mode/brainfuck.js +68 -0
- package/dist/mode/clike.d.ts +35 -0
- package/dist/mode/clike.js +1019 -0
- package/dist/mode/clojure.d.ts +2 -0
- package/dist/mode/clojure.js +272 -0
- package/dist/mode/cmake.d.ts +2 -0
- package/dist/mode/cmake.js +80 -0
- package/dist/mode/cobol.d.ts +2 -0
- package/dist/mode/cobol.js +234 -0
- package/dist/mode/coffeescript.d.ts +2 -0
- package/dist/mode/coffeescript.js +327 -0
- package/dist/mode/commonlisp.d.ts +2 -0
- package/dist/mode/commonlisp.js +107 -0
- package/dist/mode/crystal.d.ts +2 -0
- package/dist/mode/crystal.js +417 -0
- package/dist/mode/css.d.ts +5 -0
- package/dist/mode/css.js +846 -0
- package/dist/mode/cypher.d.ts +2 -0
- package/dist/mode/cypher.js +120 -0
- package/dist/mode/d.d.ts +2 -0
- package/dist/mode/d.js +203 -0
- package/dist/mode/diff.d.ts +2 -0
- package/dist/mode/diff.js +29 -0
- package/dist/mode/dockerfile.d.ts +2 -0
- package/dist/mode/dockerfile.js +198 -0
- package/dist/mode/dtd.d.ts +2 -0
- package/dist/mode/dtd.js +120 -0
- package/dist/mode/dylan.d.ts +2 -0
- package/dist/mode/dylan.js +336 -0
- package/dist/mode/ebnf.d.ts +2 -0
- package/dist/mode/ebnf.js +149 -0
- package/dist/mode/ecl.d.ts +2 -0
- package/dist/mode/ecl.js +188 -0
- package/dist/mode/eiffel.d.ts +2 -0
- package/dist/mode/eiffel.js +145 -0
- package/dist/mode/elm.d.ts +2 -0
- package/dist/mode/elm.js +228 -0
- package/dist/mode/erlang.d.ts +2 -0
- package/dist/mode/erlang.js +580 -0
- package/dist/mode/factor.d.ts +2 -0
- package/dist/mode/factor.js +63 -0
- package/dist/mode/fcl.d.ts +2 -0
- package/dist/mode/fcl.js +153 -0
- package/dist/mode/forth.d.ts +2 -0
- package/dist/mode/forth.js +162 -0
- package/dist/mode/fortran.d.ts +2 -0
- package/dist/mode/fortran.js +171 -0
- package/dist/mode/gas.d.ts +3 -0
- package/dist/mode/gas.js +342 -0
- package/dist/mode/gherkin.d.ts +2 -0
- package/dist/mode/gherkin.js +146 -0
- package/dist/mode/go.d.ts +2 -0
- package/dist/mode/go.js +163 -0
- package/dist/mode/groovy.d.ts +2 -0
- package/dist/mode/groovy.js +226 -0
- package/dist/mode/haskell.d.ts +2 -0
- package/dist/mode/haskell.js +238 -0
- package/dist/mode/haxe.d.ts +3 -0
- package/dist/mode/haxe.js +490 -0
- package/dist/mode/http.d.ts +2 -0
- package/dist/mode/http.js +87 -0
- package/dist/mode/idl.d.ts +2 -0
- package/dist/mode/idl.js +274 -0
- package/dist/mode/javascript.d.ts +5 -0
- package/dist/mode/javascript.js +922 -0
- package/dist/mode/jinja2.d.ts +2 -0
- package/dist/mode/jinja2.js +170 -0
- package/dist/mode/julia.d.ts +2 -0
- package/dist/mode/julia.js +367 -0
- package/dist/mode/livescript.d.ts +2 -0
- package/dist/mode/livescript.js +257 -0
- package/dist/mode/lua.d.ts +2 -0
- package/dist/mode/lua.js +135 -0
- package/dist/mode/mathematica.d.ts +2 -0
- package/dist/mode/mathematica.js +153 -0
- package/dist/mode/mbox.d.ts +2 -0
- package/dist/mode/mbox.js +114 -0
- package/dist/mode/mirc.d.ts +2 -0
- package/dist/mode/mirc.js +174 -0
- package/dist/mode/mllike.d.ts +4 -0
- package/dist/mode/mllike.js +346 -0
- package/dist/mode/modelica.d.ts +2 -0
- package/dist/mode/modelica.js +190 -0
- package/dist/mode/mscgen.d.ts +4 -0
- package/dist/mode/mscgen.js +147 -0
- package/dist/mode/mumps.d.ts +2 -0
- package/dist/mode/mumps.js +127 -0
- package/dist/mode/nginx.d.ts +2 -0
- package/dist/mode/nginx.js +161 -0
- package/dist/mode/nsis.d.ts +2 -0
- package/dist/mode/nsis.js +78 -0
- package/dist/mode/ntriples.d.ts +2 -0
- package/dist/mode/ntriples.js +139 -0
- package/dist/mode/octave.d.ts +2 -0
- package/dist/mode/octave.js +123 -0
- package/dist/mode/oz.d.ts +2 -0
- package/dist/mode/oz.js +233 -0
- package/dist/mode/pascal.d.ts +2 -0
- package/dist/mode/pascal.js +122 -0
- package/dist/mode/pegjs.d.ts +2 -0
- package/dist/mode/pegjs.js +85 -0
- package/dist/mode/perl.d.ts +2 -0
- package/dist/mode/perl.js +818 -0
- package/dist/mode/pig.d.ts +2 -0
- package/dist/mode/pig.js +147 -0
- package/dist/mode/powershell.d.ts +2 -0
- package/dist/mode/powershell.js +379 -0
- package/dist/mode/properties.d.ts +2 -0
- package/dist/mode/properties.js +60 -0
- package/dist/mode/protobuf.d.ts +2 -0
- package/dist/mode/protobuf.js +55 -0
- package/dist/mode/pug.d.ts +2 -0
- package/dist/mode/pug.js +502 -0
- package/dist/mode/puppet.d.ts +2 -0
- package/dist/mode/puppet.js +203 -0
- package/dist/mode/python.d.ts +3 -0
- package/dist/mode/python.js +388 -0
- package/dist/mode/q.d.ts +2 -0
- package/dist/mode/q.js +124 -0
- package/dist/mode/r.d.ts +2 -0
- package/dist/mode/r.js +172 -0
- package/dist/mode/rpm.d.ts +3 -0
- package/dist/mode/rpm.js +88 -0
- package/dist/mode/ruby.d.ts +2 -0
- package/dist/mode/ruby.js +287 -0
- package/dist/mode/rust.d.ts +2 -0
- package/dist/mode/rust.js +54 -0
- package/dist/mode/sas.d.ts +2 -0
- package/dist/mode/sas.js +266 -0
- package/dist/mode/sass.d.ts +2 -0
- package/dist/mode/sass.js +427 -0
- package/dist/mode/scheme.d.ts +2 -0
- package/dist/mode/scheme.js +261 -0
- package/dist/mode/shell.d.ts +2 -0
- package/dist/mode/shell.js +146 -0
- package/dist/mode/sieve.d.ts +2 -0
- package/dist/mode/sieve.js +176 -0
- package/dist/mode/simple-mode.d.ts +14 -0
- package/dist/mode/simple-mode.js +136 -0
- package/dist/mode/smalltalk.d.ts +2 -0
- package/dist/mode/smalltalk.js +151 -0
- package/dist/mode/solr.d.ts +2 -0
- package/dist/mode/solr.js +78 -0
- package/dist/mode/sparql.d.ts +2 -0
- package/dist/mode/sparql.js +169 -0
- package/dist/mode/spreadsheet.d.ts +2 -0
- package/dist/mode/spreadsheet.js +96 -0
- package/dist/mode/sql.d.ts +27 -0
- package/dist/mode/sql.js +481 -0
- package/dist/mode/stex.d.ts +3 -0
- package/dist/mode/stex.js +245 -0
- package/dist/mode/stylus.d.ts +2 -0
- package/dist/mode/stylus.js +747 -0
- package/dist/mode/swift.d.ts +2 -0
- package/dist/mode/swift.js +200 -0
- package/dist/mode/tcl.d.ts +2 -0
- package/dist/mode/tcl.js +123 -0
- package/dist/mode/textile.d.ts +2 -0
- package/dist/mode/textile.js +440 -0
- package/dist/mode/tiddlywiki.d.ts +2 -0
- package/dist/mode/tiddlywiki.js +277 -0
- package/dist/mode/tiki.d.ts +2 -0
- package/dist/mode/tiki.js +291 -0
- package/dist/mode/toml.d.ts +2 -0
- package/dist/mode/toml.js +74 -0
- package/dist/mode/troff.d.ts +2 -0
- package/dist/mode/troff.js +63 -0
- package/dist/mode/ttcn-cfg.d.ts +2 -0
- package/dist/mode/ttcn-cfg.js +199 -0
- package/dist/mode/ttcn.d.ts +2 -0
- package/dist/mode/ttcn.js +255 -0
- package/dist/mode/turtle.d.ts +2 -0
- package/dist/mode/turtle.js +145 -0
- package/dist/mode/vb.d.ts +2 -0
- package/dist/mode/vb.js +254 -0
- package/dist/mode/vbscript.d.ts +3 -0
- package/dist/mode/vbscript.js +320 -0
- package/dist/mode/velocity.d.ts +2 -0
- package/dist/mode/velocity.js +184 -0
- package/dist/mode/verilog.d.ts +3 -0
- package/dist/mode/verilog.js +601 -0
- package/dist/mode/vhdl.d.ts +2 -0
- package/dist/mode/vhdl.js +172 -0
- package/dist/mode/wast.d.ts +2 -0
- package/dist/mode/wast.js +119 -0
- package/dist/mode/webidl.d.ts +2 -0
- package/dist/mode/webidl.js +179 -0
- package/dist/mode/xml.d.ts +3 -0
- package/dist/mode/xml.js +397 -0
- package/dist/mode/xquery.d.ts +2 -0
- package/dist/mode/xquery.js +415 -0
- package/dist/mode/yacas.d.ts +2 -0
- package/dist/mode/yacas.js +181 -0
- package/dist/mode/yaml.d.ts +2 -0
- package/dist/mode/yaml.js +101 -0
- package/dist/mode/z80.d.ts +3 -0
- package/dist/mode/z80.js +101 -0
- package/mode/README.md +52 -0
- package/mode/apl.d.ts +2 -0
- package/mode/apl.js +140 -0
- package/mode/asciiarmor.d.ts +2 -0
- package/mode/asciiarmor.js +54 -0
- package/mode/asn1.d.ts +12 -0
- package/mode/asn1.js +190 -0
- package/mode/asterisk.d.ts +2 -0
- package/mode/asterisk.js +186 -0
- package/mode/brainfuck.d.ts +2 -0
- package/mode/brainfuck.js +68 -0
- package/mode/clike.d.ts +35 -0
- package/mode/clike.js +1019 -0
- package/mode/clojure.d.ts +2 -0
- package/mode/clojure.js +272 -0
- package/mode/cmake.d.ts +2 -0
- package/mode/cmake.js +80 -0
- package/mode/cobol.d.ts +2 -0
- package/mode/cobol.js +234 -0
- package/mode/coffeescript.d.ts +2 -0
- package/mode/coffeescript.js +327 -0
- package/mode/commonlisp.d.ts +2 -0
- package/mode/commonlisp.js +107 -0
- package/mode/crystal.d.ts +2 -0
- package/mode/crystal.js +417 -0
- package/mode/css.d.ts +5 -0
- package/mode/css.js +846 -0
- package/mode/cypher.d.ts +2 -0
- package/mode/cypher.js +120 -0
- package/mode/d.d.ts +2 -0
- package/mode/d.js +203 -0
- package/mode/diff.d.ts +2 -0
- package/mode/diff.js +29 -0
- package/mode/dockerfile.d.ts +2 -0
- package/mode/dockerfile.js +198 -0
- package/mode/dtd.d.ts +2 -0
- package/mode/dtd.js +120 -0
- package/mode/dylan.d.ts +2 -0
- package/mode/dylan.js +336 -0
- package/mode/ebnf.d.ts +2 -0
- package/mode/ebnf.js +149 -0
- package/mode/ecl.d.ts +2 -0
- package/mode/ecl.js +188 -0
- package/mode/eiffel.d.ts +2 -0
- package/mode/eiffel.js +145 -0
- package/mode/elm.d.ts +2 -0
- package/mode/elm.js +228 -0
- package/mode/erlang.d.ts +2 -0
- package/mode/erlang.js +580 -0
- package/mode/factor.d.ts +2 -0
- package/mode/factor.js +63 -0
- package/mode/fcl.d.ts +2 -0
- package/mode/fcl.js +153 -0
- package/mode/forth.d.ts +2 -0
- package/mode/forth.js +162 -0
- package/mode/fortran.d.ts +2 -0
- package/mode/fortran.js +171 -0
- package/mode/gas.d.ts +3 -0
- package/mode/gas.js +342 -0
- package/mode/gherkin.d.ts +2 -0
- package/mode/gherkin.js +146 -0
- package/mode/go.d.ts +2 -0
- package/mode/go.js +163 -0
- package/mode/groovy.d.ts +2 -0
- package/mode/groovy.js +226 -0
- package/mode/haskell.d.ts +2 -0
- package/mode/haskell.js +238 -0
- package/mode/haxe.d.ts +3 -0
- package/mode/haxe.js +490 -0
- package/mode/http.d.ts +2 -0
- package/mode/http.js +87 -0
- package/mode/idl.d.ts +2 -0
- package/mode/idl.js +274 -0
- package/mode/javascript.d.ts +5 -0
- package/mode/javascript.js +922 -0
- package/mode/jinja2.d.ts +2 -0
- package/mode/jinja2.js +170 -0
- package/mode/julia.d.ts +2 -0
- package/mode/julia.js +367 -0
- package/mode/livescript.d.ts +2 -0
- package/mode/livescript.js +257 -0
- package/mode/lua.d.ts +2 -0
- package/mode/lua.js +135 -0
- package/mode/mathematica.d.ts +2 -0
- package/mode/mathematica.js +153 -0
- package/mode/mbox.d.ts +2 -0
- package/mode/mbox.js +114 -0
- package/mode/mirc.d.ts +2 -0
- package/mode/mirc.js +174 -0
- package/mode/mllike.d.ts +4 -0
- package/mode/mllike.js +346 -0
- package/mode/modelica.d.ts +2 -0
- package/mode/modelica.js +190 -0
- package/mode/mscgen.d.ts +4 -0
- package/mode/mscgen.js +147 -0
- package/mode/mumps.d.ts +2 -0
- package/mode/mumps.js +127 -0
- package/mode/nginx.d.ts +2 -0
- package/mode/nginx.js +161 -0
- package/mode/nsis.d.ts +2 -0
- package/mode/nsis.js +78 -0
- package/mode/ntriples.d.ts +2 -0
- package/mode/ntriples.js +139 -0
- package/mode/octave.d.ts +2 -0
- package/mode/octave.js +123 -0
- package/mode/oz.d.ts +2 -0
- package/mode/oz.js +233 -0
- package/mode/pascal.d.ts +2 -0
- package/mode/pascal.js +122 -0
- package/mode/pegjs.d.ts +2 -0
- package/mode/pegjs.js +85 -0
- package/mode/perl.d.ts +2 -0
- package/mode/perl.js +818 -0
- package/mode/pig.d.ts +2 -0
- package/mode/pig.js +147 -0
- package/mode/powershell.d.ts +2 -0
- package/mode/powershell.js +379 -0
- package/mode/properties.d.ts +2 -0
- package/mode/properties.js +60 -0
- package/mode/protobuf.d.ts +2 -0
- package/mode/protobuf.js +55 -0
- package/mode/pug.d.ts +2 -0
- package/mode/pug.js +502 -0
- package/mode/puppet.d.ts +2 -0
- package/mode/puppet.js +203 -0
- package/mode/python.d.ts +3 -0
- package/mode/python.js +388 -0
- package/mode/q.d.ts +2 -0
- package/mode/q.js +124 -0
- package/mode/r.d.ts +2 -0
- package/mode/r.js +172 -0
- package/mode/rpm.d.ts +3 -0
- package/mode/rpm.js +88 -0
- package/mode/ruby.d.ts +2 -0
- package/mode/ruby.js +287 -0
- package/mode/rust.d.ts +2 -0
- package/mode/rust.js +54 -0
- package/mode/sas.d.ts +2 -0
- package/mode/sas.js +266 -0
- package/mode/sass.d.ts +2 -0
- package/mode/sass.js +427 -0
- package/mode/scheme.d.ts +2 -0
- package/mode/scheme.js +261 -0
- package/mode/shell.d.ts +2 -0
- package/mode/shell.js +146 -0
- package/mode/sieve.d.ts +2 -0
- package/mode/sieve.js +176 -0
- package/mode/simple-mode.d.ts +14 -0
- package/mode/simple-mode.js +136 -0
- package/mode/smalltalk.d.ts +2 -0
- package/mode/smalltalk.js +151 -0
- package/mode/solr.d.ts +2 -0
- package/mode/solr.js +78 -0
- package/mode/sparql.d.ts +2 -0
- package/mode/sparql.js +169 -0
- package/mode/spreadsheet.d.ts +2 -0
- package/mode/spreadsheet.js +96 -0
- package/mode/sql.d.ts +27 -0
- package/mode/sql.js +481 -0
- package/mode/stex.d.ts +3 -0
- package/mode/stex.js +245 -0
- package/mode/stylus.d.ts +2 -0
- package/mode/stylus.js +747 -0
- package/mode/swift.d.ts +2 -0
- package/mode/swift.js +200 -0
- package/mode/tcl.d.ts +2 -0
- package/mode/tcl.js +123 -0
- package/mode/textile.d.ts +2 -0
- package/mode/textile.js +440 -0
- package/mode/tiddlywiki.d.ts +2 -0
- package/mode/tiddlywiki.js +277 -0
- package/mode/tiki.d.ts +2 -0
- package/mode/tiki.js +291 -0
- package/mode/toml.d.ts +2 -0
- package/mode/toml.js +74 -0
- package/mode/troff.d.ts +2 -0
- package/mode/troff.js +63 -0
- package/mode/ttcn-cfg.d.ts +2 -0
- package/mode/ttcn-cfg.js +199 -0
- package/mode/ttcn.d.ts +2 -0
- package/mode/ttcn.js +255 -0
- package/mode/turtle.d.ts +2 -0
- package/mode/turtle.js +145 -0
- package/mode/vb.d.ts +2 -0
- package/mode/vb.js +254 -0
- package/mode/vbscript.d.ts +3 -0
- package/mode/vbscript.js +320 -0
- package/mode/velocity.d.ts +2 -0
- package/mode/velocity.js +184 -0
- package/mode/verilog.d.ts +3 -0
- package/mode/verilog.js +601 -0
- package/mode/vhdl.d.ts +2 -0
- package/mode/vhdl.js +172 -0
- package/mode/wast.d.ts +2 -0
- package/mode/wast.js +119 -0
- package/mode/webidl.d.ts +2 -0
- package/mode/webidl.js +179 -0
- package/mode/xml.d.ts +3 -0
- package/mode/xml.js +397 -0
- package/mode/xquery.d.ts +2 -0
- package/mode/xquery.js +415 -0
- package/mode/yacas.d.ts +2 -0
- package/mode/yacas.js +181 -0
- package/mode/yaml.d.ts +2 -0
- package/mode/yaml.js +101 -0
- package/mode/z80.d.ts +3 -0
- package/mode/z80.js +101 -0
- package/package.json +37 -3
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export function simpleMode(states) {
|
|
2
|
+
ensureState(states, "start");
|
|
3
|
+
var states_ = {}, meta = states.languageData || {}, hasIndentation = false;
|
|
4
|
+
for (var state in states) if (state != meta && states.hasOwnProperty(state)) {
|
|
5
|
+
var list = states_[state] = [], orig = states[state];
|
|
6
|
+
for (var i = 0; i < orig.length; i++) {
|
|
7
|
+
var data = orig[i];
|
|
8
|
+
list.push(new Rule(data, states));
|
|
9
|
+
if (data.indent || data.dedent) hasIndentation = true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
name: meta.name,
|
|
14
|
+
startState: function() {
|
|
15
|
+
return {state: "start", pending: null, indent: hasIndentation ? [] : null};
|
|
16
|
+
},
|
|
17
|
+
copyState: function(state) {
|
|
18
|
+
var s = {state: state.state, pending: state.pending, indent: state.indent && state.indent.slice(0)};
|
|
19
|
+
if (state.stack)
|
|
20
|
+
s.stack = state.stack.slice(0);
|
|
21
|
+
return s;
|
|
22
|
+
},
|
|
23
|
+
token: tokenFunction(states_),
|
|
24
|
+
indent: indentFunction(states_, meta),
|
|
25
|
+
mergeTokens: meta.mergeTokens,
|
|
26
|
+
languageData: meta
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
function ensureState(states, name) {
|
|
31
|
+
if (!states.hasOwnProperty(name))
|
|
32
|
+
throw new Error("Undefined state " + name + " in simple mode");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toRegex(val, caret) {
|
|
36
|
+
if (!val) return /(?:)/;
|
|
37
|
+
var flags = "";
|
|
38
|
+
if (val instanceof RegExp) {
|
|
39
|
+
if (val.ignoreCase) flags = "i";
|
|
40
|
+
if (val.unicode) flags += "u";
|
|
41
|
+
val = val.source;
|
|
42
|
+
} else {
|
|
43
|
+
val = String(val);
|
|
44
|
+
}
|
|
45
|
+
return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function asToken(val) {
|
|
49
|
+
if (!val) return null;
|
|
50
|
+
if (val.apply) return val
|
|
51
|
+
if (typeof val == "string") return val.replace(/\./g, " ");
|
|
52
|
+
var result = [];
|
|
53
|
+
for (var i = 0; i < val.length; i++)
|
|
54
|
+
result.push(val[i] && val[i].replace(/\./g, " "));
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function Rule(data, states) {
|
|
59
|
+
if (data.next || data.push) ensureState(states, data.next || data.push);
|
|
60
|
+
this.regex = toRegex(data.regex);
|
|
61
|
+
this.token = asToken(data.token);
|
|
62
|
+
this.data = data;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function tokenFunction(states) {
|
|
66
|
+
return function(stream, state) {
|
|
67
|
+
if (state.pending) {
|
|
68
|
+
var pend = state.pending.shift();
|
|
69
|
+
if (state.pending.length == 0) state.pending = null;
|
|
70
|
+
stream.pos += pend.text.length;
|
|
71
|
+
return pend.token;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
var curState = states[state.state];
|
|
75
|
+
for (var i = 0; i < curState.length; i++) {
|
|
76
|
+
var rule = curState[i];
|
|
77
|
+
var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex);
|
|
78
|
+
if (matches) {
|
|
79
|
+
if (rule.data.next) {
|
|
80
|
+
state.state = rule.data.next;
|
|
81
|
+
} else if (rule.data.push) {
|
|
82
|
+
(state.stack || (state.stack = [])).push(state.state);
|
|
83
|
+
state.state = rule.data.push;
|
|
84
|
+
} else if (rule.data.pop && state.stack && state.stack.length) {
|
|
85
|
+
state.state = state.stack.pop();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (rule.data.indent)
|
|
89
|
+
state.indent.push(stream.indentation() + stream.indentUnit);
|
|
90
|
+
if (rule.data.dedent)
|
|
91
|
+
state.indent.pop();
|
|
92
|
+
var token = rule.token
|
|
93
|
+
if (token && token.apply) token = token(matches)
|
|
94
|
+
if (matches.length > 2 && rule.token && typeof rule.token != "string") {
|
|
95
|
+
state.pending = [];
|
|
96
|
+
for (var j = 2; j < matches.length; j++)
|
|
97
|
+
if (matches[j])
|
|
98
|
+
state.pending.push({text: matches[j], token: rule.token[j - 1]});
|
|
99
|
+
stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
|
|
100
|
+
return token[0];
|
|
101
|
+
} else if (token && token.join) {
|
|
102
|
+
return token[0];
|
|
103
|
+
} else {
|
|
104
|
+
return token;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
stream.next();
|
|
109
|
+
return null;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function indentFunction(states, meta) {
|
|
114
|
+
return function(state, textAfter) {
|
|
115
|
+
if (state.indent == null || meta.dontIndentStates && meta.dontIndentStates.indexOf(state.state) > -1)
|
|
116
|
+
return null
|
|
117
|
+
|
|
118
|
+
var pos = state.indent.length - 1, rules = states[state.state];
|
|
119
|
+
scan: for (;;) {
|
|
120
|
+
for (var i = 0; i < rules.length; i++) {
|
|
121
|
+
var rule = rules[i];
|
|
122
|
+
if (rule.data.dedent && rule.data.dedentIfLineStart !== false) {
|
|
123
|
+
var m = rule.regex.exec(textAfter);
|
|
124
|
+
if (m && m[0]) {
|
|
125
|
+
pos--;
|
|
126
|
+
if (rule.next || rule.push) rules = states[rule.next || rule.push];
|
|
127
|
+
textAfter = textAfter.slice(m[0].length);
|
|
128
|
+
continue scan;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return pos < 0 ? 0 : state.indent[pos];
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var specialChars = /[+\-\/\\*~<>=@%|&?!.,:;^]/;
|
|
2
|
+
var keywords = /true|false|nil|self|super|thisContext/;
|
|
3
|
+
|
|
4
|
+
var Context = function(tokenizer, parent) {
|
|
5
|
+
this.next = tokenizer;
|
|
6
|
+
this.parent = parent;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
var Token = function(name, context, eos) {
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.context = context;
|
|
12
|
+
this.eos = eos;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var State = function() {
|
|
16
|
+
this.context = new Context(next, null);
|
|
17
|
+
this.expectVariable = true;
|
|
18
|
+
this.indentation = 0;
|
|
19
|
+
this.userIndentationDelta = 0;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
State.prototype.userIndent = function(indentation, indentUnit) {
|
|
23
|
+
this.userIndentationDelta = indentation > 0 ? (indentation / indentUnit - this.indentation) : 0;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
var next = function(stream, context, state) {
|
|
27
|
+
var token = new Token(null, context, false);
|
|
28
|
+
var aChar = stream.next();
|
|
29
|
+
|
|
30
|
+
if (aChar === '"') {
|
|
31
|
+
token = nextComment(stream, new Context(nextComment, context));
|
|
32
|
+
|
|
33
|
+
} else if (aChar === '\'') {
|
|
34
|
+
token = nextString(stream, new Context(nextString, context));
|
|
35
|
+
|
|
36
|
+
} else if (aChar === '#') {
|
|
37
|
+
if (stream.peek() === '\'') {
|
|
38
|
+
stream.next();
|
|
39
|
+
token = nextSymbol(stream, new Context(nextSymbol, context));
|
|
40
|
+
} else {
|
|
41
|
+
if (stream.eatWhile(/[^\s.{}\[\]()]/))
|
|
42
|
+
token.name = 'string.special';
|
|
43
|
+
else
|
|
44
|
+
token.name = 'meta';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
} else if (aChar === '$') {
|
|
48
|
+
if (stream.next() === '<') {
|
|
49
|
+
stream.eatWhile(/[^\s>]/);
|
|
50
|
+
stream.next();
|
|
51
|
+
}
|
|
52
|
+
token.name = 'string.special';
|
|
53
|
+
|
|
54
|
+
} else if (aChar === '|' && state.expectVariable) {
|
|
55
|
+
token.context = new Context(nextTemporaries, context);
|
|
56
|
+
|
|
57
|
+
} else if (/[\[\]{}()]/.test(aChar)) {
|
|
58
|
+
token.name = 'bracket';
|
|
59
|
+
token.eos = /[\[{(]/.test(aChar);
|
|
60
|
+
|
|
61
|
+
if (aChar === '[') {
|
|
62
|
+
state.indentation++;
|
|
63
|
+
} else if (aChar === ']') {
|
|
64
|
+
state.indentation = Math.max(0, state.indentation - 1);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
} else if (specialChars.test(aChar)) {
|
|
68
|
+
stream.eatWhile(specialChars);
|
|
69
|
+
token.name = 'operator';
|
|
70
|
+
token.eos = aChar !== ';'; // ; cascaded message expression
|
|
71
|
+
|
|
72
|
+
} else if (/\d/.test(aChar)) {
|
|
73
|
+
stream.eatWhile(/[\w\d]/);
|
|
74
|
+
token.name = 'number';
|
|
75
|
+
|
|
76
|
+
} else if (/[\w_]/.test(aChar)) {
|
|
77
|
+
stream.eatWhile(/[\w\d_]/);
|
|
78
|
+
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
|
|
79
|
+
|
|
80
|
+
} else {
|
|
81
|
+
token.eos = state.expectVariable;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return token;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var nextComment = function(stream, context) {
|
|
88
|
+
stream.eatWhile(/[^"]/);
|
|
89
|
+
return new Token('comment', stream.eat('"') ? context.parent : context, true);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var nextString = function(stream, context) {
|
|
93
|
+
stream.eatWhile(/[^']/);
|
|
94
|
+
return new Token('string', stream.eat('\'') ? context.parent : context, false);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
var nextSymbol = function(stream, context) {
|
|
98
|
+
stream.eatWhile(/[^']/);
|
|
99
|
+
return new Token('string.special', stream.eat('\'') ? context.parent : context, false);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
var nextTemporaries = function(stream, context) {
|
|
103
|
+
var token = new Token(null, context, false);
|
|
104
|
+
var aChar = stream.next();
|
|
105
|
+
|
|
106
|
+
if (aChar === '|') {
|
|
107
|
+
token.context = context.parent;
|
|
108
|
+
token.eos = true;
|
|
109
|
+
|
|
110
|
+
} else {
|
|
111
|
+
stream.eatWhile(/[^|]/);
|
|
112
|
+
token.name = 'variable';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return token;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const smalltalk = {
|
|
119
|
+
name: "smalltalk",
|
|
120
|
+
|
|
121
|
+
startState: function() {
|
|
122
|
+
return new State;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
token: function(stream, state) {
|
|
126
|
+
state.userIndent(stream.indentation(), stream.indentUnit);
|
|
127
|
+
|
|
128
|
+
if (stream.eatSpace()) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
var token = state.context.next(stream, state.context, state);
|
|
133
|
+
state.context = token.context;
|
|
134
|
+
state.expectVariable = token.eos;
|
|
135
|
+
|
|
136
|
+
return token.name;
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
blankLine: function(state, indentUnit) {
|
|
140
|
+
state.userIndent(0, indentUnit);
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
indent: function(state, textAfter, cx) {
|
|
144
|
+
var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
|
|
145
|
+
return (state.indentation + i) * cx.unit;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
languageData: {
|
|
149
|
+
indentOnInput: /^\s*\]$/
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var isStringChar = /[^\s\|\!\+\-\*\?\~\^\&\:\(\)\[\]\{\}\"\\]/;
|
|
2
|
+
var isOperatorChar = /[\|\!\+\-\*\?\~\^\&]/;
|
|
3
|
+
var isOperatorString = /^(OR|AND|NOT|TO)$/;
|
|
4
|
+
|
|
5
|
+
function isNumber(word) {
|
|
6
|
+
return parseFloat(word).toString() === word;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function tokenString(quote) {
|
|
10
|
+
return function(stream, state) {
|
|
11
|
+
var escaped = false, next;
|
|
12
|
+
while ((next = stream.next()) != null) {
|
|
13
|
+
if (next == quote && !escaped) break;
|
|
14
|
+
escaped = !escaped && next == "\\";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!escaped) state.tokenize = tokenBase;
|
|
18
|
+
return "string";
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function tokenOperator(operator) {
|
|
23
|
+
return function(stream, state) {
|
|
24
|
+
if (operator == "|")
|
|
25
|
+
stream.eat(/\|/);
|
|
26
|
+
else if (operator == "&")
|
|
27
|
+
stream.eat(/\&/);
|
|
28
|
+
|
|
29
|
+
state.tokenize = tokenBase;
|
|
30
|
+
return "operator";
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function tokenWord(ch) {
|
|
35
|
+
return function(stream, state) {
|
|
36
|
+
var word = ch;
|
|
37
|
+
while ((ch = stream.peek()) && ch.match(isStringChar) != null) {
|
|
38
|
+
word += stream.next();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
state.tokenize = tokenBase;
|
|
42
|
+
if (isOperatorString.test(word))
|
|
43
|
+
return "operator";
|
|
44
|
+
else if (isNumber(word))
|
|
45
|
+
return "number";
|
|
46
|
+
else if (stream.peek() == ":")
|
|
47
|
+
return "propertyName";
|
|
48
|
+
else
|
|
49
|
+
return "string";
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function tokenBase(stream, state) {
|
|
54
|
+
var ch = stream.next();
|
|
55
|
+
if (ch == '"')
|
|
56
|
+
state.tokenize = tokenString(ch);
|
|
57
|
+
else if (isOperatorChar.test(ch))
|
|
58
|
+
state.tokenize = tokenOperator(ch);
|
|
59
|
+
else if (isStringChar.test(ch))
|
|
60
|
+
state.tokenize = tokenWord(ch);
|
|
61
|
+
|
|
62
|
+
return (state.tokenize != tokenBase) ? state.tokenize(stream, state) : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export const solr = {
|
|
66
|
+
name: "solr",
|
|
67
|
+
|
|
68
|
+
startState: function() {
|
|
69
|
+
return {
|
|
70
|
+
tokenize: tokenBase
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
token: function(stream, state) {
|
|
75
|
+
if (stream.eatSpace()) return null;
|
|
76
|
+
return state.tokenize(stream, state);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var curPunc;
|
|
2
|
+
|
|
3
|
+
function wordRegexp(words) {
|
|
4
|
+
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
|
5
|
+
}
|
|
6
|
+
var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
|
|
7
|
+
"iri", "uri", "bnode", "count", "sum", "min", "max", "avg", "sample",
|
|
8
|
+
"group_concat", "rand", "abs", "ceil", "floor", "round", "concat", "substr", "strlen",
|
|
9
|
+
"replace", "ucase", "lcase", "encode_for_uri", "contains", "strstarts", "strends",
|
|
10
|
+
"strbefore", "strafter", "year", "month", "day", "hours", "minutes", "seconds",
|
|
11
|
+
"timezone", "tz", "now", "uuid", "struuid", "md5", "sha1", "sha256", "sha384",
|
|
12
|
+
"sha512", "coalesce", "if", "strlang", "strdt", "isnumeric", "regex", "exists",
|
|
13
|
+
"isblank", "isliteral", "a", "bind"]);
|
|
14
|
+
var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
|
|
15
|
+
"ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
|
|
16
|
+
"graph", "by", "asc", "desc", "as", "having", "undef", "values", "group",
|
|
17
|
+
"minus", "in", "not", "service", "silent", "using", "insert", "delete", "union",
|
|
18
|
+
"true", "false", "with",
|
|
19
|
+
"data", "copy", "to", "move", "add", "create", "drop", "clear", "load", "into"]);
|
|
20
|
+
var operatorChars = /[*+\-<>=&|\^\/!\?]/;
|
|
21
|
+
var PN_CHARS = "[A-Za-z_\\-0-9]";
|
|
22
|
+
var PREFIX_START = new RegExp("[A-Za-z]");
|
|
23
|
+
var PREFIX_REMAINDER = new RegExp("((" + PN_CHARS + "|\\.)*(" + PN_CHARS + "))?:");
|
|
24
|
+
|
|
25
|
+
function tokenBase(stream, state) {
|
|
26
|
+
var ch = stream.next();
|
|
27
|
+
curPunc = null;
|
|
28
|
+
if (ch == "$" || ch == "?") {
|
|
29
|
+
if(ch == "?" && stream.match(/\s/, false)){
|
|
30
|
+
return "operator";
|
|
31
|
+
}
|
|
32
|
+
stream.match(/^[A-Za-z0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][A-Za-z0-9_\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]*/);
|
|
33
|
+
return "variableName.local";
|
|
34
|
+
}
|
|
35
|
+
else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
|
|
36
|
+
stream.match(/^[^\s\u00a0>]*>?/);
|
|
37
|
+
return "atom";
|
|
38
|
+
}
|
|
39
|
+
else if (ch == "\"" || ch == "'") {
|
|
40
|
+
state.tokenize = tokenLiteral(ch);
|
|
41
|
+
return state.tokenize(stream, state);
|
|
42
|
+
}
|
|
43
|
+
else if (/[{}\(\),\.;\[\]]/.test(ch)) {
|
|
44
|
+
curPunc = ch;
|
|
45
|
+
return "bracket";
|
|
46
|
+
}
|
|
47
|
+
else if (ch == "#") {
|
|
48
|
+
stream.skipToEnd();
|
|
49
|
+
return "comment";
|
|
50
|
+
}
|
|
51
|
+
else if (operatorChars.test(ch)) {
|
|
52
|
+
return "operator";
|
|
53
|
+
}
|
|
54
|
+
else if (ch == ":") {
|
|
55
|
+
eatPnLocal(stream);
|
|
56
|
+
return "atom";
|
|
57
|
+
}
|
|
58
|
+
else if (ch == "@") {
|
|
59
|
+
stream.eatWhile(/[a-z\d\-]/i);
|
|
60
|
+
return "meta";
|
|
61
|
+
}
|
|
62
|
+
else if (PREFIX_START.test(ch) && stream.match(PREFIX_REMAINDER)) {
|
|
63
|
+
eatPnLocal(stream);
|
|
64
|
+
return "atom";
|
|
65
|
+
}
|
|
66
|
+
stream.eatWhile(/[_\w\d]/);
|
|
67
|
+
var word = stream.current();
|
|
68
|
+
if (ops.test(word))
|
|
69
|
+
return "builtin";
|
|
70
|
+
else if (keywords.test(word))
|
|
71
|
+
return "keyword";
|
|
72
|
+
else
|
|
73
|
+
return "variable";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function eatPnLocal(stream) {
|
|
77
|
+
stream.match(/(\.(?=[\w_\-\\%])|[:\w_-]|\\[-\\_~.!$&'()*+,;=/?#@%]|%[a-f\d][a-f\d])+/i);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function tokenLiteral(quote) {
|
|
81
|
+
return function(stream, state) {
|
|
82
|
+
var escaped = false, ch;
|
|
83
|
+
while ((ch = stream.next()) != null) {
|
|
84
|
+
if (ch == quote && !escaped) {
|
|
85
|
+
state.tokenize = tokenBase;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
escaped = !escaped && ch == "\\";
|
|
89
|
+
}
|
|
90
|
+
return "string";
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function pushContext(state, type, col) {
|
|
95
|
+
state.context = {prev: state.context, indent: state.indent, col: col, type: type};
|
|
96
|
+
}
|
|
97
|
+
function popContext(state) {
|
|
98
|
+
state.indent = state.context.indent;
|
|
99
|
+
state.context = state.context.prev;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const sparql = {
|
|
103
|
+
name: "sparql",
|
|
104
|
+
|
|
105
|
+
startState: function() {
|
|
106
|
+
return {tokenize: tokenBase,
|
|
107
|
+
context: null,
|
|
108
|
+
indent: 0,
|
|
109
|
+
col: 0};
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
token: function(stream, state) {
|
|
113
|
+
if (stream.sol()) {
|
|
114
|
+
if (state.context && state.context.align == null) state.context.align = false;
|
|
115
|
+
state.indent = stream.indentation();
|
|
116
|
+
}
|
|
117
|
+
if (stream.eatSpace()) return null;
|
|
118
|
+
var style = state.tokenize(stream, state);
|
|
119
|
+
|
|
120
|
+
if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
|
|
121
|
+
state.context.align = true;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (curPunc == "(") pushContext(state, ")", stream.column());
|
|
125
|
+
else if (curPunc == "[") pushContext(state, "]", stream.column());
|
|
126
|
+
else if (curPunc == "{") pushContext(state, "}", stream.column());
|
|
127
|
+
else if (/[\]\}\)]/.test(curPunc)) {
|
|
128
|
+
while (state.context && state.context.type == "pattern") popContext(state);
|
|
129
|
+
if (state.context && curPunc == state.context.type) {
|
|
130
|
+
popContext(state);
|
|
131
|
+
if (curPunc == "}" && state.context && state.context.type == "pattern")
|
|
132
|
+
popContext(state);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
|
|
136
|
+
else if (/atom|string|variable/.test(style) && state.context) {
|
|
137
|
+
if (/[\}\]]/.test(state.context.type))
|
|
138
|
+
pushContext(state, "pattern", stream.column());
|
|
139
|
+
else if (state.context.type == "pattern" && !state.context.align) {
|
|
140
|
+
state.context.align = true;
|
|
141
|
+
state.context.col = stream.column();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return style;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
indent: function(state, textAfter, cx) {
|
|
149
|
+
var firstChar = textAfter && textAfter.charAt(0);
|
|
150
|
+
var context = state.context;
|
|
151
|
+
if (/[\]\}]/.test(firstChar))
|
|
152
|
+
while (context && context.type == "pattern") context = context.prev;
|
|
153
|
+
|
|
154
|
+
var closing = context && firstChar == context.type;
|
|
155
|
+
if (!context)
|
|
156
|
+
return 0;
|
|
157
|
+
else if (context.type == "pattern")
|
|
158
|
+
return context.col;
|
|
159
|
+
else if (context.align)
|
|
160
|
+
return context.col + (closing ? 0 : 1);
|
|
161
|
+
else
|
|
162
|
+
return context.indent + (closing ? 0 : cx.unit);
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
languageData: {
|
|
166
|
+
commentTokens: {line: "#"}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export const spreadsheet = {
|
|
2
|
+
name: "spreadsheet",
|
|
3
|
+
|
|
4
|
+
startState: function () {
|
|
5
|
+
return {
|
|
6
|
+
stringType: null,
|
|
7
|
+
stack: []
|
|
8
|
+
};
|
|
9
|
+
},
|
|
10
|
+
token: function (stream, state) {
|
|
11
|
+
if (!stream) return;
|
|
12
|
+
|
|
13
|
+
//check for state changes
|
|
14
|
+
if (state.stack.length === 0) {
|
|
15
|
+
//strings
|
|
16
|
+
if ((stream.peek() == '"') || (stream.peek() == "'")) {
|
|
17
|
+
state.stringType = stream.peek();
|
|
18
|
+
stream.next(); // Skip quote
|
|
19
|
+
state.stack.unshift("string");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
//return state
|
|
24
|
+
//stack has
|
|
25
|
+
switch (state.stack[0]) {
|
|
26
|
+
case "string":
|
|
27
|
+
while (state.stack[0] === "string" && !stream.eol()) {
|
|
28
|
+
if (stream.peek() === state.stringType) {
|
|
29
|
+
stream.next(); // Skip quote
|
|
30
|
+
state.stack.shift(); // Clear flag
|
|
31
|
+
} else if (stream.peek() === "\\") {
|
|
32
|
+
stream.next();
|
|
33
|
+
stream.next();
|
|
34
|
+
} else {
|
|
35
|
+
stream.match(/^.[^\\\"\']*/);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return "string";
|
|
39
|
+
|
|
40
|
+
case "characterClass":
|
|
41
|
+
while (state.stack[0] === "characterClass" && !stream.eol()) {
|
|
42
|
+
if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./)))
|
|
43
|
+
state.stack.shift();
|
|
44
|
+
}
|
|
45
|
+
return "operator";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var peek = stream.peek();
|
|
49
|
+
|
|
50
|
+
//no stack
|
|
51
|
+
switch (peek) {
|
|
52
|
+
case "[":
|
|
53
|
+
stream.next();
|
|
54
|
+
state.stack.unshift("characterClass");
|
|
55
|
+
return "bracket";
|
|
56
|
+
case ":":
|
|
57
|
+
stream.next();
|
|
58
|
+
return "operator";
|
|
59
|
+
case "\\":
|
|
60
|
+
if (stream.match(/\\[a-z]+/)) return "string.special";
|
|
61
|
+
else {
|
|
62
|
+
stream.next();
|
|
63
|
+
return "atom";
|
|
64
|
+
}
|
|
65
|
+
case ".":
|
|
66
|
+
case ",":
|
|
67
|
+
case ";":
|
|
68
|
+
case "*":
|
|
69
|
+
case "-":
|
|
70
|
+
case "+":
|
|
71
|
+
case "^":
|
|
72
|
+
case "<":
|
|
73
|
+
case "/":
|
|
74
|
+
case "=":
|
|
75
|
+
stream.next();
|
|
76
|
+
return "atom";
|
|
77
|
+
case "$":
|
|
78
|
+
stream.next();
|
|
79
|
+
return "builtin";
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (stream.match(/\d+/)) {
|
|
83
|
+
if (stream.match(/^\w+/)) return "error";
|
|
84
|
+
return "number";
|
|
85
|
+
} else if (stream.match(/^[a-zA-Z_]\w*/)) {
|
|
86
|
+
if (stream.match(/(?=[\(.])/, false)) return "keyword";
|
|
87
|
+
return "variable";
|
|
88
|
+
} else if (["[", "]", "(", ")", "{", "}"].indexOf(peek) != -1) {
|
|
89
|
+
stream.next();
|
|
90
|
+
return "bracket";
|
|
91
|
+
} else if (!stream.eatSpace()) {
|
|
92
|
+
stream.next();
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {StreamParser} from "@quirekit/cm-language"
|
|
2
|
+
export declare function sql(conf: {
|
|
3
|
+
client?: {[word: string]: any},
|
|
4
|
+
atoms?: {[word: string]: any},
|
|
5
|
+
builtin?: {[word: string]: any},
|
|
6
|
+
keywords?: {[word: string]: any},
|
|
7
|
+
operatorChars?: RegExp,
|
|
8
|
+
support?: {[word: string]: any},
|
|
9
|
+
hooks?: {[hook: string]: any},
|
|
10
|
+
dateSQL?: {[word: string]: any},
|
|
11
|
+
backslashStringEscapes?: boolean,
|
|
12
|
+
brackets?: RegExp,
|
|
13
|
+
punctuation?: RegExp
|
|
14
|
+
}): StreamParser<unknown>
|
|
15
|
+
export declare const standardSQL: StreamParser<unknown>
|
|
16
|
+
export declare const msSQL: StreamParser<unknown>
|
|
17
|
+
export declare const mySQL: StreamParser<unknown>
|
|
18
|
+
export declare const mariaDB: StreamParser<unknown>
|
|
19
|
+
export declare const sqlite: StreamParser<unknown>
|
|
20
|
+
export declare const cassandra: StreamParser<unknown>
|
|
21
|
+
export declare const plSQL: StreamParser<unknown>
|
|
22
|
+
export declare const hive: StreamParser<unknown>
|
|
23
|
+
export declare const pgSQL: StreamParser<unknown>
|
|
24
|
+
export declare const gql: StreamParser<unknown>
|
|
25
|
+
export declare const gpSQL: StreamParser<unknown>
|
|
26
|
+
export declare const sparkSQL: StreamParser<unknown>
|
|
27
|
+
export declare const esper: StreamParser<unknown>
|