5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("solr", function() {
17
var isStringChar = /[^\s\|\!\+\-\*\?\~\^\&\:\(\)\[\]\{\}\"\\]/;
18
var isOperatorChar = /[\|\!\+\-\*\?\~\^\&]/;
19
var isOperatorString = /^(OR|AND|NOT|TO)$/i;
21
function isNumber(word) {
22
return parseFloat(word).toString() === word;
25
function tokenString(quote) {
26
return function(stream, state) {
27
var escaped = false, next;
28
while ((next = stream.next()) != null) {
29
if (next == quote && !escaped) break;
30
escaped = !escaped && next == "\\";
33
if (!escaped) state.tokenize = tokenBase;
38
function tokenOperator(operator) {
39
return function(stream, state) {
40
var style = "operator";
43
else if (operator == "-")
45
else if (operator == "|")
47
else if (operator == "&")
49
else if (operator == "^")
52
state.tokenize = tokenBase;
57
function tokenWord(ch) {
58
return function(stream, state) {
60
while ((ch = stream.peek()) && ch.match(isStringChar) != null) {
61
word += stream.next();
64
state.tokenize = tokenBase;
65
if (isOperatorString.test(word))
67
else if (isNumber(word))
69
else if (stream.peek() == ":")
76
function tokenBase(stream, state) {
77
var ch = stream.next();
79
state.tokenize = tokenString(ch);
80
else if (isOperatorChar.test(ch))
81
state.tokenize = tokenOperator(ch);
82
else if (isStringChar.test(ch))
83
state.tokenize = tokenWord(ch);
85
return (state.tokenize != tokenBase) ? state.tokenize(stream, state) : null;
89
startState: function() {
95
token: function(stream, state) {
96
if (stream.eatSpace()) return null;
97
return state.tokenize(stream, state);
102
CodeMirror.defineMIME("text/x-solr", "solr");