├── LICENSE ├── bigtest.html ├── compress.html ├── contrib ├── csharp │ ├── css │ │ └── csharpcolors.css │ ├── index.html │ └── js │ │ ├── parsecsharp.js │ │ └── tokenizecsharp.js ├── freemarker │ ├── LICENSE │ ├── css │ │ └── freemarkercolors.css │ ├── index.html │ └── js │ │ └── parsefreemarker.js ├── groovy │ └── index.html ├── java │ ├── LICENSE │ ├── css │ │ └── javacolors.css │ ├── index.html │ └── js │ │ ├── parsejava.js │ │ └── tokenizejava.js ├── lua │ ├── LICENSE │ ├── css │ │ └── luacolors.css │ ├── index.html │ └── js │ │ └── parselua.js ├── ometa │ ├── LICENSE │ ├── css │ │ └── ometacolors.css │ ├── index.html │ └── js │ │ ├── parseometa.js │ │ └── tokenizeometa.js ├── php │ ├── LICENSE │ ├── css │ │ └── phpcolors.css │ ├── index.html │ └── js │ │ ├── parsephp.js │ │ ├── parsephphtmlmixed.js │ │ └── tokenizephp.js ├── plsql │ ├── LICENSE │ ├── css │ │ └── plsqlcolors.css │ ├── index.html │ └── js │ │ └── parseplsql.js ├── python │ ├── LICENSE │ ├── css │ │ └── pythoncolors.css │ ├── index.html │ └── js │ │ └── parsepython.js ├── regex │ ├── css │ │ ├── js-regexcolors.css │ │ └── regexcolors.css │ ├── index.html │ ├── js-regex.html │ └── js │ │ ├── parsejavascript_and_regex.js │ │ ├── parseregex-unicode.js │ │ └── parseregex.js ├── scheme │ ├── LICENSE │ ├── css │ │ └── schemecolors.css │ ├── index.html │ └── js │ │ ├── parsescheme.js │ │ └── tokenizescheme.js ├── sql │ ├── LICENSE │ ├── css │ │ └── sqlcolors.css │ ├── index.html │ └── js │ │ └── parsesql.js └── xquery │ ├── LICENSE │ ├── css │ ├── xqcolors-dark.css │ ├── xqcolors.css │ └── xqcolors2.css │ ├── index.html │ └── js │ ├── parsexquery.js │ └── tokenizexquery.js ├── css ├── baboon.png ├── baboon_vector.svg ├── csscolors.css ├── docs.css ├── font.js ├── jscolors.css ├── people.jpg ├── sparqlcolors.css └── xmlcolors.css ├── csstest.html ├── faq.html ├── highlight.html ├── htmltest.html ├── index.html ├── js ├── codemirror.js ├── editor.js ├── highlight.js ├── mirrorframe.js ├── parsecss.js ├── parsedummy.js ├── parsehtmlmixed.js ├── parsejavascript.js ├── parsesparql.js ├── parsexml.js ├── select.js ├── stringstream.js ├── tokenize.js ├── tokenizejavascript.js ├── undo.js ├── unittests.js └── util.js ├── jstest.html ├── manual.html ├── mixedtest.html ├── readme.md ├── sparqltest.html ├── story.html ├── unittests.html └── xhtmltest.xhtml /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2010 Marijn Haverbeke 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any 5 | damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any 8 | purpose, including commercial applications, and to alter it and 9 | redistribute it freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must 12 | not claim that you wrote the original software. If you use this 13 | software in a product, an acknowledgment in the product 14 | documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must 17 | not be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | 22 | Marijn Haverbeke 23 | marijnh@gmail.com 24 | -------------------------------------------------------------------------------- /contrib/csharp/css/csharpcolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | pre.code, .editbox { 14 | color: #666666; 15 | } 16 | 17 | .editbox p { 18 | margin: 0; 19 | } 20 | 21 | span.csharp-punctuation { 22 | color: green; 23 | } 24 | 25 | span.csharp-operator { 26 | color: purple; 27 | } 28 | 29 | span.csharp-keyword { 30 | color: blue; 31 | } 32 | 33 | span.csharp-atom { 34 | color: brown; 35 | } 36 | 37 | span.csharp-variable { 38 | color: black; 39 | } 40 | 41 | span.csharp-variabledef { 42 | color: #0000FF; 43 | } 44 | 45 | span.csharp-localvariable { 46 | color: #004499; 47 | } 48 | 49 | span.csharp-property { 50 | color: black; 51 | } 52 | 53 | span.csharp-comment { 54 | color: green; 55 | } 56 | 57 | span.csharp-string { 58 | color: red; 59 | } 60 | 61 | -------------------------------------------------------------------------------- /contrib/csharp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: C# demonstration 5 | 6 | 7 | 8 | 9 |

Demonstration of CodeMirror's C# highlighter.

10 | 11 |

Written by Boris Gaber and Christopher Buchino.

12 | 13 |
14 | 48 |
49 | 50 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /contrib/csharp/js/tokenizecsharp.js: -------------------------------------------------------------------------------- 1 | /* Tokenizer for CSharp code */ 2 | 3 | var tokenizeCSharp = (function() { 4 | // Advance the stream until the given character (not preceded by a 5 | // backslash) is encountered, or the end of the line is reached. 6 | function nextUntilUnescaped(source, end) { 7 | var escaped = false; 8 | var next; 9 | while (!source.endOfLine()) { 10 | var next = source.next(); 11 | if (next == end && !escaped) 12 | return false; 13 | escaped = !escaped && next == "\\"; 14 | } 15 | return escaped; 16 | } 17 | 18 | // A map of JavaScript's keywords. The a/b/c keyword distinction is 19 | // very rough, but it gives the parser enough information to parse 20 | // correct code correctly (we don't care that much how we parse 21 | // incorrect code). The style information included in these objects 22 | // is used by the highlighter to pick the correct CSS style for a 23 | // token. 24 | var keywords = function(){ 25 | function result(type, style){ 26 | return {type: type, style: "csharp-" + style}; 27 | } 28 | // keywords that take a parenthised expression, and then a 29 | // statement (if) 30 | var keywordA = result("keyword a", "keyword"); 31 | // keywords that take just a statement (else) 32 | var keywordB = result("keyword b", "keyword"); 33 | // keywords that optionally take an expression, and form a 34 | // statement (return) 35 | var keywordC = result("keyword c", "keyword"); 36 | var operator = result("operator", "keyword"); 37 | var atom = result("atom", "atom"); 38 | // just a keyword with no indentation implications 39 | var keywordD = result("keyword d", "keyword"); 40 | 41 | return { 42 | "if": keywordA, "while": keywordA, "with": keywordA, 43 | "else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB, 44 | "return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC, 45 | "in": operator, "typeof": operator, "instanceof": operator, 46 | "var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"), 47 | "for": result("for", "keyword"), "switch": result("switch", "keyword"), 48 | "case": result("case", "keyword"), "default": result("default", "keyword"), 49 | "true": atom, "false": atom, "null": atom, 50 | 51 | "class": result("class", "keyword"), "namespace": result("class", "keyword"), 52 | 53 | "public": keywordD, "private": keywordD, "protected": keywordD, "internal": keywordD, 54 | "extern": keywordD, "override": keywordD, "virtual": keywordD, "abstract": keywordD, 55 | "static": keywordD, "out": keywordD, "ref": keywordD, "const": keywordD, 56 | 57 | "foreach": result("for", "keyword"), "using": keywordC, 58 | 59 | "int": keywordD, "double": keywordD, "long": keywordD, "bool": keywordD, "char": keywordD, 60 | "void": keywordD, "string": keywordD, "byte": keywordD, "sbyte": keywordD, "decimal": keywordD, 61 | "float": keywordD, "uint": keywordD, "ulong": keywordD, "object": keywordD, 62 | "short": keywordD, "ushort": keywordD, 63 | 64 | "get": keywordD, "set": keywordD, "value": keywordD 65 | }; 66 | }(); 67 | 68 | // Some helper regexps 69 | var isOperatorChar = /[+\-*&%=<>!?|]/; 70 | var isHexDigit = /[0-9A-Fa-f]/; 71 | var isWordChar = /[\w\$_]/; 72 | 73 | // Wrapper around jsToken that helps maintain parser state (whether 74 | // we are inside of a multi-line comment and whether the next token 75 | // could be a regular expression). 76 | function jsTokenState(inside, regexp) { 77 | function state(source, setState) { 78 | var newInside = inside; 79 | var type = jsToken(inside, regexp, source, function(c) {newInside = c;}); 80 | var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/); 81 | if (newRegexp != regexp || newInside != inside) 82 | setState(jsTokenState(newInside, newRegexp)); 83 | return type; 84 | }; 85 | state.doNotIndent = inside == "@\""; 86 | return state; 87 | } 88 | 89 | // The token reader, intended to be used by the tokenizer from 90 | // tokenize.js (through jsTokenState). Advances the source stream 91 | // over a token, and returns an object containing the type and style 92 | // of that token. 93 | function jsToken(inside, regexp, source, setInside) { 94 | function readHexNumber(){ 95 | source.next(); // skip the 'x' 96 | source.nextWhileMatches(isHexDigit); 97 | return {type: "number", style: "csharp-atom"}; 98 | } 99 | 100 | function readNumber() { 101 | source.nextWhileMatches(/[0-9]/); 102 | if (source.equals(".")){ 103 | source.next(); 104 | source.nextWhileMatches(/[0-9]/); 105 | } 106 | if (source.equals("e") || source.equals("E")){ 107 | source.next(); 108 | if (source.equals("-")) 109 | source.next(); 110 | source.nextWhileMatches(/[0-9]/); 111 | } 112 | return {type: "number", style: "csharp-atom"}; 113 | } 114 | // Read a word, look it up in keywords. If not found, it is a 115 | // variable, otherwise it is a keyword of the type found. 116 | function readWord() { 117 | source.nextWhileMatches(isWordChar); 118 | var word = source.get(); 119 | var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word]; 120 | return known ? {type: known.type, style: known.style, content: word} : 121 | {type: "variable", style: "csharp-variable", content: word}; 122 | } 123 | function readRegexp() { 124 | nextUntilUnescaped(source, "/"); 125 | source.nextWhileMatches(/[gi]/); 126 | return {type: "regexp", style: "csharp-string"}; 127 | } 128 | // Mutli-line comments are tricky. We want to return the newlines 129 | // embedded in them as regular newline tokens, and then continue 130 | // returning a comment token for every line of the comment. So 131 | // some state has to be saved (inside) to indicate whether we are 132 | // inside a /* */ sequence. 133 | function readMultilineComment(start){ 134 | var newInside = "/*"; 135 | var maybeEnd = (start == "*"); 136 | while (true) { 137 | if (source.endOfLine()) 138 | break; 139 | var next = source.next(); 140 | if (next == "/" && maybeEnd){ 141 | newInside = null; 142 | break; 143 | } 144 | maybeEnd = (next == "*"); 145 | } 146 | setInside(newInside); 147 | return {type: "comment", style: "csharp-comment"}; 148 | } 149 | function readOperator() { 150 | source.nextWhileMatches(isOperatorChar); 151 | return {type: "operator", style: "csharp-operator"}; 152 | } 153 | function readString(quote) { 154 | var endBackSlash = nextUntilUnescaped(source, quote); 155 | setInside(endBackSlash ? quote : null); 156 | return {type: "string", style: "csharp-string"}; 157 | } 158 | function readVerbatimString(start){ 159 | var newInside = "@\""; 160 | var maybeEnd = (start == "\""); 161 | while (true) { 162 | if (maybeEnd) { 163 | if (source.peek() == "\"") { 164 | source.next(); 165 | } 166 | else { 167 | newInside = null; 168 | break; 169 | } 170 | } 171 | if (source.endOfLine()) 172 | break; 173 | var next = source.next(); 174 | maybeEnd = (next == "\""); 175 | } 176 | setInside(newInside); 177 | return {type: "string", style: "csharp-string"}; 178 | } 179 | 180 | // Fetch the next token. Dispatches on first character in the 181 | // stream, or first two characters when the first is a slash. 182 | if (inside == "\"" || inside == "'") 183 | return readString(inside); 184 | var ch = source.next(); 185 | if (inside == "/*") 186 | return readMultilineComment(ch); 187 | else if (inside == "@\"") 188 | return readVerbatimString(ch); 189 | else if (ch == "\"" || ch == "'") 190 | return readString(ch); 191 | // with punctuation, the type of the token is the symbol itself 192 | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) 193 | return {type: ch, style: "csharp-punctuation"}; 194 | else if (ch == "0" && (source.equals("x") || source.equals("X"))) 195 | return readHexNumber(); 196 | else if (/[0-9]/.test(ch)) 197 | return readNumber(); 198 | else if (ch == "/"){ 199 | if (source.equals("*")) 200 | { source.next(); return readMultilineComment(ch); } 201 | else if (source.equals("/")) 202 | { nextUntilUnescaped(source, null); return {type: "comment", style: "csharp-comment"};} 203 | else if (regexp) 204 | return readRegexp(); 205 | else 206 | return readOperator(); 207 | } 208 | else if (ch == "#") { // treat c# regions like comments 209 | nextUntilUnescaped(source, null); return {type: "comment", style: "csharp-comment"}; 210 | } 211 | else if (ch == "@") { 212 | if (source.equals("\"")) { 213 | source.next(); 214 | return readVerbatimString(ch); 215 | } 216 | else 217 | return readWord(); 218 | } 219 | else if (isOperatorChar.test(ch)) 220 | return readOperator(); 221 | else 222 | return readWord(); 223 | } 224 | 225 | // The external interface to the tokenizer. 226 | return function(source, startState) { 227 | return tokenizer(source, startState || jsTokenState(false, true)); 228 | }; 229 | })(); 230 | -------------------------------------------------------------------------------- /contrib/freemarker/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Keybroker AB 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of Keybroker AB nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL Keybroker AB BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /contrib/freemarker/css/freemarkercolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 12px; 10 | font-size-adjust: none; 11 | font-style: normal; 12 | font-variant: normal; 13 | font-weight: normal; 14 | line-height: normal; 15 | color: black; 16 | } 17 | 18 | pre.code, .editbox { 19 | color: black; 20 | } 21 | 22 | .editbox p { 23 | margin: 0; 24 | } 25 | 26 | span.freemarker-comment { 27 | color: #BB9977; 28 | } 29 | 30 | span.freemarker-generic { 31 | } 32 | 33 | span.freemarker-boundary { 34 | color: darkblue; 35 | } 36 | 37 | span.freemarker-directive { 38 | color: darkblue; 39 | } 40 | 41 | span.freemarker-identifier { 42 | color: purple; 43 | } 44 | 45 | span.freemarker-builtin { 46 | color: gray; 47 | } 48 | 49 | span.freemarker-punctuation { 50 | color: blue; 51 | } 52 | 53 | span.freemarker-string { 54 | color: darkGreen; 55 | } 56 | 57 | span.freemarker-number { 58 | color: blue; 59 | } 60 | 61 | span.freemarker-error { 62 | color: #F00 !important; 63 | } 64 | -------------------------------------------------------------------------------- /contrib/freemarker/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Freemarker demonstration 6 | 7 | 20 | 21 | 22 | 23 |

This page demonstrates CodeMirror's 24 | Freemarker parser. Written by Magnus Ljung, released under a BSD-style license.

26 | 27 |
28 | 50 |
51 | 52 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /contrib/groovy/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: Groovy demonstration 5 | 6 | 7 | 8 | 9 |

Demonstration of CodeMirror's Groovy highlighter.

10 | 11 |

Created by eXo Platform SAS (license).

12 | 13 |

Note that the files for this parser aren't included in the CodeMirror repository, but have to fetched from svn.exoplatform.org:

14 | 15 | 20 | 21 |
22 | 44 |
45 | 46 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /contrib/java/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Patrick Wied 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any 5 | damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any 8 | purpose, including commercial applications, and to alter it and 9 | redistribute it freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must 12 | not claim that you wrote the original software. If you use this 13 | software in a product, an acknowledgment in the product 14 | documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must 17 | not be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | -------------------------------------------------------------------------------- /contrib/java/css/javacolors.css: -------------------------------------------------------------------------------- 1 | 2 | html { 3 | cursor: text; 4 | } 5 | 6 | .editbox { 7 | margin: .4em; 8 | padding: 0; 9 | font-family: monospace; 10 | font-size: 10pt; 11 | color: black; 12 | } 13 | 14 | pre.code, .editbox { 15 | color: #666666; 16 | } 17 | 18 | .editbox p { 19 | margin: 0; 20 | } 21 | 22 | span.java-punctuation { 23 | color: black; 24 | } 25 | 26 | span.java-operator { 27 | color: purple; 28 | } 29 | 30 | span.java-keyword { 31 | color: #7f0055; 32 | font-weight:bold; 33 | } 34 | 35 | span.java-atom { 36 | color: brown; 37 | } 38 | 39 | span.java-variable { 40 | color: black; 41 | } 42 | 43 | 44 | span.java-property { 45 | color: black; 46 | } 47 | 48 | span.java-comment { 49 | color: green; 50 | } 51 | 52 | span.javadoc-comment { 53 | color: #3e5797; 54 | font-weight:bold; 55 | } 56 | 57 | span.java-string { 58 | color: blue; 59 | } 60 | 61 | span.java-annotation{ 62 | color: gray; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /contrib/java/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demonstration of CodeMirrors Java highlighter written by Patrick Wied 6 | 7 | 8 | 9 | 10 |

Demonstration of CodeMirror's Java highlighter.

11 | 12 |

Written by Patrick Wied.

13 | 14 |
15 | 55 |
56 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /contrib/java/js/tokenizejava.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Java tokenizer for codemirror 3 | * 4 | * @author Patrick Wied 5 | * @version 2010-10-07 6 | */ 7 | var tokenizeJava = (function() { 8 | // Advance the stream until the given character (not preceded by a 9 | // backslash) is encountered, or the end of the line is reached. 10 | function nextUntilUnescaped(source, end) { 11 | var escaped = false; 12 | var next; 13 | while (!source.endOfLine()) { 14 | var next = source.next(); 15 | if (next == end && !escaped) 16 | return false; 17 | escaped = !escaped && next == "\\"; 18 | } 19 | return escaped; 20 | } 21 | 22 | // A map of Java's keywords. The a/b/c keyword distinction is 23 | // very rough, but it gives the parser enough information to parse 24 | // correct code correctly (we don't care that much how we parse 25 | // incorrect code). The style information included in these objects 26 | // is used by the highlighter to pick the correct CSS style for a 27 | // token. 28 | var keywords = function(){ 29 | function result(type, style){ 30 | return {type: type, style: "java-" + style}; 31 | } 32 | // keywords that take a parenthised expression, and then a 33 | // statement (if) 34 | var keywordA = result("keyword a", "keyword"); 35 | // keywords that take just a statement (else) 36 | var keywordB = result("keyword b", "keyword"); 37 | // keywords that optionally take an expression, and form a 38 | // statement (return) 39 | var keywordC = result("keyword c", "keyword"); 40 | var operator = result("operator", "keyword"); 41 | var atom = result("atom", "atom"); 42 | 43 | return { 44 | "if": keywordA, "while": keywordA, "with": keywordA, 45 | "else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB, 46 | "return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "throw": keywordC, "throws": keywordB, 47 | "in": operator, "typeof": operator, "instanceof": operator, 48 | "catch": result("catch", "keyword"), "for": result("for", "keyword"), "switch": result("switch", "keyword"), 49 | "case": result("case", "keyword"), "default": result("default", "keyword"), 50 | "true": atom, "false": atom, "null": atom, 51 | 52 | "class": result("class", "keyword"), "interface": result("interface", "keyword"), "package": keywordC, "import": keywordC, 53 | "implements": keywordC, "extends": keywordC, "super": keywordC, 54 | 55 | "public": keywordC, "private": keywordC, "protected": keywordC, "transient": keywordC, "this": keywordC, 56 | "static": keywordC, "final": keywordC, "const": keywordC, "abstract": keywordC, "static": keywordC, 57 | 58 | "int": keywordC, "double": keywordC, "long": keywordC, "boolean": keywordC, "char": keywordC, 59 | "void": keywordC, "byte": keywordC, "float": keywordC, "short": keywordC 60 | }; 61 | }(); 62 | 63 | // Some helper regexps 64 | var isOperatorChar = /[+\-*&%=<>!?|]/; 65 | var isHexDigit = /[0-9A-Fa-f]/; 66 | var isWordChar = /[\w\$_]/; 67 | // Wrapper around javaToken that helps maintain parser state (whether 68 | // we are inside of a multi-line comment and whether the next token 69 | // could be a regular expression). 70 | function javaTokenState(inside, regexp) { 71 | return function(source, setState) { 72 | var newInside = inside; 73 | var type = javaToken(inside, regexp, source, function(c) {newInside = c;}); 74 | var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/); 75 | if (newRegexp != regexp || newInside != inside) 76 | setState(javaTokenState(newInside, newRegexp)); 77 | return type; 78 | }; 79 | } 80 | 81 | // The token reader, inteded to be used by the tokenizer from 82 | // tokenize.js (through jsTokenState). Advances the source stream 83 | // over a token, and returns an object containing the type and style 84 | // of that token. 85 | function javaToken(inside, regexp, source, setInside) { 86 | function readHexNumber(){ 87 | source.next(); // skip the 'x' 88 | source.nextWhileMatches(isHexDigit); 89 | return {type: "number", style: "java-atom"}; 90 | } 91 | 92 | function readNumber() { 93 | source.nextWhileMatches(/[0-9]/); 94 | if (source.equals(".")){ 95 | source.next(); 96 | source.nextWhileMatches(/[0-9]/); 97 | } 98 | if (source.equals("e") || source.equals("E")){ 99 | source.next(); 100 | if (source.equals("-")) 101 | source.next(); 102 | source.nextWhileMatches(/[0-9]/); 103 | } 104 | return {type: "number", style: "java-atom"}; 105 | } 106 | // Read a word, look it up in keywords. If not found, it is a 107 | // variable, otherwise it is a keyword of the type found. 108 | function readWord() { 109 | source.nextWhileMatches(isWordChar); 110 | var word = source.get(); 111 | var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word]; 112 | return known ? {type: known.type, style: known.style, content: word} : 113 | {type: "variable", style: "java-variable", content: word}; 114 | } 115 | function readRegexp() { 116 | nextUntilUnescaped(source, "/"); 117 | source.nextWhileMatches(/[gi]/); 118 | return {type: "regexp", style: "java-string"}; 119 | } 120 | // Mutli-line comments are tricky. We want to return the newlines 121 | // embedded in them as regular newline tokens, and then continue 122 | // returning a comment token for every line of the comment. So 123 | // some state has to be saved (inside) to indicate whether we are 124 | // inside a /* */ sequence. 125 | function readMultilineComment(start){ 126 | var newInside = "/*"; 127 | var maybeEnd = (start == "*"); 128 | while (true) { 129 | if (source.endOfLine()) 130 | break; 131 | var next = source.next(); 132 | if (next == "/" && maybeEnd){ 133 | newInside = null; 134 | break; 135 | } 136 | maybeEnd = (next == "*"); 137 | } 138 | setInside(newInside); 139 | return {type: "comment", style: "java-comment"}; 140 | } 141 | 142 | // for reading javadoc 143 | function readJavaDocComment(start){ 144 | var newInside = "/**"; 145 | var maybeEnd = (start == "*"); 146 | while (true) { 147 | if (source.endOfLine()) 148 | break; 149 | var next = source.next(); 150 | if (next == "/" && maybeEnd){ 151 | newInside = null; 152 | break; 153 | } 154 | maybeEnd = (next == "*"); 155 | } 156 | setInside(newInside); 157 | return {type: "javadoc", style: "javadoc-comment"}; 158 | } 159 | // for reading annotations (word based) 160 | function readAnnotation(){ 161 | source.nextWhileMatches(isWordChar); 162 | var word = source.get(); 163 | return {type: "annotation", style: "java-annotation", content:word}; 164 | } 165 | 166 | function readOperator() { 167 | source.nextWhileMatches(isOperatorChar); 168 | return {type: "operator", style: "java-operator"}; 169 | } 170 | function readString(quote) { 171 | var endBackSlash = nextUntilUnescaped(source, quote); 172 | setInside(endBackSlash ? quote : null); 173 | return {type: "string", style: "java-string"}; 174 | } 175 | 176 | // Fetch the next token. Dispatches on first character in the 177 | // stream, or first two characters when the first is a slash. 178 | if (inside == "\"" || inside == "'") 179 | return readString(inside); 180 | var ch = source.next(); 181 | if (inside == "/*") 182 | return readMultilineComment(ch); 183 | else if(inside == "/**") 184 | return readJavaDocComment(ch); 185 | else if (ch == "\"" || ch == "'") 186 | return readString(ch); 187 | // with punctuation, the type of the token is the symbol itself 188 | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) 189 | return {type: ch, style: "java-punctuation"}; 190 | else if (ch == "0" && (source.equals("x") || source.equals("X"))) 191 | return readHexNumber(); 192 | else if (/[0-9]/.test(ch)) 193 | return readNumber(); 194 | else if (ch == "@"){ 195 | return readAnnotation(); 196 | }else if (ch == "/"){ 197 | if (source.equals("*")){ 198 | source.next(); 199 | 200 | if(source.equals("*")) 201 | return readJavaDocComment(ch); 202 | 203 | return readMultilineComment(ch); 204 | } 205 | else if (source.equals("/")) 206 | { nextUntilUnescaped(source, null); return {type: "comment", style: "java-comment"};} 207 | else if (regexp) 208 | return readRegexp(); 209 | else 210 | return readOperator(); 211 | } 212 | else if (isOperatorChar.test(ch)) 213 | return readOperator(); 214 | else 215 | return readWord(); 216 | } 217 | 218 | // The external interface to the tokenizer. 219 | return function(source, startState) { 220 | return tokenizer(source, startState || javaTokenState(false, true)); 221 | }; 222 | })(); 223 | -------------------------------------------------------------------------------- /contrib/lua/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, Franciszek Wawrzak 2 | All rights reserved. 3 | 4 | This software is provided for use in connection with the 5 | CodeMirror suite of modules and utilities, hosted and maintained 6 | at http://codemirror.net/. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /contrib/lua/css/luacolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | pre.code, .editbox { 14 | color: #666666; 15 | } 16 | 17 | .editbox p { 18 | margin: 0; 19 | } 20 | 21 | span.lua-comment { 22 | color: #BB9977; 23 | } 24 | 25 | span.lua-keyword { 26 | font-weight: bold; 27 | color: blue; 28 | } 29 | 30 | span.lua-string { 31 | color: #AA2222; 32 | } 33 | 34 | span.lua-stdfunc { 35 | font-weight: bold; 36 | color: #077; 37 | } 38 | span.lua-customfunc { 39 | font-weight: bold; 40 | color: #0AA; 41 | } 42 | 43 | 44 | span.lua-identifier { 45 | color: black; 46 | } 47 | 48 | span.lua-number { 49 | color: #3A3; 50 | } 51 | 52 | span.lua-token { 53 | color: #151; 54 | } 55 | 56 | span.lua-error { 57 | color: #FFF; 58 | background-color: #F00; 59 | } 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /contrib/lua/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: Lua demonstration 5 | 6 | 7 | 8 |

This page demonstrates CodeMirror's 9 | Lua parser. Written by Franciszek 10 | Wawrzak, released under a BSD-style license.

12 | 13 |
14 | 76 |
77 | 78 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /contrib/lua/js/parselua.js: -------------------------------------------------------------------------------- 1 | /* 2 | Simple parser for LUA 3 | Written for Lua 5.1, based on parsecss and other parsers. 4 | features: highlights keywords, strings, comments (no leveling supported! ("[==[")),tokens, basic indenting 5 | 6 | to make this parser highlight your special functions pass table with this functions names to parserConfig argument of creator, 7 | 8 | parserConfig: ["myfunction1","myfunction2"], 9 | */ 10 | 11 | 12 | function findFirstRegexp(words) { 13 | return new RegExp("^(?:" + words.join("|") + ")", "i"); 14 | } 15 | 16 | function matchRegexp(words) { 17 | return new RegExp("^(?:" + words.join("|") + ")$", "i"); 18 | } 19 | 20 | 21 | 22 | var luaCustomFunctions= matchRegexp([]); 23 | 24 | function configureLUA(parserConfig){ 25 | if(parserConfig) 26 | luaCustomFunctions= matchRegexp(parserConfig); 27 | } 28 | 29 | 30 | //long list of standard functions from lua manual 31 | var luaStdFunctions = matchRegexp([ 32 | "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load","loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require","select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall", 33 | 34 | "coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield", 35 | 36 | "debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable","debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable","debug.setupvalue","debug.traceback", 37 | 38 | "close","flush","lines","read","seek","setvbuf","write", 39 | 40 | "io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin","io.stdout","io.tmpfile","io.type","io.write", 41 | 42 | "math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg","math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max","math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh","math.sqrt","math.tan","math.tanh", 43 | 44 | "os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale","os.time","os.tmpname", 45 | 46 | "package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload","package.seeall", 47 | 48 | "string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub","string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper", 49 | 50 | "table.concat","table.insert","table.maxn","table.remove","table.sort" 51 | ]); 52 | 53 | 54 | 55 | var luaKeywords = matchRegexp(["and","break","elseif","false","nil","not","or","return", 56 | "true","function", "end", "if", "then", "else", "do", 57 | "while", "repeat", "until", "for", "in", "local" ]); 58 | 59 | var luaIndentKeys = matchRegexp(["function", "if","repeat","for","while", "[\(]", "{"]); 60 | var luaUnindentKeys = matchRegexp(["end", "until", "[\)]", "}"]); 61 | 62 | var luaUnindentKeys2 = findFirstRegexp(["end", "until", "[\)]", "}"]); 63 | var luaMiddleKeys = findFirstRegexp(["else","elseif"]); 64 | 65 | 66 | 67 | var LUAParser = Editor.Parser = (function() { 68 | var tokenizeLUA = (function() { 69 | function normal(source, setState) { 70 | var ch = source.next(); 71 | 72 | if (ch == "-" && source.equals("-")) { 73 | source.next(); 74 | setState(inSLComment); 75 | return null; 76 | } 77 | else if (ch == "\"" || ch == "'") { 78 | setState(inString(ch)); 79 | return null; 80 | } 81 | if (ch == "[" && (source.equals("[") || source.equals("="))) { 82 | var level = 0; 83 | while(source.equals("=")){ 84 | level ++; 85 | source.next(); 86 | } 87 | if(! source.equals("[") ) 88 | return "lua-error"; 89 | setState(inMLSomething(level,"lua-string")); 90 | return null; 91 | } 92 | 93 | else if (ch == "=") { 94 | if (source.equals("=")) 95 | source.next(); 96 | return "lua-token"; 97 | } 98 | 99 | else if (ch == ".") { 100 | if (source.equals(".")) 101 | source.next(); 102 | if (source.equals(".")) 103 | source.next(); 104 | return "lua-token"; 105 | } 106 | 107 | else if (ch == "+" || ch == "-" || ch == "*" || ch == "/" || ch == "%" || ch == "^" || ch == "#" ) { 108 | return "lua-token"; 109 | } 110 | else if (ch == ">" || ch == "<" || ch == "(" || ch == ")" || ch == "{" || ch == "}" || ch == "[" ) { 111 | return "lua-token"; 112 | } 113 | else if (ch == "]" || ch == ";" || ch == ":" || ch == ",") { 114 | return "lua-token"; 115 | } 116 | else if (source.equals("=") && (ch == "~" || ch == "<" || ch == ">")) { 117 | source.next(); 118 | return "lua-token"; 119 | } 120 | 121 | else if (/\d/.test(ch)) { 122 | source.nextWhileMatches(/[\w.%]/); 123 | return "lua-number"; 124 | } 125 | else { 126 | source.nextWhileMatches(/[\w\\\-_.]/); 127 | return "lua-identifier"; 128 | } 129 | } 130 | 131 | function inSLComment(source, setState) { 132 | var start = true; 133 | var count=0; 134 | while (!source.endOfLine()) { 135 | var ch = source.next(); 136 | var level = 0; 137 | if ((ch =="[") && start){ 138 | while(source.equals("=")){ 139 | source.next(); 140 | level++; 141 | } 142 | if (source.equals("[")){ 143 | setState(inMLSomething(level,"lua-comment")); 144 | return null; 145 | } 146 | } 147 | start = false; 148 | } 149 | setState(normal); 150 | return "lua-comment"; 151 | 152 | } 153 | 154 | function inMLSomething(level,what) { 155 | //wat sholud be "lua-string" or "lua-comment", level is the number of "=" in opening mark. 156 | return function(source, setState){ 157 | var dashes = 0; 158 | while (!source.endOfLine()) { 159 | var ch = source.next(); 160 | if (dashes == level+1 && ch == "]" ) { 161 | setState(normal); 162 | break; 163 | } 164 | if (dashes == 0) 165 | dashes = (ch == "]") ? 1:0; 166 | else 167 | dashes = (ch == "=") ? dashes + 1 : 0; 168 | } 169 | return what; 170 | } 171 | } 172 | 173 | 174 | function inString(quote) { 175 | return function(source, setState) { 176 | var escaped = false; 177 | while (!source.endOfLine()) { 178 | var ch = source.next(); 179 | if (ch == quote && !escaped) 180 | break; 181 | escaped = !escaped && ch == "\\"; 182 | } 183 | if (!escaped) 184 | setState(normal); 185 | return "lua-string"; 186 | }; 187 | } 188 | 189 | return function(source, startState) { 190 | return tokenizer(source, startState || normal); 191 | }; 192 | })(); 193 | 194 | function indentLUA(indentDepth, base) { 195 | return function(nextChars) { 196 | 197 | var closing = (luaUnindentKeys2.test(nextChars) || luaMiddleKeys.test(nextChars)); 198 | 199 | 200 | return base + ( indentUnit * (indentDepth - (closing?1:0)) ); 201 | }; 202 | } 203 | 204 | 205 | function parseLUA(source,basecolumn) { 206 | basecolumn = basecolumn || 0; 207 | 208 | var tokens = tokenizeLUA(source); 209 | var indentDepth = 0; 210 | 211 | var iter = { 212 | next: function() { 213 | var token = tokens.next(), style = token.style, content = token.content; 214 | 215 | 216 | 217 | if (style == "lua-identifier" && luaKeywords.test(content)){ 218 | token.style = "lua-keyword"; 219 | } 220 | if (style == "lua-identifier" && luaStdFunctions.test(content)){ 221 | token.style = "lua-stdfunc"; 222 | } 223 | if (style == "lua-identifier" && luaCustomFunctions.test(content)){ 224 | token.style = "lua-customfunc"; 225 | } 226 | 227 | if ((style != "lua-comment") && (style != "lua-string")){ 228 | if (luaIndentKeys.test(content)) 229 | indentDepth++; 230 | else if (luaUnindentKeys.test(content)) 231 | indentDepth--; 232 | } 233 | 234 | if (content == "\n") 235 | token.indentation = indentLUA( indentDepth, basecolumn); 236 | 237 | return token; 238 | }, 239 | 240 | copy: function() { 241 | var _tokenState = tokens.state, _indentDepth = indentDepth; 242 | return function(source) { 243 | tokens = tokenizeLUA(source, _tokenState); 244 | 245 | indentDepth = _indentDepth; 246 | return iter; 247 | }; 248 | } 249 | }; 250 | return iter; 251 | } 252 | 253 | return {make: parseLUA, configure:configureLUA, electricChars: "delf})"}; //en[d] els[e] unti[l] elsei[f] // this should be taken from Keys keywords 254 | })(); 255 | 256 | -------------------------------------------------------------------------------- /contrib/ometa/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-2009 Marijn Haverbeke 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any 5 | damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any 8 | purpose, including commercial applications, and to alter it and 9 | redistribute it freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must 12 | not claim that you wrote the original software. If you use this 13 | software in a product, an acknowledgment in the product 14 | documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must 17 | not be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | 22 | Marijn Haverbeke 23 | marijnh at gmail 24 | -------------------------------------------------------------------------------- /contrib/ometa/css/ometacolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | pre.code, .editbox { 14 | color: #666666; 15 | } 16 | 17 | .editbox p { 18 | margin: 0; 19 | } 20 | 21 | span.js-punctuation { 22 | color: #666666; 23 | } 24 | 25 | span.js-operator { 26 | color: #E1570F; 27 | } 28 | 29 | span.js-keyword { 30 | color: #770088; 31 | } 32 | 33 | span.js-atom { 34 | color: #228811; 35 | } 36 | 37 | span.js-variable { 38 | color: black; 39 | } 40 | 41 | span.js-variabledef { 42 | color: #0000FF; 43 | } 44 | 45 | span.js-localvariable { 46 | color: #004499; 47 | } 48 | 49 | span.js-property { 50 | color: black; 51 | } 52 | 53 | span.js-comment { 54 | color: #AA7700; 55 | } 56 | 57 | span.js-string { 58 | color: #AA2222; 59 | } 60 | 61 | span.ometa-binding { 62 | color: #FF0000; 63 | } 64 | -------------------------------------------------------------------------------- /contrib/ometa/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: OmetaJS demonstration 5 | 6 | 7 | 8 | 9 |

This page demonstrates CodeMirror's OmetaJS parser.

11 | 12 |

Adapted from the official Javascript parser by Eric KEDJI 13 | <eric.kedji@gmail.com>.

14 | 15 |
16 | 53 |
54 | 55 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /contrib/ometa/js/tokenizeometa.js: -------------------------------------------------------------------------------- 1 | /* Tokenizer for JavaScript code */ 2 | 3 | var tokenizeJavaScript = (function() { 4 | // Advance the stream until the given character (not preceded by a 5 | // backslash) is encountered, or the end of the line is reached. 6 | function nextUntilUnescaped(source, end) { 7 | var escaped = false; 8 | while (!source.endOfLine()) { 9 | var next = source.next(); 10 | if (next == end && !escaped) 11 | return false; 12 | escaped = !escaped && next == "\\"; 13 | } 14 | return escaped; 15 | } 16 | 17 | // A map of JavaScript's keywords. The a/b/c keyword distinction is 18 | // very rough, but it gives the parser enough information to parse 19 | // correct code correctly (we don't care that much how we parse 20 | // incorrect code). The style information included in these objects 21 | // is used by the highlighter to pick the correct CSS style for a 22 | // token. 23 | var keywords = function(){ 24 | function result(type, style){ 25 | return {type: type, style: "js-" + style}; 26 | } 27 | // keywords that take a parenthised expression, and then a 28 | // statement (if) 29 | var keywordA = result("keyword a", "keyword"); 30 | // keywords that take just a statement (else) 31 | var keywordB = result("keyword b", "keyword"); 32 | // keywords that optionally take an expression, and form a 33 | // statement (return) 34 | var keywordC = result("keyword c", "keyword"); 35 | var operator = result("operator", "keyword"); 36 | var atom = result("atom", "atom"); 37 | return { 38 | "if": keywordA, "while": keywordA, "with": keywordA, 39 | "else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB, 40 | "return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC, 41 | "in": operator, "typeof": operator, "instanceof": operator, 42 | "var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"), 43 | "for": result("for", "keyword"), "switch": result("switch", "keyword"), 44 | "case": result("case", "keyword"), "default": result("default", "keyword"), 45 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom, 46 | "ometa": keywordB 47 | }; 48 | }(); 49 | 50 | // Some helper regexps 51 | var isOperatorChar = /[+\-*&%=<>!?|~]/; 52 | var isHexDigit = /[0-9A-Fa-f]/; 53 | var isWordChar = /[\w\$_]/; 54 | 55 | // Wrapper around jsToken that helps maintain parser state (whether 56 | // we are inside of a multi-line comment and whether the next token 57 | // could be a regular expression). 58 | function jsTokenState(inside, regexp) { 59 | return function(source, setState) { 60 | var newInside = inside; 61 | var type = jsToken(inside, regexp, source, function(c) {newInside = c;}); 62 | var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/); 63 | if (newRegexp != regexp || newInside != inside) 64 | setState(jsTokenState(newInside, newRegexp)); 65 | return type; 66 | }; 67 | } 68 | 69 | // The token reader, intended to be used by the tokenizer from 70 | // tokenize.js (through jsTokenState). Advances the source stream 71 | // over a token, and returns an object containing the type and style 72 | // of that token. 73 | function jsToken(inside, regexp, source, setInside) { 74 | function readHexNumber(){ 75 | source.next(); // skip the 'x' 76 | source.nextWhileMatches(isHexDigit); 77 | return {type: "number", style: "js-atom"}; 78 | } 79 | 80 | function readNumber() { 81 | source.nextWhileMatches(/[0-9]/); 82 | if (source.equals(".")){ 83 | source.next(); 84 | source.nextWhileMatches(/[0-9]/); 85 | } 86 | if (source.equals("e") || source.equals("E")){ 87 | source.next(); 88 | if (source.equals("-")) 89 | source.next(); 90 | source.nextWhileMatches(/[0-9]/); 91 | } 92 | return {type: "number", style: "js-atom"}; 93 | } 94 | // Read a word, look it up in keywords. If not found, it is a 95 | // variable, otherwise it is a keyword of the type found. 96 | function readWord() { 97 | source.nextWhileMatches(isWordChar); 98 | var word = source.get(); 99 | var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word]; 100 | return known ? {type: known.type, style: known.style, content: word} : 101 | {type: "variable", style: "js-variable", content: word}; 102 | } 103 | function readRegexp() { 104 | nextUntilUnescaped(source, "/"); 105 | source.nextWhileMatches(/[gi]/); 106 | return {type: "regexp", style: "js-string"}; 107 | } 108 | // Mutli-line comments are tricky. We want to return the newlines 109 | // embedded in them as regular newline tokens, and then continue 110 | // returning a comment token for every line of the comment. So 111 | // some state has to be saved (inside) to indicate whether we are 112 | // inside a /* */ sequence. 113 | function readMultilineComment(start){ 114 | var newInside = "/*"; 115 | var maybeEnd = (start == "*"); 116 | while (true) { 117 | if (source.endOfLine()) 118 | break; 119 | var next = source.next(); 120 | if (next == "/" && maybeEnd){ 121 | newInside = null; 122 | break; 123 | } 124 | maybeEnd = (next == "*"); 125 | } 126 | setInside(newInside); 127 | return {type: "comment", style: "js-comment"}; 128 | } 129 | function readMultilineString(start, quotes) { 130 | var newInside = quotes; 131 | var quote = quotes.charAt(0); 132 | var maybeEnd = (start == quote); 133 | while (true) { 134 | if (source.endOfLine()) 135 | break; 136 | var next = source.next(); 137 | if (next == quote && source.peek() == quote && maybeEnd) { 138 | source.next(); 139 | newInside = null; 140 | break; 141 | } 142 | maybeEnd = (next == quote); 143 | } 144 | setInside(newInside); 145 | return {type: "multilineString", style: "js-string"}; 146 | } 147 | function readOperator() { 148 | source.nextWhileMatches(isOperatorChar); 149 | return {type: "operator", style: "js-operator"}; 150 | } 151 | function readString(quote) { 152 | var endBackSlash = nextUntilUnescaped(source, quote); 153 | setInside(endBackSlash ? quote : null); 154 | return {type: "string", style: "js-string"}; 155 | } 156 | function readOmetaIdentifierString() { 157 | source.nextWhileMatches(isWordChar); 158 | return {type: "string", style: "js-string"}; 159 | } 160 | function readOmetaBinding() { 161 | source.nextWhileMatches(isWordChar); 162 | return {type: "variable", style: "ometa-binding"}; 163 | } 164 | 165 | // Fetch the next token. Dispatches on first character in the 166 | // stream, or first two characters when the first is a slash. 167 | if (inside == "\"" || inside == "'") 168 | return readString(inside); 169 | var ch = source.next(); 170 | if (inside == "/*") 171 | return readMultilineComment(ch); 172 | if (inside == '"""' || inside == "'''") 173 | return readMultilineString(ch, inside); 174 | if (ch == '"' && source.lookAhead('""', true) || ch == "'" && source.lookAhead("''", true)) 175 | return readMultilineString('-', ch+ch+ch); // work as far as '-' is not '"' nor "'" 176 | else if (ch == "\"" || ch == "'") 177 | return readString(ch); 178 | else if (ch == "`" || ch == "#" ) 179 | return readOmetaIdentifierString(); 180 | else if (ch == ':' && isWordChar.test(source.peek())) 181 | return readOmetaBinding(); 182 | // with punctuation, the type of the token is the symbol itself 183 | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) 184 | return {type: ch, style: "js-punctuation"}; 185 | else if (ch == "0" && (source.equals("x") || source.equals("X"))) 186 | return readHexNumber(); 187 | else if (/[0-9]/.test(ch)) 188 | return readNumber(); 189 | else if (ch == "/"){ 190 | if (source.equals("*")) 191 | { source.next(); return readMultilineComment(ch); } 192 | else if (source.equals("/")) 193 | { nextUntilUnescaped(source, null); return {type: "comment", style: "js-comment"};} 194 | else if (regexp) 195 | return readRegexp(); 196 | else 197 | return readOperator(); 198 | } 199 | else if (isOperatorChar.test(ch)) 200 | return readOperator(); 201 | else 202 | return readWord(); 203 | } 204 | 205 | // The external interface to the tokenizer. 206 | return function(source, startState) { 207 | return tokenizer(source, startState || jsTokenState(false, true)); 208 | }; 209 | })(); 210 | -------------------------------------------------------------------------------- /contrib/php/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2009, Yahoo! Inc. 2 | All rights reserved. 3 | 4 | This software is provided for use in connection with the 5 | CodeMirror suite of modules and utilities, hosted and maintained 6 | at http://codemirror.net/. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | * Neither the name of Yahoo! Inc. nor the names of its 22 | contributors may be used to endorse or promote products 23 | derived from this software without specific prior 24 | written permission of Yahoo! Inc. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 29 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 30 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 31 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 32 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 36 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 | POSSIBILITY OF SUCH DAMAGE. 38 | -------------------------------------------------------------------------------- /contrib/php/css/phpcolors.css: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved. 3 | The copyrights embodied in the content of this file are licensed by 4 | Yahoo! Inc. under the BSD (revised) open source license 5 | 6 | @author Dan Vlad Dascalescu 7 | */ 8 | 9 | html { 10 | cursor: text; 11 | } 12 | 13 | .editbox { 14 | margin: .4em; 15 | padding: 0; 16 | font-family: monospace; 17 | font-size: 10pt; 18 | } 19 | 20 | /*We should define specific styles for every element of the syntax. 21 | the setting below will cause some annoying color to show through if we missed 22 | defining a style for a token. This is also the "color" of the whitespace and 23 | of the cursor. 24 | */ 25 | pre.code, .editbox { 26 | color: red; 27 | } 28 | 29 | .editbox p { 30 | margin: 0; 31 | } 32 | 33 | span.php-punctuation { 34 | color: blue; 35 | } 36 | 37 | span.php-keyword { 38 | color: #770088; 39 | font-weight: bold; 40 | } 41 | 42 | span.php-operator { 43 | color: blue; 44 | } 45 | 46 | /* __FILE__ etc.; http://php.net/manual/en/reserved.php */ 47 | span.php-compile-time-constant { 48 | color: #776088; 49 | font-weight: bold; 50 | } 51 | 52 | /* output of get_defined_constants(). Differs from http://php.net/manual/en/reserved.constants.php */ 53 | span.php-predefined-constant { 54 | color: darkgreen; 55 | font-weight: bold; 56 | } 57 | 58 | /* PHP reserved "language constructs"... echo() etc.; http://php.net/manual/en/reserved.php */ 59 | span.php-reserved-language-construct { 60 | color: green; 61 | font-weight: bold; 62 | } 63 | 64 | /* PHP built-in functions: glob(), chr() etc.; output of get_defined_functions()["internal"] */ 65 | span.php-predefined-function { 66 | color: green; 67 | } 68 | 69 | /* PHP predefined classes: PDO, Exception etc.; output of get_declared_classes() and different from http://php.net/manual/en/reserved.classes.php */ 70 | span.php-predefined-class { 71 | color: green; 72 | } 73 | 74 | span.php-atom { 75 | color: #228811; 76 | } 77 | 78 | /* class, interface, namespace or function names, but not $variables */ 79 | span.php-t_string { 80 | color: black; 81 | } 82 | 83 | span.php-variable { 84 | color: black; 85 | font-weight: bold; 86 | } 87 | 88 | 89 | span.js-localvariable { 90 | color: #004499; 91 | } 92 | 93 | span.php-comment { 94 | color: #AA7700; 95 | font-stretch: condensed; 96 | /* font-style: italic; This causes line height to slightly change, getting line numbers out of sync */ 97 | } 98 | 99 | span.php-string-single-quoted { 100 | color: #AA2222; 101 | } 102 | /* double quoted strings allow interpolation */ 103 | span.php-string-double-quoted { 104 | color: #AA2222; 105 | font-weight: bold; 106 | } 107 | 108 | span.syntax-error { 109 | background-color: red; 110 | } 111 | 112 | span.deprecated { 113 | font-size: smaller; 114 | } 115 | -------------------------------------------------------------------------------- /contrib/php/js/parsephphtmlmixed.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2009 Yahoo! Inc. All rights reserved. 3 | The copyrights embodied in the content of this file are licensed by 4 | Yahoo! Inc. under the BSD (revised) open source license 5 | 6 | @author Dan Vlad Dascalescu 7 | 8 | Based on parsehtmlmixed.js by Marijn Haverbeke. 9 | */ 10 | 11 | var PHPHTMLMixedParser = Editor.Parser = (function() { 12 | var processingInstructions = [""); 36 | break; 37 | } 38 | } 39 | else if (token.style == "xml-attribute" && token.content == "\"php\"" && inTag == "script" && lastAtt == "language") 40 | inTag = "script/php"; 41 | // "xml-processing" tokens are ignored, because they should be handled by a specific local parser 42 | else if (token.content == ">") { 43 | if (inTag == "script/php") 44 | iter.next = local(PHPParser, ""); 45 | else if (inTag == "script") 46 | iter.next = local(JSParser, " 2 | 3 | 4 | CodeMirror: PLSQL demonstration 5 | 6 | 7 | 8 | 9 |

Demonstration of CodeMirror's PLSQL 10 | highlighter.

11 | 12 |

Written by Peter Raganitsch (license), based 13 | on John Benediktsson SQL parser.

14 | 15 |
16 | 54 |
55 | 56 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /contrib/plsql/js/parseplsql.js: -------------------------------------------------------------------------------- 1 | var PlsqlParser = Editor.Parser = (function() { 2 | 3 | function wordRegexp(words) { 4 | return new RegExp("^(?:" + words.join("|") + ")$", "i"); 5 | } 6 | 7 | var functions = wordRegexp([ 8 | "abs","acos","add_months","ascii","asin","atan","atan2","average", 9 | "bfilename", 10 | "ceil","chartorowid","chr","concat","convert","cos","cosh","count", 11 | "decode","deref","dual","dump","dup_val_on_index", 12 | "empty","error","exp", 13 | "false","floor","found", 14 | "glb","greatest", 15 | "hextoraw", 16 | "initcap","instr","instrb","isopen", 17 | "last_day","least","lenght","lenghtb","ln","lower","lpad","ltrim","lub", 18 | "make_ref","max","min","mod","months_between", 19 | "new_time","next_day","nextval","nls_charset_decl_len","nls_charset_id","nls_charset_name","nls_initcap","nls_lower", 20 | "nls_sort","nls_upper","nlssort","no_data_found","notfound","null","nvl", 21 | "others", 22 | "power", 23 | "rawtohex","reftohex","round","rowcount","rowidtochar","rpad","rtrim", 24 | "sign","sin","sinh","soundex","sqlcode","sqlerrm","sqrt","stddev","substr","substrb","sum","sysdate", 25 | "tan","tanh","to_char","to_date","to_label","to_multi_byte","to_number","to_single_byte","translate","true","trunc", 26 | "uid","upper","user","userenv", 27 | "variance","vsize" 28 | 29 | ]); 30 | 31 | var keywords = wordRegexp([ 32 | "abort","accept","access","add","all","alter","and","any","array","arraylen","as","asc","assert","assign","at","attributes","audit", 33 | "authorization","avg", 34 | "base_table","begin","between","binary_integer","body","boolean","by", 35 | "case","cast","char","char_base","check","close","cluster","clusters","colauth","column","comment","commit","compress","connect", 36 | "connected","constant","constraint","crash","create","current","currval","cursor", 37 | "data_base","database","date","dba","deallocate","debugoff","debugon","decimal","declare","default","definition","delay","delete", 38 | "desc","digits","dispose","distinct","do","drop", 39 | "else","elsif","enable","end","entry","escape","exception","exception_init","exchange","exclusive","exists","exit","external", 40 | "fast","fetch","file","for","force","form","from","function", 41 | "generic","goto","grant","group", 42 | "having", 43 | "identified","if","immediate","in","increment","index","indexes","indicator","initial","initrans","insert","interface","intersect", 44 | "into","is", 45 | "key", 46 | "level","library","like","limited","local","lock","log","logging","long","loop", 47 | "master","maxextents","maxtrans","member","minextents","minus","mislabel","mode","modify","multiset", 48 | "new","next","no","noaudit","nocompress","nologging","noparallel","not","nowait","number_base", 49 | "object","of","off","offline","on","online","only","open","option","or","order","out", 50 | "package","parallel","partition","pctfree","pctincrease","pctused","pls_integer","positive","positiven","pragma","primary","prior", 51 | "private","privileges","procedure","public", 52 | "raise","range","raw","read","rebuild","record","ref","references","refresh","release","rename","replace","resource","restrict","return", 53 | "returning","reverse","revoke","rollback","row","rowid","rowlabel","rownum","rows","run", 54 | "savepoint","schema","segment","select","separate","session","set","share","snapshot","some","space","split","sql","start","statement", 55 | "storage","subtype","successful","synonym", 56 | "tabauth","table","tables","tablespace","task","terminate","then","to","trigger","truncate","type", 57 | "union","unique","unlimited","unrecoverable","unusable","update","use","using", 58 | "validate","value","values","variable","view","views", 59 | "when","whenever","where","while","with","work" 60 | ]); 61 | 62 | var types = wordRegexp([ 63 | "bfile","blob", 64 | "character","clob", 65 | "dec", 66 | "float", 67 | "int","integer", 68 | "mlslabel", 69 | "natural","naturaln","nchar","nclob","number","numeric","nvarchar2", 70 | "real","rowtype", 71 | "signtype","smallint","string", 72 | "varchar","varchar2" 73 | ]); 74 | 75 | var operators = wordRegexp([ 76 | ":=", "<", "<=", "==", "!=", "<>", ">", ">=", "like", "rlike", "in", "xor", "between" 77 | ]); 78 | 79 | var operatorChars = /[*+\-<>=&|:\/]/; 80 | 81 | var tokenizeSql = (function() { 82 | function normal(source, setState) { 83 | var ch = source.next(); 84 | if (ch == "@" || ch == "$") { 85 | source.nextWhileMatches(/[\w\d]/); 86 | return "plsql-var"; 87 | } 88 | else if (ch == "\"" || ch == "'" || ch == "`") { 89 | setState(inLiteral(ch)); 90 | return null; 91 | } 92 | else if (ch == "," || ch == ";") { 93 | return "plsql-separator" 94 | } 95 | else if (ch == '-') { 96 | if (source.peek() == "-") { 97 | while (!source.endOfLine()) source.next(); 98 | return "plsql-comment"; 99 | } 100 | else if (/\d/.test(source.peek())) { 101 | source.nextWhileMatches(/\d/); 102 | if (source.peek() == '.') { 103 | source.next(); 104 | source.nextWhileMatches(/\d/); 105 | } 106 | return "plsql-number"; 107 | } 108 | else 109 | return "plsql-operator"; 110 | } 111 | else if (operatorChars.test(ch)) { 112 | source.nextWhileMatches(operatorChars); 113 | return "plsql-operator"; 114 | } 115 | else if (/\d/.test(ch)) { 116 | source.nextWhileMatches(/\d/); 117 | if (source.peek() == '.') { 118 | source.next(); 119 | source.nextWhileMatches(/\d/); 120 | } 121 | return "plsql-number"; 122 | } 123 | else if (/[()]/.test(ch)) { 124 | return "plsql-punctuation"; 125 | } 126 | else { 127 | source.nextWhileMatches(/[_\w\d]/); 128 | var word = source.get(), type; 129 | if (operators.test(word)) 130 | type = "plsql-operator"; 131 | else if (keywords.test(word)) 132 | type = "plsql-keyword"; 133 | else if (functions.test(word)) 134 | type = "plsql-function"; 135 | else if (types.test(word)) 136 | type = "plsql-type"; 137 | else 138 | type = "plsql-word"; 139 | return {style: type, content: word}; 140 | } 141 | } 142 | 143 | function inLiteral(quote) { 144 | return function(source, setState) { 145 | var escaped = false; 146 | while (!source.endOfLine()) { 147 | var ch = source.next(); 148 | if (ch == quote && !escaped) { 149 | setState(normal); 150 | break; 151 | } 152 | escaped = !escaped && ch == "\\"; 153 | } 154 | return quote == "`" ? "plsql-word" : "plsql-literal"; 155 | }; 156 | } 157 | 158 | return function(source, startState) { 159 | return tokenizer(source, startState || normal); 160 | }; 161 | })(); 162 | 163 | function indentSql(context) { 164 | return function(nextChars) { 165 | var firstChar = nextChars && nextChars.charAt(0); 166 | var closing = context && firstChar == context.type; 167 | if (!context) 168 | return 0; 169 | else if (context.align) 170 | return context.col - (closing ? context.width : 0); 171 | else 172 | return context.indent + (closing ? 0 : indentUnit); 173 | } 174 | } 175 | 176 | function parseSql(source) { 177 | var tokens = tokenizeSql(source); 178 | var context = null, indent = 0, col = 0; 179 | function pushContext(type, width, align) { 180 | context = {prev: context, indent: indent, col: col, type: type, width: width, align: align}; 181 | } 182 | function popContext() { 183 | context = context.prev; 184 | } 185 | 186 | var iter = { 187 | next: function() { 188 | var token = tokens.next(); 189 | var type = token.style, content = token.content, width = token.value.length; 190 | 191 | if (content == "\n") { 192 | token.indentation = indentSql(context); 193 | indent = col = 0; 194 | if (context && context.align == null) context.align = false; 195 | } 196 | else if (type == "whitespace" && col == 0) { 197 | indent = width; 198 | } 199 | else if (!context && type != "plsql-comment") { 200 | pushContext(";", 0, false); 201 | } 202 | 203 | if (content != "\n") col += width; 204 | 205 | if (type == "plsql-punctuation") { 206 | if (content == "(") 207 | pushContext(")", width); 208 | else if (content == ")") 209 | popContext(); 210 | } 211 | else if (type == "plsql-separator" && content == ";" && context && !context.prev) { 212 | popContext(); 213 | } 214 | 215 | return token; 216 | }, 217 | 218 | copy: function() { 219 | var _context = context, _indent = indent, _col = col, _tokenState = tokens.state; 220 | return function(source) { 221 | tokens = tokenizeSql(source, _tokenState); 222 | context = _context; 223 | indent = _indent; 224 | col = _col; 225 | return iter; 226 | }; 227 | } 228 | }; 229 | return iter; 230 | } 231 | 232 | return {make: parseSql, electricChars: ")"}; 233 | })(); 234 | -------------------------------------------------------------------------------- /contrib/python/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009, Timothy Farrell 2 | All rights reserved. 3 | 4 | This software is provided for use in connection with the 5 | CodeMirror suite of modules and utilities, hosted and maintained 6 | at http://codemirror.net/. 7 | 8 | Redistribution and use of this software in source and binary forms, 9 | with or without modification, are permitted provided that the 10 | following conditions are met: 11 | 12 | * Redistributions of source code must retain the above 13 | copyright notice, this list of conditions and the 14 | following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above 17 | copyright notice, this list of conditions and the 18 | following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 | POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /contrib/python/css/pythoncolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | padding: .4em; 7 | margin: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | line-height: 1.1em; 11 | color: black; 12 | } 13 | 14 | pre.code, .editbox { 15 | color: #666666; 16 | } 17 | 18 | .editbox p { 19 | margin: 0; 20 | } 21 | 22 | span.py-delimiter, span.py-special { 23 | color: #666666; 24 | } 25 | 26 | span.py-operator { 27 | color: #666666; 28 | } 29 | 30 | span.py-error { 31 | background-color: #660000; 32 | color: #FFFFFF; 33 | } 34 | 35 | span.py-keyword { 36 | color: #770088; 37 | font-weight: bold; 38 | } 39 | 40 | span.py-literal { 41 | color: #228811; 42 | } 43 | 44 | span.py-identifier, span.py-func { 45 | color: black; 46 | } 47 | 48 | span.py-type, span.py-decorator { 49 | color: #0000FF; 50 | } 51 | 52 | span.py-comment { 53 | color: #AA7700; 54 | } 55 | 56 | span.py-string, span.py-bytes, span.py-raw, span.py-unicode { 57 | color: #AA2222; 58 | } 59 | -------------------------------------------------------------------------------- /contrib/python/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: Python demonstration 5 | 18 | 19 | 20 |

21 | This is a simple demonstration of the Python syntax highlighting module 22 | for CodeMirror. 23 |

24 |

25 | Features of this parser include: 26 |

27 | 37 |

Written by Timothy Farrell (license). Special 38 | thanks to Adam Brand and Marijn Haverbeke for their help in debugging 39 | and providing for this parser.

40 | 41 |
42 | 127 |
128 | 129 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /contrib/regex/css/js-regexcolors.css: -------------------------------------------------------------------------------- 1 | /*///////////////////////////////*/ 2 | html { 3 | cursor: text; 4 | } 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | .editbox p { 13 | margin: 0; 14 | } 15 | 16 | html, body { 17 | background: #cccccc !important; 18 | } 19 | 20 | /*///////////////////////////////*/ 21 | /* Inside character classes */ 22 | span.regex-class-special-escape { 23 | color: Coral; 24 | } 25 | span.regex-class-begin, span.regex-class-end { 26 | color: YellowGreen; 27 | } 28 | span.regex-class-negator { 29 | color: Wheat; 30 | } 31 | span.regex-class-range-hyphen { 32 | color: Turquoise; 33 | } 34 | span.regex-class-final-hyphen { 35 | color: Violet; 36 | } 37 | 38 | /*///////////////////////////////*/ 39 | /* Inside character classes (suffixable by -begin-range or -end-range if beginning or ending a range) */ 40 | span.regex-unicode-class-inside { 41 | color: Tomato; 42 | } 43 | span.regex-class-initial-hyphen { 44 | color: Teal; 45 | } 46 | span.regex-class-character { 47 | color: Tan; 48 | } 49 | span.regex-class-octal { 50 | color: SteelBlue; 51 | } 52 | span.regex-class-hex { 53 | color: SpringGreen; 54 | } 55 | span.regex-class-unicode-escape { 56 | color: SlateGray; 57 | } 58 | span.regex-class-ascii-control { 59 | color: SlateBlue; 60 | } 61 | span.regex-class-extra-escaped { 62 | color: SkyBlue; 63 | } 64 | span.regex-class-escaped-special { 65 | color: CornflowerBlue; 66 | } 67 | 68 | /*///////////////////////////////*/ 69 | span.class-special-escape-begin-range, span.class-special-escape-end-range { 70 | color: Brown; 71 | } 72 | span.regex-unicode-class-inside-begin-range, span.regex-unicode-class-inside-end-range { 73 | color: Silver; 74 | } 75 | span.regex-class-initial-hyphen-begin-range, span.regex-class-initial-hyphen-end-range { 76 | color: SeaGreen; 77 | } 78 | span.regex-class-character-begin-range, span.regex-class-character-end-range { 79 | color: SandyBrown; 80 | } 81 | span.regex-class-octal-begin-range, span.regex-class-octal-end-range { 82 | color: Salmon; 83 | } 84 | span.regex-class-hex-begin-range, span.regex-class-hex-end-range { 85 | color: SaddleBrown; 86 | } 87 | span.regex-class-unicode-escape-begin-range, span.regex-class-unicode-escape-end-range { 88 | color: RoyalBlue; 89 | } 90 | span.regex-class-ascii-control-begin-range, span.regex-class-ascii-control-end-range { 91 | color: RosyBrown; 92 | } 93 | span.regex-class-extra-escaped-begin-range, span.regex-class-extra-escaped-end-range { 94 | color: Orange; 95 | } 96 | span.regex-class-escaped-special-begin-range, span.regex-class-escaped-special-end-range { 97 | color: DarkKhaki; 98 | } 99 | 100 | 101 | /*///////////////////////////////*/ 102 | /* Outside character classes */ 103 | span.regex-special-escape { 104 | color: Chocolate; 105 | } 106 | span.regex-escaped-special { 107 | color: Orange; 108 | } 109 | span.regex-alternator { 110 | color: darkpink; 111 | } 112 | span.regex-unicode-class-outside { 113 | color: Green; 114 | } 115 | span.regex-octal { 116 | color: MediumVioletRed; 117 | } 118 | span.regex-ascii { 119 | color: MediumTurquoise; 120 | } 121 | span.regex-hex { 122 | color: MediumSpringGreen; 123 | } 124 | span.regex-unicode-escape { 125 | color:pink; 126 | } 127 | span.regex-ascii-control { 128 | color: MediumSlateBlue; 129 | } 130 | span.regex-extra-escaped { 131 | color: MediumSeaGreen; 132 | } 133 | span.regex-quantifier-escape { 134 | color: Azure; 135 | } 136 | span.regex-quantifiers { 137 | color: MediumPurple; 138 | } 139 | span.regex-repetition { 140 | color: MediumOrchid; 141 | } 142 | span.regex-literal-begin, span.regex-literal-end { 143 | color: MediumBlue; 144 | } 145 | span.regex-character { 146 | color: Navy; 147 | } 148 | 149 | /*///////////////////////////////*/ 150 | /* Literals/Surrounding characters */ 151 | span.regex-flags { 152 | color: Green; 153 | } 154 | 155 | /*///////////////////////////////*/ 156 | /* Optional outside character class features*/ 157 | span.regex-empty-class { 158 | color: Lime; 159 | } 160 | span.regex-named-backreference { 161 | color: LightSlateGray; 162 | } 163 | span.regex-free-spacing-mode { 164 | background-color: LightSeaGreen; 165 | } 166 | span.regex-mode-modifier { 167 | color: LightSalmon; 168 | } 169 | span.regex-comment-pattern { 170 | color: LightGreen; 171 | } 172 | span.regex-capturing-group, span.regex-ending-capturing-group { 173 | color: LightGray; 174 | } 175 | span.regex-named-capturing-group, span.regex-ending-named-capturing-group { 176 | color: LightCoral; 177 | } 178 | span.regex-group, span.regex-ending-group { 179 | color: LawnGreen; 180 | } 181 | 182 | 183 | span.regex-capturing-group1-1, span.regex-ending-capturing-group1-1 { 184 | background-color: red; 185 | } 186 | span.regex-capturing-group1-2, span.regex-ending-capturing-group1-2 { 187 | background-color: orange; 188 | } 189 | span.regex-capturing-group2-1, span.regex-ending-capturing-group2-1 { 190 | background-color: yellow; 191 | } 192 | span.regex-capturing-group2-2, span.regex-ending-capturing-group2-2 { 193 | background-color: green; 194 | } 195 | 196 | /*///////////////////////////////*/ 197 | /* Closing parentheses without opening, etc. */ 198 | span.regex-bad-character, span.regex-bad-sequence { 199 | color: red; 200 | } 201 | 202 | /* Used if "uniform" inner_group_mode is used */ 203 | span.regex-group-1-1 { 204 | background-color: blue; 205 | } 206 | span.regex-group-1-2 { 207 | background-color: green; 208 | } 209 | span.regex-group-2-1 { 210 | background-color: pink; 211 | } 212 | span.regex-group-2-2 { 213 | background-color: yellow; 214 | } 215 | -------------------------------------------------------------------------------- /contrib/regex/css/regexcolors.css: -------------------------------------------------------------------------------- 1 | /*///////////////////////////////*/ 2 | html { 3 | cursor: text; 4 | } 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | .editbox p { 13 | margin: 0; 14 | } 15 | 16 | html, body { 17 | background: #555555 !important; 18 | } 19 | 20 | /*///////////////////////////////*/ 21 | /* Inside character classes */ 22 | span.regex-class-special-escape { 23 | color: Coral; 24 | } 25 | span.regex-class-begin, span.regex-class-end { 26 | color: YellowGreen; 27 | } 28 | span.regex-class-negator { 29 | color: Wheat; 30 | } 31 | span.regex-class-range-hyphen { 32 | color: Turquoise; 33 | } 34 | span.regex-class-final-hyphen { 35 | color: Violet; 36 | } 37 | 38 | /*///////////////////////////////*/ 39 | /* Inside character classes (suffixable by -begin-range or -end-range if beginning or ending a range) */ 40 | span.regex-unicode-class-inside { 41 | color: Tomato; 42 | } 43 | span.regex-class-initial-hyphen { 44 | color: Teal; 45 | } 46 | span.regex-class-character { 47 | color: Tan; 48 | } 49 | span.regex-class-octal { 50 | color: SteelBlue; 51 | } 52 | span.regex-class-hex { 53 | color: SpringGreen; 54 | } 55 | span.regex-class-unicode-escape { 56 | color: LightGray; 57 | } 58 | span.regex-class-ascii-control { 59 | color: SlateBlue; 60 | } 61 | span.regex-class-extra-escaped { 62 | color: SkyBlue; 63 | } 64 | span.regex-class-escaped-special { 65 | color: CornflowerBlue; 66 | } 67 | 68 | /*///////////////////////////////*/ 69 | span.class-special-escape-begin-range, span.class-special-escape-end-range { 70 | color: Brown; 71 | } 72 | span.regex-unicode-class-inside-begin-range, span.regex-unicode-class-inside-end-range { 73 | color: Silver; 74 | } 75 | span.regex-class-initial-hyphen-begin-range, span.regex-class-initial-hyphen-end-range { 76 | color: SeaGreen; 77 | } 78 | span.regex-class-character-begin-range, span.regex-class-character-end-range { 79 | color: SandyBrown; 80 | } 81 | span.regex-class-octal-begin-range, span.regex-class-octal-end-range { 82 | color: Salmon; 83 | } 84 | span.regex-class-hex-begin-range, span.regex-class-hex-end-range { 85 | color: Tan; 86 | } 87 | span.regex-class-unicode-escape-begin-range, span.regex-class-unicode-escape-end-range { 88 | color: LightBlue; 89 | } 90 | span.regex-class-ascii-control-begin-range, span.regex-class-ascii-control-end-range { 91 | color: RosyBrown; 92 | } 93 | span.regex-class-extra-escaped-begin-range, span.regex-class-extra-escaped-end-range { 94 | color: Orange; 95 | } 96 | span.regex-class-escaped-special-begin-range, span.regex-class-escaped-special-end-range { 97 | color: DarkKhaki; 98 | } 99 | 100 | 101 | /*///////////////////////////////*/ 102 | /* Outside character classes */ 103 | span.regex-special-escape { 104 | color: Chocolate; 105 | } 106 | span.regex-escaped-special { 107 | color: Orange; 108 | } 109 | span.regex-alternator { 110 | color: BurlyWood; 111 | } 112 | span.regex-unicode-class-outside { 113 | color: Gold; 114 | } 115 | span.regex-octal { 116 | color: MediumVioletRed; 117 | } 118 | span.regex-ascii { 119 | color: MediumTurquoise; 120 | } 121 | span.regex-hex { 122 | color: MediumSpringGreen; 123 | } 124 | span.regex-unicode-escape { 125 | color:pink; 126 | } 127 | span.regex-ascii-control { 128 | color: MediumSlateBlue; 129 | } 130 | span.regex-extra-escaped { 131 | color: MediumSeaGreen; 132 | } 133 | span.regex-quantifier-escape { 134 | color: Azure; 135 | } 136 | span.regex-quantifiers { 137 | color: MediumPurple; 138 | } 139 | span.regex-repetition { 140 | color: MediumOrchid; 141 | } 142 | span.regex-literal-begin, span.regex-literal-end { 143 | color: MediumBlue; 144 | } 145 | span.regex-character { 146 | color: #FFFFAA; 147 | } 148 | 149 | /*///////////////////////////////*/ 150 | /* Literals/Surrounding characters */ 151 | span.regex-flags { 152 | color: LimeGreen; 153 | } 154 | 155 | /*///////////////////////////////*/ 156 | /* Optional outside character class features*/ 157 | span.regex-empty-class { 158 | color: Lime; 159 | } 160 | span.regex-named-backreference { 161 | color: LightSlateGray; 162 | } 163 | span.regex-free-spacing-mode { 164 | background-color: LightSeaGreen; 165 | } 166 | span.regex-mode-modifier { 167 | color: LightSalmon; 168 | } 169 | span.regex-comment-pattern { 170 | color: LightGreen; 171 | } 172 | span.regex-capturing-group, span.regex-ending-capturing-group { 173 | color: LightGray; 174 | } 175 | span.regex-named-capturing-group, span.regex-ending-named-capturing-group { 176 | color: LightCoral; 177 | } 178 | span.regex-group, span.regex-ending-group { 179 | color: LawnGreen; 180 | } 181 | 182 | 183 | span.regex-capturing-group1-1, span.regex-ending-capturing-group1-1 { 184 | background-color: red; 185 | } 186 | span.regex-capturing-group1-2, span.regex-ending-capturing-group1-2 { 187 | background-color: orange; 188 | } 189 | span.regex-capturing-group2-1, span.regex-ending-capturing-group2-1 { 190 | background-color: yellow; 191 | } 192 | span.regex-capturing-group2-2, span.regex-ending-capturing-group2-2 { 193 | background-color: green; 194 | } 195 | 196 | /*///////////////////////////////*/ 197 | /* Closing parentheses without opening, etc. */ 198 | span.regex-bad-character, span.regex-bad-sequence { 199 | color: red; 200 | } 201 | 202 | /* Used if "uniform" inner_group_mode is used */ 203 | span.regex-group-1-1 { 204 | color: lightblue; 205 | } 206 | span.regex-group-1-2 { 207 | color: lightgreen; 208 | } 209 | span.regex-group-2-1 { 210 | color: pink; 211 | } 212 | span.regex-group-2-2 { 213 | color: yellow; 214 | } 215 | -------------------------------------------------------------------------------- /contrib/regex/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror Regex Highlighting 5 | 6 | 90 | 91 | 92 | 93 |
94 |

CodeMirror Regex Code Editor Demonstration

95 |

The Regex parser for CodeMirror allows syntax coloring on regular expressions with some beginning customizability by 96 | Regex flavor/language. For integrating styling of regular expression literals into JavaScript syntax highlighting, see this 97 | JavaScript+Regex Demo.

98 |

Styling ability is fine-grained, so any token should be distinctly stylable if so desired. Parenthetical groups can 99 | be styled with the same styles for inner content, and the script also enables styling by nesting depth and sequence, 100 | including by imposing a limit such that styles will alternate.

101 |

Information can also be passed on (especially when the parseregex-unicode.js file is included) for use in CodeMirror's 102 | activeTokens argument such as demonstrated below by tooltips which show which characters are present in a given 103 | range or Unicode class.

104 |

Note that this editor does not support free-spacing mode, so it is not recommended to use multiple lines for input, but 105 | for demonstration purposes, multiple lines are shown.

106 | 111 | 112 |
113 | 114 | 115 | -------------------------------------------------------------------------------- /contrib/regex/js-regex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror Regex Highlighting 5 | 6 | 94 | 95 | 96 | 97 |
98 |

CodeMirror JavaScript-Integrated Regex Code Editor Demonstration

99 |

This demonstrates a parser in the regex folder which wraps the regular CodeMirror JavaScript editor and adds syntax coloring to 100 | regular expression literals in JavaScript.

101 | 105 | 106 |

While the above styles by depth or sequence no matter the grouping type, this parser also allows styling distinctly by grouping type (capturing, named, non-capturing), while also still allowing alternating of colors within a type.

107 | 111 |

One may also simply turn off the styling of content inside groups, allowing only individual tokens to be styled per the stylesheet (though the parentheses tokens themselves can still indicate depth or sequence):

112 | 116 |
117 | 118 | 119 | -------------------------------------------------------------------------------- /contrib/regex/js/parsejavascript_and_regex.js: -------------------------------------------------------------------------------- 1 | // See the dependencies parsejavascript.js and parseregex.js (optionally with parseregex-unicode.js) for options 2 | 3 | var JSAndRegexParser = Editor.Parser = (function() { 4 | // Parser 5 | var run = function () {}, 6 | regexParser, jsParser, lastRegexSrc, 7 | regexPG = {}, jsPG = {}; 8 | 9 | function simpleStream (s) { 10 | var str = s, pos = 0; 11 | return { 12 | next : function () { 13 | if (pos >= str.length) { 14 | throw StopIteration; 15 | } 16 | return str.charAt(pos++); 17 | } 18 | }; 19 | } 20 | 21 | function regex () { 22 | var token; 23 | try { 24 | token = regexParser.next(); 25 | } 26 | catch(e) { 27 | _setState(js); 28 | return js(); 29 | } 30 | _setState(regex); 31 | return token; 32 | } 33 | function js () { 34 | var token = jsParser.next(); 35 | if (token.type === 'regexp') { 36 | lastRegexSrc = stringStream(simpleStream(token.content)); 37 | regexParser = RegexParser.make(lastRegexSrc); 38 | return regex(); 39 | } 40 | return token; 41 | } 42 | 43 | function _setState (func) { 44 | run = func; 45 | } 46 | 47 | function parseJSAndRegex (stream, basecolumn) { 48 | JSParser.configure(jsPG); 49 | RegexParser.configure(regexPG); 50 | jsParser = JSParser.make(stream, basecolumn); 51 | _setState(js); 52 | 53 | var iter = { 54 | next: function() { 55 | return run(stream); 56 | }, 57 | copy: function() { 58 | var _run = run, _lastRegexSrc = lastRegexSrc, 59 | _jsParser = jsParser.copy(), 60 | _regexParser = regexParser && regexParser.copy(); 61 | 62 | return function (_stream) { 63 | stream = _stream; 64 | jsParser = _jsParser(_stream); 65 | regexParser = _regexParser && _regexParser(_lastRegexSrc); 66 | run = _run; 67 | return iter; 68 | }; 69 | } 70 | }; 71 | return iter; 72 | } 73 | 74 | // Parser object 75 | return { 76 | make: parseJSAndRegex, 77 | configure: function (parserConfig) { 78 | for (var opt in parserConfig) { 79 | if ((/^regex_/).test(opt)) { 80 | regexPG[opt.replace(/^regex_/, '')] = parserConfig[opt]; 81 | } 82 | else { // Doesn't need a js- prefix, but we'll strip if it does 83 | jsPG[opt.replace(/^js_/, '')] = parserConfig[opt]; 84 | } 85 | } 86 | regexPG.flavor = regexPG.flavor || 'ecma-262-ed3'; // Allow ed5, etc. if specified 87 | regexPG.literal = true; // This is only for literals, since can't easily detect whether will be used for RegExp 88 | regexPG.literal_initial = '/'; // Ensure it's always this for JavaScript regex literals 89 | } 90 | }; 91 | })(); 92 | -------------------------------------------------------------------------------- /contrib/scheme/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010 Danny Yoo 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any 5 | damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any 8 | purpose, including commercial applications, and to alter it and 9 | redistribute it freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must 12 | not claim that you wrote the original software. If you use this 13 | software in a product, an acknowledgment in the product 14 | documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must 17 | not be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | 22 | Danny Yoo 23 | dyoo@cs.wpi.edu 24 | -------------------------------------------------------------------------------- /contrib/scheme/css/schemecolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | width: 100%; 4 | height: 100%; 5 | background-color: white; 6 | } 7 | 8 | .editbox { 9 | width: 100%; 10 | height: 100%; 11 | margin: 0pt; 12 | padding: 0; 13 | font-family: monospace; 14 | font-size: 10pt; 15 | color: black; 16 | } 17 | 18 | 19 | 20 | pre.code, .editbox { 21 | color: #666666; 22 | } 23 | 24 | .editbox p { 25 | margin: 0; 26 | } 27 | 28 | span.scheme-string {color: green;} 29 | span.scheme-number {color: blue;} 30 | span.scheme-boolean {color: darkred;} 31 | span.scheme-character {color: orange;} 32 | span.scheme-symbol {color: steelblue;} 33 | span.scheme-punctuation {color: black;} 34 | span.scheme-lparen {color: black;} 35 | span.scheme-rparen {color: black;} 36 | span.scheme-comment { color: orange; } 37 | 38 | span.good-matching-paren { 39 | font-weight: bold; 40 | color: #3399FF; 41 | } 42 | span.bad-matching-paren { 43 | font-weight: bold; 44 | color: red; 45 | } 46 | -------------------------------------------------------------------------------- /contrib/scheme/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: Scheme demonstration 6 | 7 | 8 | 21 | 22 | 23 | 24 |

This page demonstrates CodeMirror's 25 | Scheme parser. (license)

26 | 27 |
28 | 44 |
45 | 46 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /contrib/scheme/js/tokenizescheme.js: -------------------------------------------------------------------------------- 1 | /* Tokenizer for Scheme code */ 2 | 3 | 4 | 5 | 6 | /** 7 | TODO: follow the definitions in: 8 | 9 | http://docs.racket-lang.org/reference/reader.html 10 | 11 | to the letter; at the moment, we've just done something quick-and-dirty. 12 | 13 | */ 14 | 15 | 16 | var tokenizeScheme = (function() { 17 | var isWhiteSpace = function(ch) { 18 | // The messy regexp is because IE's regexp matcher is of the 19 | // opinion that non-breaking spaces are no whitespace. 20 | return ch != "\n" && /^[\s\u00a0]*$/.test(ch); 21 | }; 22 | 23 | 24 | // scanUntilUnescaped: string-stream char -> boolean 25 | // Advances the stream until the given character (not preceded by a 26 | // backslash) is encountered. 27 | // Returns true if we hit end of line without closing. 28 | // Returns false otherwise. 29 | var scanUntilUnescaped = function(source, end) { 30 | var escaped = false; 31 | while (true) { 32 | if (source.endOfLine()) { 33 | return true; 34 | } 35 | var next = source.next(); 36 | if (next == end && !escaped) 37 | return false; 38 | escaped = !escaped && next == "\\"; 39 | } 40 | return false; 41 | } 42 | 43 | 44 | // Advance the stream until endline. 45 | var scanUntilEndline = function(source, end) { 46 | while (!source.endOfLine()) { 47 | source.next(); 48 | } 49 | } 50 | 51 | 52 | // Some helper regexps 53 | var isHexDigit = /[0-9A-Fa-f]/; 54 | 55 | 56 | var whitespaceChar = new RegExp("[\\s\\u00a0]"); 57 | 58 | var isDelimiterChar = 59 | new RegExp("[\\s\\\(\\\)\\\[\\\]\\\{\\\}\\\"\\\,\\\'\\\`\\\;]"); 60 | 61 | var isNotDelimiterChar = 62 | new RegExp("[^\\s\\\(\\\)\\\[\\\]\\\{\\\}\\\"\\\,\\\'\\\`\\\;]"); 63 | 64 | 65 | var numberHeader = ("(?:(?:\\d+\\/\\d+)|"+ 66 | ( "(?:(?:\\d+\\.\\d+|\\d+\\.|\\.\\d+)(?:[eE][+\\-]?\\d+)?)|")+ 67 | ( "(?:\\d+(?:[eE][+\\-]?\\d+)?))")); 68 | var numberPatterns = [ 69 | // complex numbers 70 | new RegExp("^((?:(?:\\#[ei])?[+\\-]?" + numberHeader +")?" 71 | + "(?:[+\\-]" + numberHeader + ")i$)"), 72 | /^((?:\#[ei])?[+-]inf.0)$/, 73 | /^((?:\#[ei])?[+-]nan.0)$/, 74 | new RegExp("^((?:\\#[ei])?[+\\-]?" + numberHeader + "$)"), 75 | new RegExp("^0[xX][0-9A-Fa-f]+$")]; 76 | 77 | 78 | // looksLikeNumber: string -> boolean 79 | // Returns true if string s looks like a number. 80 | var looksLikeNumber = function(s) { 81 | for (var i = 0; i < numberPatterns.length; i++) { 82 | if (numberPatterns[i].test(s)) { 83 | return true; 84 | } 85 | } 86 | return false; 87 | }; 88 | 89 | 90 | 91 | var UNCLOSED_STRING = function(source, setState) { 92 | var readNewline = function() { 93 | var content = source.get(); 94 | return { type:'whitespace', style:'whitespace', content: content }; 95 | }; 96 | 97 | var ch = source.peek(); 98 | if (ch === '\n') { 99 | source.next(); 100 | return readNewline(); 101 | } else { 102 | var isUnclosedString = scanUntilUnescaped(source, '"'); 103 | if (isUnclosedString) { 104 | setState(UNCLOSED_STRING); 105 | } else { 106 | setState(START); 107 | } 108 | var content = source.get(); 109 | return {type: "string", style: "scheme-string", content: content, 110 | isUnclosed: isUnclosedString}; 111 | } 112 | }; 113 | 114 | 115 | 116 | var START = function(source, setState) { 117 | // Read a word, look it up in keywords. If not found, it is a 118 | // variable, otherwise it is a keyword of the type found. 119 | var readWordOrNumber = function() { 120 | source.nextWhileMatches(isNotDelimiterChar); 121 | var word = source.get(); 122 | if (looksLikeNumber(word)) { 123 | return {type: "number", style: "scheme-number", content: word}; 124 | } else { 125 | return {type: "variable", style: "scheme-symbol", content: word}; 126 | } 127 | }; 128 | 129 | 130 | var readString = function(quote) { 131 | var isUnclosedString = scanUntilUnescaped(source, quote); 132 | if (isUnclosedString) { 133 | setState(UNCLOSED_STRING); 134 | } 135 | var word = source.get(); 136 | return {type: "string", style: "scheme-string", content: word, 137 | isUnclosed: isUnclosedString}; 138 | }; 139 | 140 | 141 | var readPound = function() { 142 | var text; 143 | // FIXME: handle special things here 144 | if (source.equals(";")) { 145 | source.next(); 146 | text = source.get(); 147 | return {type: text, 148 | style:"scheme-symbol", 149 | content: text}; 150 | } else { 151 | text = source.get(); 152 | 153 | return {type : "symbol", 154 | style: "scheme-symbol", 155 | content: text}; 156 | } 157 | 158 | }; 159 | 160 | var readLineComment = function() { 161 | scanUntilEndline(source); 162 | var text = source.get(); 163 | return { type: "comment", style: "scheme-comment", content: text}; 164 | }; 165 | 166 | 167 | var readWhitespace = function() { 168 | source.nextWhile(isWhiteSpace); 169 | var content = source.get(); 170 | return { type: 'whitespace', style:'whitespace', content: content }; 171 | }; 172 | 173 | var readNewline = function() { 174 | var content = source.get(); 175 | return { type:'whitespace', style:'whitespace', content: content }; 176 | }; 177 | 178 | 179 | // Fetch the next token. Dispatches on first character in the 180 | // stream, or first two characters when the first is a slash. 181 | var ch = source.next(); 182 | if (ch === '\n') { 183 | return readNewline(); 184 | } else if (whitespaceChar.test(ch)) { 185 | return readWhitespace(); 186 | } else if (ch === "#") { 187 | return readPound(); 188 | } else if (ch ===';') { 189 | return readLineComment(); 190 | } else if (ch === "\"") { 191 | return readString(ch); 192 | } else if (isDelimiterChar.test(ch)) { 193 | return {type: ch, style: "scheme-punctuation"}; 194 | } else { 195 | return readWordOrNumber(); 196 | } 197 | } 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | var makeTokenizer = function(source, state) { 206 | // Newlines are always a separate token. 207 | 208 | var tokenizer = { 209 | state: state, 210 | 211 | take: function(type) { 212 | if (typeof(type) == "string") 213 | type = {style: type, type: type}; 214 | 215 | type.content = (type.content || "") + source.get(); 216 | type.value = type.content; 217 | return type; 218 | }, 219 | 220 | next: function () { 221 | if (!source.more()) throw StopIteration; 222 | 223 | var type; 224 | while (!type) { 225 | type = tokenizer.state(source, function(s) { 226 | tokenizer.state = s; 227 | }); 228 | } 229 | var result = this.take(type); 230 | return result; 231 | } 232 | }; 233 | return tokenizer; 234 | }; 235 | 236 | 237 | // The external interface to the tokenizer. 238 | return function(source, startState) { 239 | return makeTokenizer(source, startState || START); 240 | }; 241 | })(); 242 | -------------------------------------------------------------------------------- /contrib/sql/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 John Benediktsson 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any 5 | damages arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any 8 | purpose, including commercial applications, and to alter it and 9 | redistribute it freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must 12 | not claim that you wrote the original software. If you use this 13 | software in a product, an acknowledgment in the product 14 | documentation would be appreciated but is not required. 15 | 16 | 2. Altered source versions must be plainly marked as such, and must 17 | not be misrepresented as being the original software. 18 | 19 | 3. This notice may not be removed or altered from any source 20 | distribution. 21 | 22 | John Benediktsson 23 | -------------------------------------------------------------------------------- /contrib/sql/css/sqlcolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | .editbox p { 14 | margin: 0; 15 | } 16 | 17 | span.sql-keyword { 18 | color: blue; 19 | } 20 | 21 | span.sql-var { 22 | color: red; 23 | } 24 | 25 | span.sql-comment { 26 | color: #AA7700; 27 | } 28 | 29 | span.sql-literal { 30 | color: green; 31 | } 32 | 33 | span.sql-operator { 34 | color: blue; 35 | } 36 | 37 | span.sql-word { 38 | color: black; 39 | } 40 | 41 | span.sql-quoted-word { 42 | color: #680; 43 | } 44 | 45 | span.sql-function { 46 | color: darkorange; 47 | } 48 | 49 | span.sql-type { 50 | color: purple; 51 | } 52 | 53 | span.sql-separator { 54 | color: #666666; 55 | } 56 | 57 | span.sql-number { 58 | color: darkcyan; 59 | } 60 | -------------------------------------------------------------------------------- /contrib/sql/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: SQL demonstration 5 | 6 | 7 | 8 | 9 |

Demonstration of CodeMirror's SQL 10 | highlighter.

11 | 12 |

Written by John Benediktsson (license).

13 | 14 |
15 | 43 |
44 | 45 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /contrib/xquery/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 Mike Brevoort 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /contrib/xquery/css/xqcolors-dark.css: -------------------------------------------------------------------------------- 1 | 2 | .editbox { 3 | margin: .4em; 4 | padding: 0; 5 | font-family: monospace; 6 | font-size: 10pt; 7 | color: white; 8 | background-color: black; 9 | line-height: 16px; 10 | } 11 | 12 | span.word { 13 | color:white; 14 | } 15 | 16 | span.xqueryKeyword { 17 | color: #ffbd40; 18 | /* font-weight: bold; */ 19 | } 20 | 21 | span.xqueryComment { 22 | color: #CDCDCD; 23 | font-style:italic; 24 | } 25 | 26 | span.xqueryModifier { 27 | color:#6c8cd5; 28 | font-weight: bold; 29 | } 30 | 31 | span.xqueryType { 32 | color:#6c8cd5; 33 | font-weight: bold; 34 | } 35 | 36 | span.xqueryAtom { 37 | color:#6c8cd5; 38 | font-weight: bold; 39 | } 40 | 41 | span.xqueryString { 42 | color: #9fee00; 43 | } 44 | 45 | span.xqueryRegexp { 46 | color: rgb(128,0,64); 47 | } 48 | 49 | span.xqueryNumber { 50 | color: rgb(255,0,0); 51 | } 52 | 53 | span.xqueryVariable { 54 | 55 | } 56 | 57 | span.xqueryFunction { 58 | color:#FFF700; 59 | } 60 | 61 | span.xqueryLocalvariable { 62 | color: white; 63 | } 64 | 65 | span.xqueryProperty 66 | { 67 | color: white; 68 | } 69 | 70 | span.xqueryOperator { 71 | color: orange; 72 | } 73 | 74 | span.xqueryPunctuation { 75 | color: white; 76 | } 77 | 78 | span.xquery-doc-directive { 79 | color: white; 80 | } 81 | 82 | span.xml-tagname { 83 | color: #ffbd40; ; 84 | } 85 | 86 | span.xml-attribute { 87 | color: #FFF700; 88 | } 89 | 90 | span.xml-attribute-value { 91 | color: #FFF700; 92 | font-style:italic; 93 | } -------------------------------------------------------------------------------- /contrib/xquery/css/xqcolors.css: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010 Mike Brevoort http://mike.brevoort.com (twitter:@mbrevoort) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This is an indirect collective derivative of the other parses in this package 17 | 18 | */ 19 | .editbox { 20 | margin: .4em; 21 | padding: 0; 22 | font-family: monospace; 23 | font-size: 10pt; 24 | color: black; 25 | background-color: white; 26 | line-height: 16px; 27 | } 28 | 29 | span.word { 30 | } 31 | 32 | span.xqueryKeyword { 33 | color: red; /* #1240AB; */ 34 | /* font-weight: bold; */ 35 | } 36 | 37 | span.xqueryComment { 38 | color: gray; 39 | font-style: italic; 40 | } 41 | 42 | span.xqueryModifier { 43 | color: rgb(0,102,153); 44 | font-weight: bold; 45 | } 46 | 47 | span.xqueryType { 48 | color: purple; 49 | font-weight: bold; 50 | } 51 | 52 | span.xqueryAtom { 53 | color: rgb(0,102,153); 54 | font-weight: bold; 55 | } 56 | 57 | span.xqueryString { 58 | color: green; 59 | } 60 | 61 | span.xqueryRegexp { 62 | color: rgb(128,0,64); 63 | } 64 | 65 | span.xqueryNumber { 66 | color: #1240AB; 67 | } 68 | 69 | span.xqueryVariable { 70 | /* color: red; */ 71 | } 72 | 73 | span.xqueryFunction { 74 | color: #1240AB; 75 | /* font-weight:bold; */ 76 | } 77 | 78 | 79 | span.xqueryOperator { 80 | color: red; 81 | } 82 | 83 | span.xqueryPunctuation { 84 | color: DIMGray; 85 | } 86 | 87 | span.xml-tagname { 88 | color: purple; 89 | } 90 | 91 | span.xml-attribute { 92 | color: purple; 93 | font-style:italic; 94 | } 95 | 96 | span.xml-attribute-value { 97 | color: purple; 98 | font-style:italic; 99 | } -------------------------------------------------------------------------------- /contrib/xquery/css/xqcolors2.css: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2010 Mike Brevoort http://mike.brevoort.com (twitter:@mbrevoort) 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | This is an indirect collective derivative of the other parses in this package 17 | 18 | */ 19 | .editbox { 20 | margin: .4em; 21 | padding: 0; 22 | font-family: monospace; 23 | font-size: 10pt; 24 | color: black; 25 | background-color: white; 26 | line-height: 16px; 27 | } 28 | 29 | span.word { 30 | } 31 | 32 | span.xqueryKeyword { 33 | color: blue; 34 | /* font-weight: bold; */ 35 | } 36 | 37 | span.xqueryComment { 38 | color: gray; 39 | } 40 | 41 | span.xqueryModifier { 42 | color: rgb(0,102,153); 43 | font-weight: bold; 44 | } 45 | 46 | span.xqueryType { 47 | color: rgb(0,135,255); 48 | font-weight: bold; 49 | } 50 | 51 | span.xqueryAtom { 52 | color: rgb(0,102,153); 53 | font-weight: bold; 54 | } 55 | 56 | span.xqueryString { 57 | color: green; 58 | } 59 | 60 | span.xqueryRegexp { 61 | color: rgb(128,0,64); 62 | } 63 | 64 | span.xqueryNumber { 65 | color: rgb(255,0,0); 66 | } 67 | 68 | span.xqueryVariable { 69 | color: red; 70 | } 71 | 72 | span.xqueryFunction { 73 | text-decoration:underline 74 | } 75 | 76 | 77 | span.xqueryOperator { 78 | color: DimGray; 79 | } 80 | 81 | span.xqueryPunctuation { 82 | } 83 | 84 | span.xml-tagname { 85 | color: purple; 86 | } 87 | 88 | span.xml-attribute { 89 | color: purple; 90 | font-style:italic; 91 | } 92 | 93 | span.xml-attribute-value { 94 | color: purple; 95 | font-style:italic; 96 | } -------------------------------------------------------------------------------- /css/baboon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codemirror/CodeMirror-v1/2d7adc98d16cfb05aecf208177d4a4281b43ce30/css/baboon.png -------------------------------------------------------------------------------- /css/csscolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | pre.code, .editbox { 14 | color: #666; 15 | } 16 | 17 | .editbox p { 18 | margin: 0; 19 | } 20 | 21 | span.css-at { 22 | color: #708; 23 | } 24 | 25 | span.css-unit { 26 | color: #281; 27 | } 28 | 29 | span.css-value { 30 | color: #708; 31 | } 32 | 33 | span.css-identifier { 34 | color: black; 35 | } 36 | 37 | span.css-selector { 38 | color: #11B; 39 | } 40 | 41 | span.css-important { 42 | color: #00F; 43 | } 44 | 45 | span.css-colorcode { 46 | color: #299; 47 | } 48 | 49 | span.css-comment { 50 | color: #A70; 51 | } 52 | 53 | span.css-string { 54 | color: #A22; 55 | } 56 | -------------------------------------------------------------------------------- /css/docs.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: Arial, sans-serif; 3 | line-height: 1.5; 4 | max-width: 64.3em; 5 | margin: 3em auto; 6 | padding: 0 1em; 7 | } 8 | body.droid { 9 | font-family: Droid Sans, Arial, sans-serif; 10 | } 11 | 12 | h1 { 13 | letter-spacing: -3px; 14 | font-size: 3.23em; 15 | font-weight: bold; 16 | margin: 0; 17 | } 18 | 19 | h2 { 20 | font-size: 1.23em; 21 | font-weight: bold; 22 | margin: .5em 0; 23 | letter-spacing: -1px; 24 | } 25 | 26 | h3 { 27 | font-size: 1em; 28 | font-weight: bold; 29 | margin: .4em 0; 30 | } 31 | 32 | pre { 33 | font-family: Courier New, monospaced; 34 | background-color: #eee; 35 | -moz-border-radius: 6px; 36 | -webkit-border-radius: 6px; 37 | border-radius: 6px; 38 | padding: 1em; 39 | } 40 | 41 | pre.code { 42 | margin: 0 1em; 43 | } 44 | 45 | .grey { 46 | font-size: 2em; 47 | padding: .5em 1em; 48 | line-height: 1.2em; 49 | margin-top: .5em; 50 | position: relative; 51 | } 52 | 53 | img.logo { 54 | position: absolute; 55 | right: -25px; 56 | bottom: 4px; 57 | } 58 | 59 | a:link, a:visited, .quasilink { 60 | color: #df0019; 61 | cursor: pointer; 62 | text-decoration: none; 63 | } 64 | 65 | a:hover, .quasilink:hover { 66 | color: #800004; 67 | } 68 | 69 | h1 a:link, h1 a:visited, h1 a:hover { 70 | color: black; 71 | } 72 | 73 | ul { 74 | margin: 0; 75 | padding-left: 1.2em; 76 | } 77 | 78 | a.download { 79 | color: white; 80 | background-color: #df0019; 81 | width: 100%; 82 | display: block; 83 | text-align: center; 84 | font-size: 1.23em; 85 | font-weight: bold; 86 | text-decoration: none; 87 | -moz-border-radius: 6px; 88 | -webkit-border-radius: 6px; 89 | border-radius: 6px; 90 | padding: .5em 0; 91 | margin-bottom: 1em; 92 | } 93 | 94 | a.download:hover { 95 | background-color: #bb0010; 96 | } 97 | 98 | .rel { 99 | margin-bottom: 0; 100 | } 101 | 102 | .rel-note { 103 | color: #777; 104 | font-size: .9em; 105 | margin-top: .1em; 106 | } 107 | 108 | .logo-braces { 109 | color: #df0019; 110 | position: relative; 111 | top: -4px; 112 | } 113 | 114 | .blk { 115 | float: left; 116 | } 117 | 118 | .left { 119 | width: 37em; 120 | padding-right: 6.53em; 121 | padding-bottom: 1em; 122 | } 123 | 124 | .left1 { 125 | width: 15.24em; 126 | padding-right: 6.45em; 127 | } 128 | 129 | .left2 { 130 | width: 15.24em; 131 | } 132 | 133 | .right { 134 | width: 20.68em; 135 | } 136 | 137 | .leftbig { 138 | width: 42.44em; 139 | padding-right: 6.53em; 140 | } 141 | 142 | .rightsmall { 143 | width: 15.24em; 144 | } 145 | 146 | .clear:after { 147 | visibility: hidden; 148 | display: block; 149 | font-size: 0; 150 | content: " "; 151 | clear: both; 152 | height: 0; 153 | } 154 | .clear { display: inline-block; } 155 | /* start commented backslash hack \*/ 156 | * html .clear { height: 1%; } 157 | .clear { display: block; } 158 | /* close commented backslash hack */ 159 | -------------------------------------------------------------------------------- /css/font.js: -------------------------------------------------------------------------------- 1 | function waitForStyles() { 2 | for (var i = 0; i < document.styleSheets.length; i++) 3 | if (/googleapis/.test(document.styleSheets[i].href)) 4 | return document.body.className += " droid"; 5 | setTimeout(waitForStyles, 100); 6 | } 7 | setTimeout(function() { 8 | if (/AppleWebKit/.test(navigator.userAgent) && /iP[oa]d|iPhone/.test(navigator.userAgent)) return; 9 | var link = document.createElement("LINK"); 10 | link.type = "text/css"; 11 | link.rel = "stylesheet"; 12 | link.href = "http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans:bold"; 13 | document.documentElement.getElementsByTagName("HEAD")[0].appendChild(link); 14 | waitForStyles(); 15 | }, 20); 16 | -------------------------------------------------------------------------------- /css/jscolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | pre.code, .editbox { 14 | color: #666666; 15 | } 16 | 17 | .editbox p { 18 | margin: 0; 19 | } 20 | 21 | span.js-punctuation { 22 | color: #666666; 23 | } 24 | 25 | span.js-operator { 26 | color: #666666; 27 | } 28 | 29 | span.js-keyword { 30 | color: #770088; 31 | } 32 | 33 | span.js-atom { 34 | color: #228811; 35 | } 36 | 37 | span.js-variable { 38 | color: black; 39 | } 40 | 41 | span.js-variabledef { 42 | color: #0000FF; 43 | } 44 | 45 | span.js-localvariable { 46 | color: #004499; 47 | } 48 | 49 | span.js-property { 50 | color: black; 51 | } 52 | 53 | span.js-comment { 54 | color: #AA7700; 55 | } 56 | 57 | span.js-string { 58 | color: #AA2222; 59 | } 60 | -------------------------------------------------------------------------------- /css/people.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codemirror/CodeMirror-v1/2d7adc98d16cfb05aecf208177d4a4281b43ce30/css/people.jpg -------------------------------------------------------------------------------- /css/sparqlcolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | .editbox p { 14 | margin: 0; 15 | } 16 | 17 | span.sp-keyword { 18 | color: #708; 19 | } 20 | 21 | span.sp-prefixed { 22 | color: #5d1; 23 | } 24 | 25 | span.sp-var { 26 | color: #00c; 27 | } 28 | 29 | span.sp-comment { 30 | color: #a70; 31 | } 32 | 33 | span.sp-literal { 34 | color: #a22; 35 | } 36 | 37 | span.sp-uri { 38 | color: #292; 39 | } 40 | 41 | span.sp-operator { 42 | color: #088; 43 | } 44 | -------------------------------------------------------------------------------- /css/xmlcolors.css: -------------------------------------------------------------------------------- 1 | html { 2 | cursor: text; 3 | } 4 | 5 | .editbox { 6 | margin: .4em; 7 | padding: 0; 8 | font-family: monospace; 9 | font-size: 10pt; 10 | color: black; 11 | } 12 | 13 | .editbox p { 14 | margin: 0; 15 | } 16 | 17 | span.xml-tagname { 18 | color: #A0B; 19 | } 20 | 21 | span.xml-attribute { 22 | color: #281; 23 | } 24 | 25 | span.xml-punctuation { 26 | color: black; 27 | } 28 | 29 | span.xml-attname { 30 | color: #00F; 31 | } 32 | 33 | span.xml-comment { 34 | color: #A70; 35 | } 36 | 37 | span.xml-cdata { 38 | color: #48A; 39 | } 40 | 41 | span.xml-processing { 42 | color: #999; 43 | } 44 | 45 | span.xml-entity { 46 | color: #A22; 47 | } 48 | 49 | span.xml-error { 50 | color: #F00 !important; 51 | } 52 | 53 | span.xml-text { 54 | color: black; 55 | } 56 | -------------------------------------------------------------------------------- /csstest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: CSS demonstration 5 | 6 | 7 | 8 | 9 |

Demonstration of CodeMirror's CSS 10 | highlighter.

11 | 12 |
13 | 48 |
49 | 50 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /faq.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: FAQ 5 | 6 | 7 | 8 | 9 | 10 |

{ } CodeMirror

11 | 12 |
13 | /* Frequently asked
14 |    questions */
15 | 
16 | 17 |
18 | 19 |

Q: Can I use CodeMirror in my such-and-such project?

20 | 21 |

A: Yes. The license is short, simple, and 22 | permissive.

23 | 24 |

Q: You said you fixed this-and-this issue, but I'm 25 | still seeing it.

26 | 27 |

A: One possibility is that I screwed up, but a very real 28 | alternative is that you're looking at a cached version of the 29 | CodeMirror scripts. Because the scripts are loaded into an iframe, 30 | the ctrl-f5 you issued on the outer page doesn't always cause them 31 | to be reloaded (IE, Opera, and Firefox are the worst offenders 32 | here). Clear your cache and re-try.

33 | 34 |

Q: I can't put content containing 35 | </textarea> into CodeMirror!

36 | 37 |

A: [Web-programming 101] The first </textarea> 38 | following a <textarea> tag will close the 39 | textarea. This has nothing to do with CodeMirror. Sit down, and 40 | spend ten minutes thinking about why HTML-escaping was 41 | invented.

42 | 43 |

Q: I have this huge chunk of code that does not 44 | work, can you debug it for me?

45 | 46 |

A: Nope. If you can't be bothered isolate your problem in 20 47 | lines of code or less, I can't be bothered to think about it.

48 | 49 |

Q: How do I submit patches for CodeMirror?

50 | 51 |

A: Preferred way is to create a fork on github, add your 53 | patch, and send me a pull request. Diffs (against the latest 54 | version!) by mail are also cool.

55 | 56 | 57 |
58 | 59 |

Questions

60 | 61 | 68 | 69 |

Site

70 | 71 | 78 | 79 |
80 | 81 |
 
82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /highlight.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | CodeMirror: String highlight demonstration 9 | 10 | 11 | 12 | 13 |
14 | 55 |
56 | 57 | 58 | 59 |
60 |
61 |

62 | 
63 | 64 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /htmltest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: HTML/XML demonstration 5 | 6 | 19 | 20 | 21 | 22 |

This is a simple demonstration of the XML/HTML indentation module 23 | for CodeMirror. The javascript file contains some comments with 25 | more information.

26 | 27 |
28 |
29 | 41 |
42 |
43 | 44 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror 5 | 6 | 7 | 8 | 9 | 10 | 11 |

{ } CodeMirror

12 | 13 |
 14 | /* In-browser code editing
 15 |    made bearable */
 16 | 
17 | 18 |
19 | 20 |

CodeMirror is a JavaScript library that can be used to create a 21 | relatively pleasant editor interface for code-like content ― 22 | computer programs, HTML markup, and similar. If a parser has been 23 | written for the language you are editing (see below for a list of 24 | supported languages), the code will be coloured, and the editor will 25 | help you with indentation.

26 | 27 | 78 | 79 |

Supported browsers

80 | 81 |

The following browsers are able to run CodeMirror:

82 | 83 |
    84 |
  • Firefox 1.5 or higher
  • 85 |
  • Internet Explorer 6 or higher
  • 86 |
  • Safari 3 or higher
  • 87 |
  • Opera 9.52 or higher
  • 88 |
  • Chrome
  • 89 |
90 | 91 |

I am not actively testing against every new browser release, and 92 | vendors have a habit of introducing bugs all the time, so I am 93 | relying on the community to tell me when something breaks. See below for information on how to contact me.

95 | 96 |

Getting the code

97 | 98 |

All of CodeMirror is released under a zlib-style license. To get it, you can download 100 | the latest 101 | release or the current development 103 | snapshot as zip files. To create a custom minified script file, 104 | you can use the compression API.

105 | 106 |

We use git for version control. 107 | The main repository can be fetched in this way:

108 | 109 |
git clone http://marijnhaverbeke.nl/git/codemirror
110 | 111 |

CodeMirror can also be found on GitHub: http://github.com/marijnh/CodeMirror. 113 | If you plan to hack on the code and contribute patches, the best way 114 | to do it is to create a GitHub fork, and send pull requests.

115 | 116 |

Documentation

117 | 118 |

The manual is your first stop for 119 | learning how to use this library. It starts with a quick explanation 120 | of how to use the editor, and then describes all of the (many) 121 | options and methods that CodeMirror exposes.

122 | 123 |

For those who want to learn more about the code, this document about CodeMirror's architecture 125 | will be useful. The source code itself 127 | is, for the most part, also very well commented.

128 | 129 |

Support

130 | 131 |

There is a Google group (a 133 | sort of mailing list/newsgroup thing) for discussion and news 134 | related to CodeMirror. Please check the FAQ 135 | before asking a question. You can also e-mail me directly: Marijn Haverbeke.

137 | 138 |
139 | 140 |
141 | 142 | Current project page 143 | 144 |

This is the old CodeMirror 1 project page. For new releases and 145 | events, see CodeMirror 2.

146 | 147 |
148 | 149 |
 
150 | 151 |
152 | 153 | 154 |
155 | 156 | 157 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /js/highlight.js: -------------------------------------------------------------------------------- 1 | // Minimal framing needed to use CodeMirror-style parsers to highlight 2 | // code. Load this along with tokenize.js, stringstream.js, and your 3 | // parser. Then call highlightText, passing a string as the first 4 | // argument, and as the second argument either a callback function 5 | // that will be called with an array of SPAN nodes for every line in 6 | // the code, or a DOM node to which to append these spans, and 7 | // optionally (not needed if you only loaded one parser) a parser 8 | // object. 9 | 10 | // Stuff from util.js that the parsers are using. 11 | var StopIteration = {toString: function() {return "StopIteration"}}; 12 | 13 | var Editor = {}; 14 | var indentUnit = 2; 15 | 16 | (function(){ 17 | function normaliseString(string) { 18 | var tab = ""; 19 | for (var i = 0; i < indentUnit; i++) tab += " "; 20 | 21 | string = string.replace(/\t/g, tab).replace(/\u00a0/g, " ").replace(/\r\n?/g, "\n"); 22 | var pos = 0, parts = [], lines = string.split("\n"); 23 | for (var line = 0; line < lines.length; line++) { 24 | if (line != 0) parts.push("\n"); 25 | parts.push(lines[line]); 26 | } 27 | 28 | return { 29 | next: function() { 30 | if (pos < parts.length) return parts[pos++]; 31 | else throw StopIteration; 32 | } 33 | }; 34 | } 35 | 36 | window.highlightText = function(string, callback, parser) { 37 | parser = (parser || Editor.Parser).make(stringStream(normaliseString(string))); 38 | var line = []; 39 | if (callback.nodeType == 1) { 40 | var node = callback; 41 | callback = function(line) { 42 | for (var i = 0; i < line.length; i++) 43 | node.appendChild(line[i]); 44 | node.appendChild(document.createElement("br")); 45 | }; 46 | } 47 | 48 | try { 49 | while (true) { 50 | var token = parser.next(); 51 | if (token.value == "\n") { 52 | callback(line); 53 | line = []; 54 | } 55 | else { 56 | var span = document.createElement("span"); 57 | span.className = token.style; 58 | span.appendChild(document.createTextNode(token.value)); 59 | line.push(span); 60 | } 61 | } 62 | } 63 | catch (e) { 64 | if (e != StopIteration) throw e; 65 | } 66 | if (line.length) callback(line); 67 | } 68 | })(); 69 | -------------------------------------------------------------------------------- /js/mirrorframe.js: -------------------------------------------------------------------------------- 1 | /* Demonstration of embedding CodeMirror in a bigger application. The 2 | * interface defined here is a mess of prompts and confirms, and 3 | * should probably not be used in a real project. 4 | */ 5 | 6 | function MirrorFrame(place, options) { 7 | this.home = document.createElement("div"); 8 | if (place.appendChild) 9 | place.appendChild(this.home); 10 | else 11 | place(this.home); 12 | 13 | var self = this; 14 | function makeButton(name, action) { 15 | var button = document.createElement("input"); 16 | button.type = "button"; 17 | button.value = name; 18 | self.home.appendChild(button); 19 | button.onclick = function(){self[action].call(self);}; 20 | } 21 | 22 | makeButton("Search", "search"); 23 | makeButton("Replace", "replace"); 24 | makeButton("Current line", "line"); 25 | makeButton("Jump to line", "jump"); 26 | makeButton("Insert constructor", "macro"); 27 | makeButton("Indent all", "reindent"); 28 | 29 | this.mirror = new CodeMirror(this.home, options); 30 | } 31 | 32 | MirrorFrame.prototype = { 33 | search: function() { 34 | var text = prompt("Enter search term:", ""); 35 | if (!text) return; 36 | 37 | var first = true; 38 | do { 39 | var cursor = this.mirror.getSearchCursor(text, first); 40 | first = false; 41 | while (cursor.findNext()) { 42 | cursor.select(); 43 | if (!confirm("Search again?")) 44 | return; 45 | } 46 | } while (confirm("End of document reached. Start over?")); 47 | }, 48 | 49 | replace: function() { 50 | // This is a replace-all, but it is possible to implement a 51 | // prompting replace. 52 | var from = prompt("Enter search string:", ""), to; 53 | if (from) to = prompt("What should it be replaced with?", ""); 54 | if (to == null) return; 55 | 56 | var cursor = this.mirror.getSearchCursor(from, false); 57 | while (cursor.findNext()) 58 | cursor.replace(to); 59 | }, 60 | 61 | jump: function() { 62 | var line = prompt("Jump to line:", ""); 63 | if (line && !isNaN(Number(line))) 64 | this.mirror.jumpToLine(Number(line)); 65 | }, 66 | 67 | line: function() { 68 | alert("The cursor is currently at line " + this.mirror.currentLine()); 69 | this.mirror.focus(); 70 | }, 71 | 72 | macro: function() { 73 | var name = prompt("Name your constructor:", ""); 74 | if (name) 75 | this.mirror.replaceSelection("function " + name + "() {\n \n}\n\n" + name + ".prototype = {\n \n};\n"); 76 | }, 77 | 78 | reindent: function() { 79 | this.mirror.reindent(); 80 | } 81 | }; 82 | -------------------------------------------------------------------------------- /js/parsecss.js: -------------------------------------------------------------------------------- 1 | /* Simple parser for CSS */ 2 | 3 | var CSSParser = Editor.Parser = (function() { 4 | var tokenizeCSS = (function() { 5 | function normal(source, setState) { 6 | var ch = source.next(); 7 | if (ch == "@") { 8 | source.nextWhileMatches(/\w/); 9 | return "css-at"; 10 | } 11 | else if (ch == "/" && source.equals("*")) { 12 | setState(inCComment); 13 | return null; 14 | } 15 | else if (ch == "<" && source.equals("!")) { 16 | setState(inSGMLComment); 17 | return null; 18 | } 19 | else if (ch == "=") { 20 | return "css-compare"; 21 | } 22 | else if (source.equals("=") && (ch == "~" || ch == "|")) { 23 | source.next(); 24 | return "css-compare"; 25 | } 26 | else if (ch == "\"" || ch == "'") { 27 | setState(inString(ch)); 28 | return null; 29 | } 30 | else if (ch == "#") { 31 | source.nextWhileMatches(/\w/); 32 | return "css-hash"; 33 | } 34 | else if (ch == "!") { 35 | source.nextWhileMatches(/[ \t]/); 36 | source.nextWhileMatches(/\w/); 37 | return "css-important"; 38 | } 39 | else if (/\d/.test(ch)) { 40 | source.nextWhileMatches(/[\w.%]/); 41 | return "css-unit"; 42 | } 43 | else if (/[,.+>*\/]/.test(ch)) { 44 | return "css-select-op"; 45 | } 46 | else if (/[;{}:\[\]]/.test(ch)) { 47 | return "css-punctuation"; 48 | } 49 | else { 50 | source.nextWhileMatches(/[\w\\\-_]/); 51 | return "css-identifier"; 52 | } 53 | } 54 | 55 | function inCComment(source, setState) { 56 | var maybeEnd = false; 57 | while (!source.endOfLine()) { 58 | var ch = source.next(); 59 | if (maybeEnd && ch == "/") { 60 | setState(normal); 61 | break; 62 | } 63 | maybeEnd = (ch == "*"); 64 | } 65 | return "css-comment"; 66 | } 67 | 68 | function inSGMLComment(source, setState) { 69 | var dashes = 0; 70 | while (!source.endOfLine()) { 71 | var ch = source.next(); 72 | if (dashes >= 2 && ch == ">") { 73 | setState(normal); 74 | break; 75 | } 76 | dashes = (ch == "-") ? dashes + 1 : 0; 77 | } 78 | return "css-comment"; 79 | } 80 | 81 | function inString(quote) { 82 | return function(source, setState) { 83 | var escaped = false; 84 | while (!source.endOfLine()) { 85 | var ch = source.next(); 86 | if (ch == quote && !escaped) 87 | break; 88 | escaped = !escaped && ch == "\\"; 89 | } 90 | if (!escaped) 91 | setState(normal); 92 | return "css-string"; 93 | }; 94 | } 95 | 96 | return function(source, startState) { 97 | return tokenizer(source, startState || normal); 98 | }; 99 | })(); 100 | 101 | function indentCSS(inBraces, inRule, base) { 102 | return function(nextChars) { 103 | if (!inBraces || /^\}/.test(nextChars)) return base; 104 | else if (inRule) return base + indentUnit * 2; 105 | else return base + indentUnit; 106 | }; 107 | } 108 | 109 | // This is a very simplistic parser -- since CSS does not really 110 | // nest, it works acceptably well, but some nicer colouroing could 111 | // be provided with a more complicated parser. 112 | function parseCSS(source, basecolumn) { 113 | basecolumn = basecolumn || 0; 114 | var tokens = tokenizeCSS(source); 115 | var inBraces = false, inRule = false, inDecl = false;; 116 | 117 | var iter = { 118 | next: function() { 119 | var token = tokens.next(), style = token.style, content = token.content; 120 | 121 | if (style == "css-hash") 122 | style = token.style = inRule ? "css-colorcode" : "css-identifier"; 123 | if (style == "css-identifier") { 124 | if (inRule) token.style = "css-value"; 125 | else if (!inBraces && !inDecl) token.style = "css-selector"; 126 | } 127 | 128 | if (content == "\n") 129 | token.indentation = indentCSS(inBraces, inRule, basecolumn); 130 | 131 | if (content == "{" && inDecl == "@media") 132 | inDecl = false; 133 | else if (content == "{") 134 | inBraces = true; 135 | else if (content == "}") 136 | inBraces = inRule = inDecl = false; 137 | else if (content == ";") 138 | inRule = inDecl = false; 139 | else if (inBraces && style != "css-comment" && style != "whitespace") 140 | inRule = true; 141 | else if (!inBraces && style == "css-at") 142 | inDecl = content; 143 | 144 | return token; 145 | }, 146 | 147 | copy: function() { 148 | var _inBraces = inBraces, _inRule = inRule, _tokenState = tokens.state; 149 | return function(source) { 150 | tokens = tokenizeCSS(source, _tokenState); 151 | inBraces = _inBraces; 152 | inRule = _inRule; 153 | return iter; 154 | }; 155 | } 156 | }; 157 | return iter; 158 | } 159 | 160 | return {make: parseCSS, electricChars: "}"}; 161 | })(); 162 | -------------------------------------------------------------------------------- /js/parsedummy.js: -------------------------------------------------------------------------------- 1 | var DummyParser = Editor.Parser = (function() { 2 | function tokenizeDummy(source) { 3 | while (!source.endOfLine()) source.next(); 4 | return "text"; 5 | } 6 | function parseDummy(source) { 7 | function indentTo(n) {return function() {return n;}} 8 | source = tokenizer(source, tokenizeDummy); 9 | var space = 0; 10 | 11 | var iter = { 12 | next: function() { 13 | var tok = source.next(); 14 | if (tok.type == "whitespace") { 15 | if (tok.value == "\n") tok.indentation = indentTo(space); 16 | else space = tok.value.length; 17 | } 18 | return tok; 19 | }, 20 | copy: function() { 21 | var _space = space; 22 | return function(_source) { 23 | space = _space; 24 | source = tokenizer(_source, tokenizeDummy); 25 | return iter; 26 | }; 27 | } 28 | }; 29 | return iter; 30 | } 31 | return {make: parseDummy}; 32 | })(); 33 | -------------------------------------------------------------------------------- /js/parsehtmlmixed.js: -------------------------------------------------------------------------------- 1 | var HTMLMixedParser = Editor.Parser = (function() { 2 | 3 | // tags that trigger seperate parsers 4 | var triggers = { 5 | "script": "JSParser", 6 | "style": "CSSParser" 7 | }; 8 | 9 | function checkDependencies() { 10 | var parsers = ['XMLParser']; 11 | for (var p in triggers) parsers.push(triggers[p]); 12 | for (var i in parsers) { 13 | if (!window[parsers[i]]) throw new Error(parsers[i] + " parser must be loaded for HTML mixed mode to work."); 14 | } 15 | XMLParser.configure({useHTMLKludges: true}); 16 | } 17 | 18 | function parseMixed(stream) { 19 | checkDependencies(); 20 | var htmlParser = XMLParser.make(stream), localParser = null, inTag = false; 21 | var iter = {next: top, copy: copy}; 22 | 23 | function top() { 24 | var token = htmlParser.next(); 25 | if (token.content == "<") 26 | inTag = true; 27 | else if (token.style == "xml-tagname" && inTag === true) 28 | inTag = token.content.toLowerCase(); 29 | else if (token.content == ">") { 30 | if (triggers[inTag]) { 31 | var parser = window[triggers[inTag]]; 32 | iter.next = local(parser, "=&|]/; 11 | 12 | var tokenizeSparql = (function() { 13 | function normal(source, setState) { 14 | var ch = source.next(); 15 | if (ch == "$" || ch == "?") { 16 | source.nextWhileMatches(/[\w\d]/); 17 | return "sp-var"; 18 | } 19 | else if (ch == "<" && !source.matches(/[\s\u00a0=]/)) { 20 | source.nextWhileMatches(/[^\s\u00a0>]/); 21 | if (source.equals(">")) source.next(); 22 | return "sp-uri"; 23 | } 24 | else if (ch == "\"" || ch == "'") { 25 | setState(inLiteral(ch)); 26 | return null; 27 | } 28 | else if (/[{}\(\),\.;\[\]]/.test(ch)) { 29 | return "sp-punc"; 30 | } 31 | else if (ch == "#") { 32 | while (!source.endOfLine()) source.next(); 33 | return "sp-comment"; 34 | } 35 | else if (operatorChars.test(ch)) { 36 | source.nextWhileMatches(operatorChars); 37 | return "sp-operator"; 38 | } 39 | else if (ch == ":") { 40 | source.nextWhileMatches(/[\w\d\._\-]/); 41 | return "sp-prefixed"; 42 | } 43 | else { 44 | source.nextWhileMatches(/[_\w\d]/); 45 | if (source.equals(":")) { 46 | source.next(); 47 | source.nextWhileMatches(/[\w\d_\-]/); 48 | return "sp-prefixed"; 49 | } 50 | var word = source.get(), type; 51 | if (ops.test(word)) 52 | type = "sp-operator"; 53 | else if (keywords.test(word)) 54 | type = "sp-keyword"; 55 | else 56 | type = "sp-word"; 57 | return {style: type, content: word}; 58 | } 59 | } 60 | 61 | function inLiteral(quote) { 62 | return function(source, setState) { 63 | var escaped = false; 64 | while (!source.endOfLine()) { 65 | var ch = source.next(); 66 | if (ch == quote && !escaped) { 67 | setState(normal); 68 | break; 69 | } 70 | escaped = !escaped && ch == "\\"; 71 | } 72 | return "sp-literal"; 73 | }; 74 | } 75 | 76 | return function(source, startState) { 77 | return tokenizer(source, startState || normal); 78 | }; 79 | })(); 80 | 81 | function indentSparql(context) { 82 | return function(nextChars) { 83 | var firstChar = nextChars && nextChars.charAt(0); 84 | if (/[\]\}]/.test(firstChar)) 85 | while (context && context.type == "pattern") context = context.prev; 86 | 87 | var closing = context && firstChar == matching[context.type]; 88 | if (!context) 89 | return 0; 90 | else if (context.type == "pattern") 91 | return context.col; 92 | else if (context.align) 93 | return context.col - (closing ? context.width : 0); 94 | else 95 | return context.indent + (closing ? 0 : indentUnit); 96 | } 97 | } 98 | 99 | function parseSparql(source) { 100 | var tokens = tokenizeSparql(source); 101 | var context = null, indent = 0, col = 0; 102 | function pushContext(type, width) { 103 | context = {prev: context, indent: indent, col: col, type: type, width: width}; 104 | } 105 | function popContext() { 106 | context = context.prev; 107 | } 108 | 109 | var iter = { 110 | next: function() { 111 | var token = tokens.next(), type = token.style, content = token.content, width = token.value.length; 112 | 113 | if (content == "\n") { 114 | token.indentation = indentSparql(context); 115 | indent = col = 0; 116 | if (context && context.align == null) context.align = false; 117 | } 118 | else if (type == "whitespace" && col == 0) { 119 | indent = width; 120 | } 121 | else if (type != "sp-comment" && context && context.align == null) { 122 | context.align = true; 123 | } 124 | 125 | if (content != "\n") col += width; 126 | 127 | if (/[\[\{\(]/.test(content)) { 128 | pushContext(content, width); 129 | } 130 | else if (/[\]\}\)]/.test(content)) { 131 | while (context && context.type == "pattern") 132 | popContext(); 133 | if (context && content == matching[context.type]) 134 | popContext(); 135 | } 136 | else if (content == "." && context && context.type == "pattern") { 137 | popContext(); 138 | } 139 | else if ((type == "sp-word" || type == "sp-prefixed" || type == "sp-uri" || type == "sp-var" || type == "sp-literal") && 140 | context && /[\{\[]/.test(context.type)) { 141 | pushContext("pattern", width); 142 | } 143 | 144 | return token; 145 | }, 146 | 147 | copy: function() { 148 | var _context = context, _indent = indent, _col = col, _tokenState = tokens.state; 149 | return function(source) { 150 | tokens = tokenizeSparql(source, _tokenState); 151 | context = _context; 152 | indent = _indent; 153 | col = _col; 154 | return iter; 155 | }; 156 | } 157 | }; 158 | return iter; 159 | } 160 | 161 | return {make: parseSparql, electricChars: "}]"}; 162 | })(); 163 | -------------------------------------------------------------------------------- /js/stringstream.js: -------------------------------------------------------------------------------- 1 | /* String streams are the things fed to parsers (which can feed them 2 | * to a tokenizer if they want). They provide peek and next methods 3 | * for looking at the current character (next 'consumes' this 4 | * character, peek does not), and a get method for retrieving all the 5 | * text that was consumed since the last time get was called. 6 | * 7 | * An easy mistake to make is to let a StopIteration exception finish 8 | * the token stream while there are still characters pending in the 9 | * string stream (hitting the end of the buffer while parsing a 10 | * token). To make it easier to detect such errors, the stringstreams 11 | * throw an exception when this happens. 12 | */ 13 | 14 | // Make a stringstream stream out of an iterator that returns strings. 15 | // This is applied to the result of traverseDOM (see codemirror.js), 16 | // and the resulting stream is fed to the parser. 17 | var stringStream = function(source){ 18 | // String that's currently being iterated over. 19 | var current = ""; 20 | // Position in that string. 21 | var pos = 0; 22 | // Accumulator for strings that have been iterated over but not 23 | // get()-ed yet. 24 | var accum = ""; 25 | // Make sure there are more characters ready, or throw 26 | // StopIteration. 27 | function ensureChars() { 28 | while (pos == current.length) { 29 | accum += current; 30 | current = ""; // In case source.next() throws 31 | pos = 0; 32 | try {current = source.next();} 33 | catch (e) { 34 | if (e != StopIteration) throw e; 35 | else return false; 36 | } 37 | } 38 | return true; 39 | } 40 | 41 | return { 42 | // peek: -> character 43 | // Return the next character in the stream. 44 | peek: function() { 45 | if (!ensureChars()) return null; 46 | return current.charAt(pos); 47 | }, 48 | // next: -> character 49 | // Get the next character, throw StopIteration if at end, check 50 | // for unused content. 51 | next: function() { 52 | if (!ensureChars()) { 53 | if (accum.length > 0) 54 | throw "End of stringstream reached without emptying buffer ('" + accum + "')."; 55 | else 56 | throw StopIteration; 57 | } 58 | return current.charAt(pos++); 59 | }, 60 | // get(): -> string 61 | // Return the characters iterated over since the last call to 62 | // .get(). 63 | get: function() { 64 | var temp = accum; 65 | accum = ""; 66 | if (pos > 0){ 67 | temp += current.slice(0, pos); 68 | current = current.slice(pos); 69 | pos = 0; 70 | } 71 | return temp; 72 | }, 73 | // Push a string back into the stream. 74 | push: function(str) { 75 | current = current.slice(0, pos) + str + current.slice(pos); 76 | }, 77 | lookAhead: function(str, consume, skipSpaces, caseInsensitive) { 78 | function cased(str) {return caseInsensitive ? str.toLowerCase() : str;} 79 | str = cased(str); 80 | var found = false; 81 | 82 | var _accum = accum, _pos = pos; 83 | if (skipSpaces) this.nextWhileMatches(/[\s\u00a0]/); 84 | 85 | while (true) { 86 | var end = pos + str.length, left = current.length - pos; 87 | if (end <= current.length) { 88 | found = str == cased(current.slice(pos, end)); 89 | pos = end; 90 | break; 91 | } 92 | else if (str.slice(0, left) == cased(current.slice(pos))) { 93 | accum += current; current = ""; 94 | try {current = source.next();} 95 | catch (e) {if (e != StopIteration) throw e; break;} 96 | pos = 0; 97 | str = str.slice(left); 98 | } 99 | else { 100 | break; 101 | } 102 | } 103 | 104 | if (!(found && consume)) { 105 | current = accum.slice(_accum.length) + current; 106 | pos = _pos; 107 | accum = _accum; 108 | } 109 | 110 | return found; 111 | }, 112 | // Wont't match past end of line. 113 | lookAheadRegex: function(regex, consume) { 114 | if (regex.source.charAt(0) != "^") 115 | throw new Error("Regexps passed to lookAheadRegex must start with ^"); 116 | 117 | // Fetch the rest of the line 118 | while (current.indexOf("\n", pos) == -1) { 119 | try {current += source.next();} 120 | catch (e) {if (e != StopIteration) throw e; break;} 121 | } 122 | var matched = current.slice(pos).match(regex); 123 | if (matched && consume) pos += matched[0].length; 124 | return matched; 125 | }, 126 | 127 | // Utils built on top of the above 128 | // more: -> boolean 129 | // Produce true if the stream isn't empty. 130 | more: function() { 131 | return this.peek() !== null; 132 | }, 133 | applies: function(test) { 134 | var next = this.peek(); 135 | return (next !== null && test(next)); 136 | }, 137 | nextWhile: function(test) { 138 | var next; 139 | while ((next = this.peek()) !== null && test(next)) 140 | this.next(); 141 | }, 142 | matches: function(re) { 143 | var next = this.peek(); 144 | return (next !== null && re.test(next)); 145 | }, 146 | nextWhileMatches: function(re) { 147 | var next; 148 | while ((next = this.peek()) !== null && re.test(next)) 149 | this.next(); 150 | }, 151 | equals: function(ch) { 152 | return ch === this.peek(); 153 | }, 154 | endOfLine: function() { 155 | var next = this.peek(); 156 | return next == null || next == "\n"; 157 | } 158 | }; 159 | }; 160 | -------------------------------------------------------------------------------- /js/tokenize.js: -------------------------------------------------------------------------------- 1 | // A framework for simple tokenizers. Takes care of newlines and 2 | // white-space, and of getting the text from the source stream into 3 | // the token object. A state is a function of two arguments -- a 4 | // string stream and a setState function. The second can be used to 5 | // change the tokenizer's state, and can be ignored for stateless 6 | // tokenizers. This function should advance the stream over a token 7 | // and return a string or object containing information about the next 8 | // token, or null to pass and have the (new) state be called to finish 9 | // the token. When a string is given, it is wrapped in a {style, type} 10 | // object. In the resulting object, the characters consumed are stored 11 | // under the content property. Any whitespace following them is also 12 | // automatically consumed, and added to the value property. (Thus, 13 | // content is the actual meaningful part of the token, while value 14 | // contains all the text it spans.) 15 | 16 | function tokenizer(source, state) { 17 | // Newlines are always a separate token. 18 | function isWhiteSpace(ch) { 19 | // The messy regexp is because IE's regexp matcher is of the 20 | // opinion that non-breaking spaces are no whitespace. 21 | return ch != "\n" && /^[\s\u00a0]*$/.test(ch); 22 | } 23 | 24 | var tokenizer = { 25 | state: state, 26 | 27 | take: function(type) { 28 | if (typeof(type) == "string") 29 | type = {style: type, type: type}; 30 | 31 | type.content = (type.content || "") + source.get(); 32 | if (!/\n$/.test(type.content)) 33 | source.nextWhile(isWhiteSpace); 34 | type.value = type.content + source.get(); 35 | return type; 36 | }, 37 | 38 | next: function () { 39 | if (!source.more()) throw StopIteration; 40 | 41 | var type; 42 | if (source.equals("\n")) { 43 | source.next(); 44 | return this.take("whitespace"); 45 | } 46 | 47 | if (source.applies(isWhiteSpace)) 48 | type = "whitespace"; 49 | else 50 | while (!type) 51 | type = this.state(source, function(s) {tokenizer.state = s;}); 52 | 53 | return this.take(type); 54 | } 55 | }; 56 | return tokenizer; 57 | } 58 | -------------------------------------------------------------------------------- /js/tokenizejavascript.js: -------------------------------------------------------------------------------- 1 | /* Tokenizer for JavaScript code */ 2 | 3 | var tokenizeJavaScript = (function() { 4 | // Advance the stream until the given character (not preceded by a 5 | // backslash) is encountered, or the end of the line is reached. 6 | function nextUntilUnescaped(source, end) { 7 | var escaped = false; 8 | while (!source.endOfLine()) { 9 | var next = source.next(); 10 | if (next == end && !escaped) 11 | return false; 12 | escaped = !escaped && next == "\\"; 13 | } 14 | return escaped; 15 | } 16 | 17 | // A map of JavaScript's keywords. The a/b/c keyword distinction is 18 | // very rough, but it gives the parser enough information to parse 19 | // correct code correctly (we don't care that much how we parse 20 | // incorrect code). The style information included in these objects 21 | // is used by the highlighter to pick the correct CSS style for a 22 | // token. 23 | var keywords = function(){ 24 | function result(type, style){ 25 | return {type: type, style: "js-" + style}; 26 | } 27 | // keywords that take a parenthised expression, and then a 28 | // statement (if) 29 | var keywordA = result("keyword a", "keyword"); 30 | // keywords that take just a statement (else) 31 | var keywordB = result("keyword b", "keyword"); 32 | // keywords that optionally take an expression, and form a 33 | // statement (return) 34 | var keywordC = result("keyword c", "keyword"); 35 | var operator = result("operator", "keyword"); 36 | var atom = result("atom", "atom"); 37 | return { 38 | "if": keywordA, "while": keywordA, "with": keywordA, 39 | "else": keywordB, "do": keywordB, "try": keywordB, "finally": keywordB, 40 | "return": keywordC, "break": keywordC, "continue": keywordC, "new": keywordC, "delete": keywordC, "throw": keywordC, 41 | "in": operator, "typeof": operator, "instanceof": operator, 42 | "var": result("var", "keyword"), "function": result("function", "keyword"), "catch": result("catch", "keyword"), 43 | "for": result("for", "keyword"), "switch": result("switch", "keyword"), 44 | "case": result("case", "keyword"), "default": result("default", "keyword"), 45 | "true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom 46 | }; 47 | }(); 48 | 49 | // Some helper regexps 50 | var isOperatorChar = /[+\-*&%=<>!?|]/; 51 | var isHexDigit = /[0-9A-Fa-f]/; 52 | var isWordChar = /[\w\$_]/; 53 | 54 | // Wrapper around jsToken that helps maintain parser state (whether 55 | // we are inside of a multi-line comment and whether the next token 56 | // could be a regular expression). 57 | function jsTokenState(inside, regexp) { 58 | return function(source, setState) { 59 | var newInside = inside; 60 | var type = jsToken(inside, regexp, source, function(c) {newInside = c;}); 61 | var newRegexp = type.type == "operator" || type.type == "keyword c" || type.type.match(/^[\[{}\(,;:]$/); 62 | if (newRegexp != regexp || newInside != inside) 63 | setState(jsTokenState(newInside, newRegexp)); 64 | return type; 65 | }; 66 | } 67 | 68 | // The token reader, intended to be used by the tokenizer from 69 | // tokenize.js (through jsTokenState). Advances the source stream 70 | // over a token, and returns an object containing the type and style 71 | // of that token. 72 | function jsToken(inside, regexp, source, setInside) { 73 | function readHexNumber(){ 74 | source.next(); // skip the 'x' 75 | source.nextWhileMatches(isHexDigit); 76 | return {type: "number", style: "js-atom"}; 77 | } 78 | 79 | function readNumber() { 80 | source.nextWhileMatches(/[0-9]/); 81 | if (source.equals(".")){ 82 | source.next(); 83 | source.nextWhileMatches(/[0-9]/); 84 | } 85 | if (source.equals("e") || source.equals("E")){ 86 | source.next(); 87 | if (source.equals("-")) 88 | source.next(); 89 | source.nextWhileMatches(/[0-9]/); 90 | } 91 | return {type: "number", style: "js-atom"}; 92 | } 93 | // Read a word, look it up in keywords. If not found, it is a 94 | // variable, otherwise it is a keyword of the type found. 95 | function readWord() { 96 | source.nextWhileMatches(isWordChar); 97 | var word = source.get(); 98 | var known = keywords.hasOwnProperty(word) && keywords.propertyIsEnumerable(word) && keywords[word]; 99 | return known ? {type: known.type, style: known.style, content: word} : 100 | {type: "variable", style: "js-variable", content: word}; 101 | } 102 | function readRegexp() { 103 | nextUntilUnescaped(source, "/"); 104 | source.nextWhileMatches(/[gimy]/); // 'y' is "sticky" option in Mozilla 105 | return {type: "regexp", style: "js-string"}; 106 | } 107 | // Mutli-line comments are tricky. We want to return the newlines 108 | // embedded in them as regular newline tokens, and then continue 109 | // returning a comment token for every line of the comment. So 110 | // some state has to be saved (inside) to indicate whether we are 111 | // inside a /* */ sequence. 112 | function readMultilineComment(start){ 113 | var newInside = "/*"; 114 | var maybeEnd = (start == "*"); 115 | while (true) { 116 | if (source.endOfLine()) 117 | break; 118 | var next = source.next(); 119 | if (next == "/" && maybeEnd){ 120 | newInside = null; 121 | break; 122 | } 123 | maybeEnd = (next == "*"); 124 | } 125 | setInside(newInside); 126 | return {type: "comment", style: "js-comment"}; 127 | } 128 | function readOperator() { 129 | source.nextWhileMatches(isOperatorChar); 130 | return {type: "operator", style: "js-operator"}; 131 | } 132 | function readString(quote) { 133 | var endBackSlash = nextUntilUnescaped(source, quote); 134 | setInside(endBackSlash ? quote : null); 135 | return {type: "string", style: "js-string"}; 136 | } 137 | 138 | // Fetch the next token. Dispatches on first character in the 139 | // stream, or first two characters when the first is a slash. 140 | if (inside == "\"" || inside == "'") 141 | return readString(inside); 142 | var ch = source.next(); 143 | if (inside == "/*") 144 | return readMultilineComment(ch); 145 | else if (ch == "\"" || ch == "'") 146 | return readString(ch); 147 | // with punctuation, the type of the token is the symbol itself 148 | else if (/[\[\]{}\(\),;\:\.]/.test(ch)) 149 | return {type: ch, style: "js-punctuation"}; 150 | else if (ch == "0" && (source.equals("x") || source.equals("X"))) 151 | return readHexNumber(); 152 | else if (/[0-9]/.test(ch)) 153 | return readNumber(); 154 | else if (ch == "/"){ 155 | if (source.equals("*")) 156 | { source.next(); return readMultilineComment(ch); } 157 | else if (source.equals("/")) 158 | { nextUntilUnescaped(source, null); return {type: "comment", style: "js-comment"};} 159 | else if (regexp) 160 | return readRegexp(); 161 | else 162 | return readOperator(); 163 | } 164 | else if (isOperatorChar.test(ch)) 165 | return readOperator(); 166 | else 167 | return readWord(); 168 | } 169 | 170 | // The external interface to the tokenizer. 171 | return function(source, startState) { 172 | return tokenizer(source, startState || jsTokenState(false, true)); 173 | }; 174 | })(); 175 | -------------------------------------------------------------------------------- /js/unittests.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Test Harness for CodeMirror 3 | * JS-unit compatible tests here. The two available assertions are 4 | * assertEquals (strict equality) and assertEquivalent (looser equivalency). 5 | * 6 | * 'editor' is a global object for the CodeMirror editor shared between all 7 | * tests. After manipulating it in each test, try to restore it to 8 | * approximately its original state. 9 | */ 10 | 11 | function testSetGet() { 12 | var code = 'It was the best of times.\nIt was the worst of times.'; 13 | editor.setCode(code); 14 | assertEquals(code, editor.getCode()); 15 | editor.setCode(''); 16 | assertEquals('', editor.getCode()); 17 | } 18 | 19 | function testSetStylesheet() { 20 | function cssStatus() { 21 | // Returns a list of tuples, for each CSS link return the filename and 22 | // whether it is enabled. 23 | links = editor.win.document.getElementsByTagName('link'); 24 | css = []; 25 | for (var x = 0, link; link = links[x]; x++) { 26 | if (link.rel.indexOf("stylesheet") !== -1) { 27 | css.push([link.href.substring(link.href.lastIndexOf('/') + 1), 28 | !link.disabled]) 29 | } 30 | } 31 | return css; 32 | } 33 | assertEquivalent([], cssStatus()); 34 | editor.setStylesheet('css/jscolors.css'); 35 | assertEquivalent([['jscolors.css', true]], cssStatus()); 36 | editor.setStylesheet(['css/csscolors.css', 'css/xmlcolors.css']); 37 | assertEquivalent([['jscolors.css', false], ['csscolors.css', true], ['xmlcolors.css', true]], cssStatus()); 38 | editor.setStylesheet([]); 39 | assertEquivalent([['jscolors.css', false], ['csscolors.css', false], ['xmlcolors.css', false]], cssStatus()); 40 | } 41 | 42 | // Update this list of tests as new ones are added. 43 | var tests = ['testSetGet', 'testSetStylesheet']; 44 | 45 | -------------------------------------------------------------------------------- /js/util.js: -------------------------------------------------------------------------------- 1 | /* A few useful utility functions. */ 2 | 3 | // Capture a method on an object. 4 | function method(obj, name) { 5 | return function() {obj[name].apply(obj, arguments);}; 6 | } 7 | 8 | // The value used to signal the end of a sequence in iterators. 9 | var StopIteration = {toString: function() {return "StopIteration"}}; 10 | 11 | // Apply a function to each element in a sequence. 12 | function forEach(iter, f) { 13 | if (iter.next) { 14 | try {while (true) f(iter.next());} 15 | catch (e) {if (e != StopIteration) throw e;} 16 | } 17 | else { 18 | for (var i = 0; i < iter.length; i++) 19 | f(iter[i]); 20 | } 21 | } 22 | 23 | // Map a function over a sequence, producing an array of results. 24 | function map(iter, f) { 25 | var accum = []; 26 | forEach(iter, function(val) {accum.push(f(val));}); 27 | return accum; 28 | } 29 | 30 | // Create a predicate function that tests a string againsts a given 31 | // regular expression. No longer used but might be used by 3rd party 32 | // parsers. 33 | function matcher(regexp){ 34 | return function(value){return regexp.test(value);}; 35 | } 36 | 37 | // Test whether a DOM node has a certain CSS class. 38 | function hasClass(element, className) { 39 | var classes = element.className; 40 | return classes && new RegExp("(^| )" + className + "($| )").test(classes); 41 | } 42 | function removeClass(element, className) { 43 | element.className = element.className.replace(new RegExp(" " + className + "\\b", "g"), ""); 44 | return element; 45 | } 46 | 47 | // Insert a DOM node after another node. 48 | function insertAfter(newNode, oldNode) { 49 | var parent = oldNode.parentNode; 50 | parent.insertBefore(newNode, oldNode.nextSibling); 51 | return newNode; 52 | } 53 | 54 | function removeElement(node) { 55 | if (node.parentNode) 56 | node.parentNode.removeChild(node); 57 | } 58 | 59 | function clearElement(node) { 60 | while (node.firstChild) 61 | node.removeChild(node.firstChild); 62 | } 63 | 64 | // Check whether a node is contained in another one. 65 | function isAncestor(node, child) { 66 | while (child = child.parentNode) { 67 | if (node == child) 68 | return true; 69 | } 70 | return false; 71 | } 72 | 73 | // The non-breaking space character. 74 | var nbsp = "\u00a0"; 75 | var matching = {"{": "}", "[": "]", "(": ")", 76 | "}": "{", "]": "[", ")": "("}; 77 | 78 | // Standardize a few unportable event properties. 79 | function normalizeEvent(event) { 80 | if (!event.stopPropagation) { 81 | event.stopPropagation = function() {this.cancelBubble = true;}; 82 | event.preventDefault = function() {this.returnValue = false;}; 83 | } 84 | if (!event.stop) { 85 | event.stop = function() { 86 | this.stopPropagation(); 87 | this.preventDefault(); 88 | }; 89 | } 90 | 91 | if (event.type == "keypress") { 92 | event.code = (event.charCode == null) ? event.keyCode : event.charCode; 93 | event.character = String.fromCharCode(event.code); 94 | } 95 | return event; 96 | } 97 | 98 | // Portably register event handlers. 99 | function addEventHandler(node, type, handler, removeFunc) { 100 | function wrapHandler(event) { 101 | handler(normalizeEvent(event || window.event)); 102 | } 103 | if (typeof node.addEventListener == "function") { 104 | node.addEventListener(type, wrapHandler, false); 105 | if (removeFunc) return function() {node.removeEventListener(type, wrapHandler, false);}; 106 | } 107 | else { 108 | node.attachEvent("on" + type, wrapHandler); 109 | if (removeFunc) return function() {node.detachEvent("on" + type, wrapHandler);}; 110 | } 111 | } 112 | 113 | function nodeText(node) { 114 | return node.textContent || node.innerText || node.nodeValue || ""; 115 | } 116 | 117 | function nodeTop(node) { 118 | var top = 0; 119 | while (node.offsetParent) { 120 | top += node.offsetTop; 121 | node = node.offsetParent; 122 | } 123 | return top; 124 | } 125 | 126 | function isBR(node) { 127 | var nn = node.nodeName; 128 | return nn == "BR" || nn == "br"; 129 | } 130 | function isSpan(node) { 131 | var nn = node.nodeName; 132 | return nn == "SPAN" || nn == "span"; 133 | } 134 | -------------------------------------------------------------------------------- /jstest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CodeMirror: JavaScript demonstration 6 | 7 | 8 | 9 | 10 |

This page demonstrates CodeMirror's 11 | JavaScript parser. Note that the ugly buttons at the top are not are 12 | not part of CodeMirror proper -- they demonstrate the way it can be 13 | embedded in a web-application.

14 | 15 |
16 | 40 |
41 | 42 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /mixedtest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: HTML mixed-mode demonstration 5 | 6 | 7 | 8 | 9 |

This is a simple demonstration of the HTML mixed-mode indentation 10 | module for CodeMirror. Script tags use the JS 11 | parser, style tags use the CSS parser.

12 | 13 |
14 | 41 |
42 | 43 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # CodeMirror 2 | 3 | **This repository is no longer being maintained.** 4 | 5 | All development work has shifted to 6 | [**https://github.com/marijnh/CodeMirror**](https://github.com/marijnh/CodeMirror). 7 | -------------------------------------------------------------------------------- /sparqltest.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: Sparql demonstration 5 | 6 | 7 | 8 | 9 |

Demonstration of CodeMirror's Sparql 10 | highlighter.

11 | 12 |
13 | 29 |
30 | 31 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /unittests.html: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | Test Harness for CodeMirror 11 | 12 | 13 | 14 | 106 | 107 | 108 | 109 |

Test Harness for CodeMirror

110 |
111 |
112 |
113 | 114 |
115 | 116 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /xhtmltest.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CodeMirror: HTML/XML demonstration 5 | 6 | 19 | 20 | 21 | 22 |

This file runs CodeMirror inside an XHTML document.

23 | 24 |
25 | 37 |
38 | 39 | 49 | 50 | 51 | --------------------------------------------------------------------------------