MCPcopy Create free account
hub / github.com/nwutils/nw-sample-apps / tokenBase

Function tokenBase

mini-code-edit/cm/mode/plsql/plsql.js:20–78  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

18 }
19
20 function tokenBase(stream, state) {
21 var ch = stream.next();
22 // start of string?
23 if (ch == '"' || ch == "'")
24 return chain(stream, state, tokenString(ch));
25 // is it one of the special signs []{}().,;? Seperator?
26 else if (/[\[\]{}\(\),;\.]/.test(ch))
27 return ret(ch);
28 // start of a number value?
29 else if (/\d/.test(ch)) {
30 stream.eatWhile(/[\w\.]/);
31 return ret("number", "number");
32 }
33 // multi line comment or simple operator?
34 else if (ch == "/") {
35 if (stream.eat("*")) {
36 return chain(stream, state, tokenComment);
37 }
38 else {
39 stream.eatWhile(isOperatorChar);
40 return ret("operator", "operator");
41 }
42 }
43 // single line comment or simple operator?
44 else if (ch == "-") {
45 if (stream.eat("-")) {
46 stream.skipToEnd();
47 return ret("comment", "comment");
48 }
49 else {
50 stream.eatWhile(isOperatorChar);
51 return ret("operator", "operator");
52 }
53 }
54 // pl/sql variable?
55 else if (ch == "@" || ch == "$") {
56 stream.eatWhile(/[\w\d\$_]/);
57 return ret("word", "variable");
58 }
59 // is it a operator?
60 else if (isOperatorChar.test(ch)) {
61 stream.eatWhile(isOperatorChar);
62 return ret("operator", "operator");
63 }
64 else {
65 // get the whole word
66 stream.eatWhile(/[\w\$_]/);
67 // is it one of the listed keywords?
68 if (keywords && keywords.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "keyword");
69 // is it one of the listed functions?
70 if (functions && functions.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "builtin");
71 // is it one of the listed types?
72 if (types && types.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "variable-2");
73 // is it one of the listed sqlplus keywords?
74 if (sqlplus && sqlplus.propertyIsEnumerable(stream.current().toLowerCase())) return ret("keyword", "variable-3");
75 // default: just a "word"
76 return ret("word", "plsql-word");
77 }

Callers

nothing calls this directly

Calls 3

chainFunction · 0.70
tokenStringFunction · 0.70
retFunction · 0.70

Tested by

no test coverage detected