LaravelTest
104 строки · 2.6 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("solr", function() {15"use strict";16
17var isStringChar = /[^\s\|\!\+\-\*\?\~\^\&\:\(\)\[\]\{\}\"\\]/;18var isOperatorChar = /[\|\!\+\-\*\?\~\^\&]/;19var isOperatorString = /^(OR|AND|NOT|TO)$/i;20
21function isNumber(word) {22return parseFloat(word).toString() === word;23}24
25function tokenString(quote) {26return function(stream, state) {27var escaped = false, next;28while ((next = stream.next()) != null) {29if (next == quote && !escaped) break;30escaped = !escaped && next == "\\";31}32
33if (!escaped) state.tokenize = tokenBase;34return "string";35};36}37
38function tokenOperator(operator) {39return function(stream, state) {40var style = "operator";41if (operator == "+")42style += " positive";43else if (operator == "-")44style += " negative";45else if (operator == "|")46stream.eat(/\|/);47else if (operator == "&")48stream.eat(/\&/);49else if (operator == "^")50style += " boost";51
52state.tokenize = tokenBase;53return style;54};55}56
57function tokenWord(ch) {58return function(stream, state) {59var word = ch;60while ((ch = stream.peek()) && ch.match(isStringChar) != null) {61word += stream.next();62}63
64state.tokenize = tokenBase;65if (isOperatorString.test(word))66return "operator";67else if (isNumber(word))68return "number";69else if (stream.peek() == ":")70return "field";71else72return "string";73};74}75
76function tokenBase(stream, state) {77var ch = stream.next();78if (ch == '"')79state.tokenize = tokenString(ch);80else if (isOperatorChar.test(ch))81state.tokenize = tokenOperator(ch);82else if (isStringChar.test(ch))83state.tokenize = tokenWord(ch);84
85return (state.tokenize != tokenBase) ? state.tokenize(stream, state) : null;86}87
88return {89startState: function() {90return {91tokenize: tokenBase92};93},94
95token: function(stream, state) {96if (stream.eatSpace()) return null;97return state.tokenize(stream, state);98}99};100});101
102CodeMirror.defineMIME("text/x-solr", "solr");103
104});105