PageSourceSearch

https://learnsqlonline.org/static/js/codemirror/mode/clike/clike.js

js learnsqlonline.org collected 2026-09-26 05:05:17 UTC 11,397 bytes, 302 lines download raw bytes

vendor: 4,693 bytes, lines 1-143
1CodeMirror.defineMode("clike", function(config, parserConfig) {
2  var indentUnit = config.indentUnit,
3      statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
4      dontAlignCalls = parserConfig.dontAlignCalls,
5      keywords = parserConfig.keywords || {},
6      builtin = parserConfig.builtin || {},
7      blockKeywords = parserConfig.blockKeywords || {},
8      atoms = parserConfig.atoms || {},
9      hooks = parserConfig.hooks || {},
10      multiLineStrings = parserConfig.multiLineStrings;
11  var isOperatorChar = /[+\-*&%=<>!?|\/]/;
12
13  var curPunc;
14
15  function tokenBase(stream, state) {
16    var ch = stream.next();
17    if (hooks[ch]) {
18      var result = hooks[ch](stream, state);
19      if (result !== false) return result;
20    }
21    if (ch == '"' || ch == "'") {
22      state.tokenize = tokenString(ch);
23      return state.tokenize(stream, state);
24    }
25    if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
26      curPunc = ch;
27      return null;
28    }
29    if (/\d/.test(ch)) {
30      stream.eatWhile(/[\w\.]/);
31      return "number";
32    }
33    if (ch == "/") {
34      if (stream.eat("*")) {
35        state.tokenize = tokenComment;
36        return tokenComment(stream, state);
37      }
38      if (stream.eat("/")) {
39        stream.skipToEnd();
40        return "comment";
41      }
42    }
43    if (isOperatorChar.test(ch)) {
44      stream.eatWhile(isOperatorChar);
45      return "operator";
46    }
47    stream.eatWhile(/[\w\$_]/);
48    var cur = stream.current();
49    if (keywords.propertyIsEnumerable(cur)) {
50      if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
51      return "keyword";
52    }
53    if (builtin.propertyIsEnumerable(cur)) {
54      if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
55      return "builtin";
56    }
57    if (atoms.propertyIsEnumerable(cur)) return "atom";
58    return "variable";
59  }
60
61  function tokenString(quote) {
62    return function(stream, state) {
63      var escaped = false, next, end = false;
64      while ((next = stream.next()) != null) {
65        if (next == quote && !escaped) {end = true; break;}
66        escaped = !escaped && next == "\\";
67      }
68      if (end || !(escaped || multiLineStrings))
69        state.tokenize = null;
70      return "string";
71    };
72  }
73
74  function tokenComment(stream, state) {
75    var maybeEnd = false, ch;
76    while (ch = stream.next()) {
77      if (ch == "/" && maybeEnd) {
78        state.tokenize = null;
79        break;
80      }
81      maybeEnd = (ch == "*");
82    }
83    return "comment";
84  }
85
86  function Context(indented, column, type, align, prev) {
87    this.indented = indented;
88    this.column = column;
89    this.type = type;
90    this.align = align;
91    this.prev = prev;
92  }
93  function pushContext(state, col, type) {
94    var indent = state.indented;
95    if (state.context && state.context.type == "statement")
96      indent = state.context.indented;
97    return state.context = new Context(indent, col, type, null, state.context);
98  }
99  function popContext(state) {
100    var t = state.context.type;
101    if (t == ")" || t == "]" || t == "}")
102      state.indented = state.context.indented;
103    return state.context = state.context.prev;
104  }
105
106  // Interface
107
108  return {
109    startState: function(basecolumn) {
110      return {
111        tokenize: null,
112        context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
113        indented: 0,
114        startOfLine: true
115      };
116    },
117
118    token: function(stream, state) {
119      var ctx = state.context;
120      if (stream.sol()) {
121        if (ctx.align == null) ctx.align = false;
122        state.indented = stream.indentation();
123        state.startOfLine = true;
124      }
125      if (stream.eatSpace()) return null;
126      curPunc = null;
127      var style = (state.tokenize || tokenBase)(stream, state);
128      if (style == "comment" || style == "meta") return style;
129      if (ctx.align == null) ctx.align = true;
130
131      if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
132      else if (curPunc == "{") pushContext(state, stream.column(), "}");
133      else if (curPunc == "[") pushContext(state, stream.column(), "]");
134      else if (curPunc == "(") pushContext(state, stream.column(), ")");
135      else if (curPunc == "}") {
136        while (ctx.type == "statement") ctx = popContext(state);
137        if (ctx.type == "}") ctx = popContext(state);
138        while (ctx.type == "statement") ctx = popContext(state);
139      }
140      else if (curPunc == ctx.type) popContext(state);
141      else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
142        pushContext(state, stream.column(), "statement");
143      state.startOfLine = false;
144      return style;
145    },
146
147    indent: function(state, textAfter) {
148      if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
149      var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
150      if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
151      var closing = firstChar == ctx.type;
152      if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
153      else if (dontAlignCalls && ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
154      else if (ctx.align) return ctx.column + (closing ? 0 : 1);
155      else return ctx.indented + (closing ? 0 : indentUnit);
156    },
157
158    electricChars: "{}"
159  };
160});
161
162(function() {
163  function words(str) {
164    var obj = {}, words = str.split(" ");
165    for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
166    return obj;
167  }
168  var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
169    "double static else struct entry switch extern typedef float union for unsigned " +
170    "goto while enum void const signed volatile";
171
172  function cppHook(stream, state) {
173    if (!state.startOfLine) return false;
174    for (;;) {
175      if (stream.skipTo("\\")) {
176        stream.next();
177        if (stream.eol()) {
178          state.tokenize = cppHook;
179          break;
180        }
181      } else {
182        stream.skipToEnd();
183        state.tokenize = null;
184        break;
185      }
186    }
187    return "meta";
188  }
189
190  // C#-style strings where "" escapes a quote.
191  function tokenAtString(stream, state) {
192    var next;
193    while ((next = stream.next()) != null) {
194      if (next == '"' && !stream.eat('"')) {
195        state.tokenize = null;
196        break;
197      }
198    }
199    return "string";
200  }
201
202  function mimes(ms, mode) {
203    for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
204  }
205
206  mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], {
207    name: "clike",
208    keywords: words(cKeywords),
209    blockKeywords: words("case do else for if switch while struct"),
210    atoms: words("null"),
211    hooks: {"#": cppHook}
212  });
213  mimes(["text/x-c++src", "text/x-c++hdr"], {
214    name: "clike",
215    keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
216                    "static_cast typeid catch operator template typename class friend private " +
217                    "this using const_cast inline public throw virtual delete mutable protected " +
218                    "wchar_t"),
219    blockKeywords: words("catch class do else finally for if struct switch try while"),
220    atoms: words("true false null"),
221    hooks: {"#": cppHook}
222  });
223  CodeMirror.defineMIME("text/x-java", {
224    name: "clike",
225    keywords: words("abstract assert boolean break byte case catch char class const continue default " + 
226                    "do double else enum extends final finally float for goto if implements import " +
227                    "instanceof int interface long native new package private protected public " +
228                    "return short static strictfp super switch synchronized this throw throws transient " +
229                    "try void volatile while"),
230    blockKeywords: words("catch class do else finally for if switch try while"),
231    atoms: words("true false null"),
232    hooks: {
233      "@": function(stream) {
234        stream.eatWhile(/[\w\$_]/);
235        return "meta";
236      }
237    }
238  });
239  CodeMirror.defineMIME("text/x-csharp", {
240    name: "clike",
241    keywords: words("abstract as base break case catch checked class const continue" + 
242                    " default delegate do else enum event explicit extern finally fixed for" + 
243                    " foreach goto if implicit in interface internal is lock namespace new" + 
244                    " operator out override params private protected public readonly ref return sealed" + 
245                    " sizeof stackalloc static struct switch this throw try typeof unchecked" + 
246                    " unsafe using virtual void volatile while add alias ascending descending dynamic from get" + 
247                    " global group into join let orderby partial remove select set value var yield"),
248    blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
249    builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
250                    " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
251                    " UInt64 bool byte char decimal double short int long object"  +
252                    " sbyte float string ushort uint ulong"),
253    atoms: words("true false null"),
254    hooks: {
255      "@": function(stream, state) {
256        if (stream.eat('"')) {
257          state.tokenize = tokenAtString;
258          return tokenAtString(stream, state);
259        }
260        stream.eatWhile(/[\w\$_]/);
261        return "meta";
262      }
263    }
264  });
265  CodeMirror.defineMIME("text/x-scala", {
266    name: "clike",
267    keywords: words(
268      
269      /* scala */
270      "abstract case catch class def do else extends false final finally for forSome if " +
271      "implicit import lazy match new null object override package private protected return " +
272      "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
273      "<% >: # @ " +
274                    
275      /* package scala */
276      "assert assume require print println printf readLine readBoolean readByte readShort " +
277      "readChar readInt readLong readFloat readDouble " +
278      
279      "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
280      "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
281      "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
282      "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
283      "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
284      
285      /* package java.lang */            
286      "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
287      "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
288      "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
289      "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
290      
291      
292    ),
293    blockKeywords: words("catch class do else finally for forSome if match switch try while"),
294    atoms: words("true false null"),
295    hooks: {
296      "@": function(stream) {
297        stream.eatWhile(/[\w\$_]/);
298        return "meta";
299      }
300    }
301  });
302}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.