summaryrefslogtreecommitdiff
path: root/public/vendor/codemirror/mode/cypher
diff options
context:
space:
mode:
authorWu Cheng-Han2015-05-04 15:53:29 +0800
committerWu Cheng-Han2015-05-04 15:53:29 +0800
commit4b0ca55eb79e963523eb6c8197825e9e8ae904e2 (patch)
tree574f3923af77b37b41dbf1b00bcd7827ef724a28 /public/vendor/codemirror/mode/cypher
parent61eb11d23c65c9e5c493c67d055f785cbec139e2 (diff)
First commit, version 0.2.7
Diffstat (limited to 'public/vendor/codemirror/mode/cypher')
-rwxr-xr-xpublic/vendor/codemirror/mode/cypher/cypher.js146
-rwxr-xr-xpublic/vendor/codemirror/mode/cypher/index.html63
2 files changed, 209 insertions, 0 deletions
diff --git a/public/vendor/codemirror/mode/cypher/cypher.js b/public/vendor/codemirror/mode/cypher/cypher.js
new file mode 100755
index 00000000..9decf307
--- /dev/null
+++ b/public/vendor/codemirror/mode/cypher/cypher.js
@@ -0,0 +1,146 @@
+// CodeMirror, copyright (c) by Marijn Haverbeke and others
+// Distributed under an MIT license: http://codemirror.net/LICENSE
+
+// By the Neo4j Team and contributors.
+// https://github.com/neo4j-contrib/CodeMirror
+
+(function(mod) {
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
+ mod(require("../../lib/codemirror"));
+ else if (typeof define == "function" && define.amd) // AMD
+ define(["../../lib/codemirror"], mod);
+ else // Plain browser env
+ mod(CodeMirror);
+})(function(CodeMirror) {
+ "use strict";
+ var wordRegexp = function(words) {
+ return new RegExp("^(?:" + words.join("|") + ")$", "i");
+ };
+
+ CodeMirror.defineMode("cypher", function(config) {
+ var tokenBase = function(stream/*, state*/) {
+ var ch = stream.next(), curPunc = null;
+ if (ch === "\"" || ch === "'") {
+ stream.match(/.+?["']/);
+ return "string";
+ }
+ if (/[{}\(\),\.;\[\]]/.test(ch)) {
+ curPunc = ch;
+ return "node";
+ } else if (ch === "/" && stream.eat("/")) {
+ stream.skipToEnd();
+ return "comment";
+ } else if (operatorChars.test(ch)) {
+ stream.eatWhile(operatorChars);
+ return null;
+ } else {
+ stream.eatWhile(/[_\w\d]/);
+ if (stream.eat(":")) {
+ stream.eatWhile(/[\w\d_\-]/);
+ return "atom";
+ }
+ var word = stream.current();
+ if (funcs.test(word)) return "builtin";
+ if (preds.test(word)) return "def";
+ if (keywords.test(word)) return "keyword";
+ return "variable";
+ }
+ };
+ var pushContext = function(state, type, col) {
+ return state.context = {
+ prev: state.context,
+ indent: state.indent,
+ col: col,
+ type: type
+ };
+ };
+ var popContext = function(state) {
+ state.indent = state.context.indent;
+ return state.context = state.context.prev;
+ };
+ var indentUnit = config.indentUnit;
+ var curPunc;
+ var funcs = wordRegexp(["abs", "acos", "allShortestPaths", "asin", "atan", "atan2", "avg", "ceil", "coalesce", "collect", "cos", "cot", "count", "degrees", "e", "endnode", "exp", "extract", "filter", "floor", "haversin", "head", "id", "keys", "labels", "last", "left", "length", "log", "log10", "lower", "ltrim", "max", "min", "node", "nodes", "percentileCont", "percentileDisc", "pi", "radians", "rand", "range", "reduce", "rel", "relationship", "relationships", "replace", "right", "round", "rtrim", "shortestPath", "sign", "sin", "split", "sqrt", "startnode", "stdev", "stdevp", "str", "substring", "sum", "tail", "tan", "timestamp", "toFloat", "toInt", "trim", "type", "upper"]);
+ var preds = wordRegexp(["all", "and", "any", "has", "in", "none", "not", "or", "single", "xor"]);
+ var keywords = wordRegexp(["as", "asc", "ascending", "assert", "by", "case", "commit", "constraint", "create", "csv", "cypher", "delete", "desc", "descending", "distinct", "drop", "else", "end", "explain", "false", "fieldterminator", "foreach", "from", "headers", "in", "index", "is", "limit", "load", "match", "merge", "null", "on", "optional", "order", "periodic", "profile", "remove", "return", "scan", "set", "skip", "start", "then", "true", "union", "unique", "unwind", "using", "when", "where", "with"]);
+ var operatorChars = /[*+\-<>=&|~%^]/;
+
+ return {
+ startState: function(/*base*/) {
+ return {
+ tokenize: tokenBase,
+ context: null,
+ indent: 0,
+ col: 0
+ };
+ },
+ token: function(stream, state) {
+ if (stream.sol()) {
+ if (state.context && (state.context.align == null)) {
+ state.context.align = false;
+ }
+ state.indent = stream.indentation();
+ }
+ if (stream.eatSpace()) {
+ return null;
+ }
+ var style = state.tokenize(stream, state);
+ if (style !== "comment" && state.context && (state.context.align == null) && state.context.type !== "pattern") {
+ state.context.align = true;
+ }
+ if (curPunc === "(") {
+ pushContext(state, ")", stream.column());
+ } else if (curPunc === "[") {
+ pushContext(state, "]", stream.column());
+ } else if (curPunc === "{") {
+ pushContext(state, "}", stream.column());
+ } else if (/[\]\}\)]/.test(curPunc)) {
+ while (state.context && state.context.type === "pattern") {
+ popContext(state);
+ }
+ if (state.context && curPunc === state.context.type) {
+ popContext(state);
+ }
+ } else if (curPunc === "." && state.context && state.context.type === "pattern") {
+ popContext(state);
+ } else if (/atom|string|variable/.test(style) && state.context) {
+ if (/[\}\]]/.test(state.context.type)) {
+ pushContext(state, "pattern", stream.column());
+ } else if (state.context.type === "pattern" && !state.context.align) {
+ state.context.align = true;
+ state.context.col = stream.column();
+ }
+ }
+ return style;
+ },
+ indent: function(state, textAfter) {
+ var firstChar = textAfter && textAfter.charAt(0);
+ var context = state.context;
+ if (/[\]\}]/.test(firstChar)) {
+ while (context && context.type === "pattern") {
+ context = context.prev;
+ }
+ }
+ var closing = context && firstChar === context.type;
+ if (!context) return 0;
+ if (context.type === "keywords") return CodeMirror.commands.newlineAndIndent;
+ if (context.align) return context.col + (closing ? 0 : 1);
+ return context.indent + (closing ? 0 : indentUnit);
+ }
+ };
+ });
+
+ CodeMirror.modeExtensions["cypher"] = {
+ autoFormatLineBreaks: function(text) {
+ var i, lines, reProcessedPortion;
+ var lines = text.split("\n");
+ var reProcessedPortion = /\s+\b(return|where|order by|match|with|skip|limit|create|delete|set)\b\s/g;
+ for (var i = 0; i < lines.length; i++)
+ lines[i] = lines[i].replace(reProcessedPortion, " \n$1 ").trim();
+ return lines.join("\n");
+ }
+ };
+
+ CodeMirror.defineMIME("application/x-cypher-query", "cypher");
+
+});
diff --git a/public/vendor/codemirror/mode/cypher/index.html b/public/vendor/codemirror/mode/cypher/index.html
new file mode 100755
index 00000000..b8bd75c8
--- /dev/null
+++ b/public/vendor/codemirror/mode/cypher/index.html
@@ -0,0 +1,63 @@
+<!doctype html>
+
+<title>CodeMirror: Cypher Mode for CodeMirror</title>
+<meta charset="utf-8"/>
+<link rel=stylesheet href="../../doc/docs.css">
+
+<link rel="stylesheet" href="../../lib/codemirror.css" />
+<link rel="stylesheet" href="../../theme/neo.css" />
+<script src="../../lib/codemirror.js"></script>
+<script src="cypher.js"></script>
+<style>
+.CodeMirror {
+ border-top: 1px solid black;
+ border-bottom: 1px solid black;
+}
+ </style>
+<div id=nav>
+ <a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
+
+ <ul>
+ <li><a href="../../index.html">Home</a>
+ <li><a href="../../doc/manual.html">Manual</a>
+ <li><a href="https://github.com/codemirror/codemirror">Code</a>
+ </ul>
+ <ul>
+ <li><a href="../index.html">Language modes</a>
+ <li><a class=active href="#">Cypher Mode for CodeMirror</a>
+ </ul>
+</div>
+
+<article>
+<h2>Cypher Mode for CodeMirror</h2>
+<form>
+ <textarea id="code" name="code">// Cypher Mode for CodeMirror, using the neo theme
+MATCH (joe { name: 'Joe' })-[:knows*2..2]-(friend_of_friend)
+WHERE NOT (joe)-[:knows]-(friend_of_friend)
+RETURN friend_of_friend.name, COUNT(*)
+ORDER BY COUNT(*) DESC , friend_of_friend.name
+</textarea>
+ </form>
+ <p><strong>MIME types defined:</strong>
+ <code><a href="?mime=application/x-cypher-query">application/x-cypher-query</a></code>
+ </p>
+<script>
+window.onload = function() {
+ var mime = 'application/x-cypher-query';
+ // get mime type
+ if (window.location.href.indexOf('mime=') > -1) {
+ mime = window.location.href.substr(window.location.href.indexOf('mime=') + 5);
+ }
+ window.editor = CodeMirror.fromTextArea(document.getElementById('code'), {
+ mode: mime,
+ indentWithTabs: true,
+ smartIndent: true,
+ lineNumbers: true,
+ matchBrackets : true,
+ autofocus: true,
+ theme: 'neo'
+ });
+};
+</script>
+
+</article>