| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Depends on csslint.js from https://github.com/stubbornella/csslint | ||
|
|
||
| CodeMirror.registerHelper("lint", "css", function(text) { | ||
| var found = []; | ||
| var results = CSSLint.verify(text), messages = results.messages, message = null; | ||
| for ( var i = 0; i < messages.length; i++) { | ||
| message = messages[i]; | ||
| var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col; | ||
| found.push({ | ||
| from: CodeMirror.Pos(startLine, startCol), | ||
| to: CodeMirror.Pos(endLine, endCol), | ||
| message: message.message, | ||
| severity : message.type | ||
| }); | ||
| } | ||
| return found; | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,6 +103,7 @@ article { | |
| } | ||
|
|
||
| #logo { | ||
| border: 0; | ||
| margin-right: 7px; | ||
| margin-bottom: 25px; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| DTD mode | ||
| Ported to CodeMirror by Peter Kroon <plakroon@gmail.com> | ||
| Report bugs/issues here: https://github.com/marijnh/CodeMirror/issues | ||
| GitHub: @peterkroon | ||
| */ | ||
|
|
||
| CodeMirror.defineMode("dtd", function(config) { | ||
| var indentUnit = config.indentUnit, type; | ||
| function ret(style, tp) {type = tp; return style;} | ||
|
|
||
| function tokenBase(stream, state) { | ||
| var ch = stream.next(); | ||
|
|
||
| if (ch == "<" && stream.eat("!") ) { | ||
| if (stream.eatWhile(/[\-]/)) { | ||
| state.tokenize = tokenSGMLComment; | ||
| return tokenSGMLComment(stream, state); | ||
| } else if (stream.eatWhile(/[\w]/)) return ret("keyword", "doindent"); | ||
| } else if (ch == "<" && stream.eat("?")) { //xml declaration | ||
| state.tokenize = inBlock("meta", "?>"); | ||
| return ret("meta", ch); | ||
| } else if (ch == "#" && stream.eatWhile(/[\w]/)) return ret("atom", "tag"); | ||
| else if (ch == "|") return ret("keyword", "seperator"); | ||
| else if (ch.match(/[\(\)\[\]\-\.,\+\?>]/)) return ret(null, ch);//if(ch === ">") return ret(null, "endtag"); else | ||
| else if (ch.match(/[\[\]]/)) return ret("rule", ch); | ||
| else if (ch == "\"" || ch == "'") { | ||
| state.tokenize = tokenString(ch); | ||
| return state.tokenize(stream, state); | ||
| } else if (stream.eatWhile(/[a-zA-Z\?\+\d]/)) { | ||
| var sc = stream.current(); | ||
| if( sc.substr(sc.length-1,sc.length).match(/\?|\+/) !== null )stream.backUp(1); | ||
| return ret("tag", "tag"); | ||
| } else if (ch == "%" || ch == "*" ) return ret("number", "number"); | ||
| else { | ||
| stream.eatWhile(/[\w\\\-_%.{,]/); | ||
| return ret(null, null); | ||
| } | ||
| } | ||
|
|
||
| function tokenSGMLComment(stream, state) { | ||
| var dashes = 0, ch; | ||
| while ((ch = stream.next()) != null) { | ||
| if (dashes >= 2 && ch == ">") { | ||
| state.tokenize = tokenBase; | ||
| break; | ||
| } | ||
| dashes = (ch == "-") ? dashes + 1 : 0; | ||
| } | ||
| return ret("comment", "comment"); | ||
| } | ||
|
|
||
| function tokenString(quote) { | ||
| return function(stream, state) { | ||
| var escaped = false, ch; | ||
| while ((ch = stream.next()) != null) { | ||
| if (ch == quote && !escaped) { | ||
| state.tokenize = tokenBase; | ||
| break; | ||
| } | ||
| escaped = !escaped && ch == "\\"; | ||
| } | ||
| return ret("string", "tag"); | ||
| }; | ||
| } | ||
|
|
||
| function inBlock(style, terminator) { | ||
| return function(stream, state) { | ||
| while (!stream.eol()) { | ||
| if (stream.match(terminator)) { | ||
| state.tokenize = tokenBase; | ||
| break; | ||
| } | ||
| stream.next(); | ||
| } | ||
| return style; | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| startState: function(base) { | ||
| return {tokenize: tokenBase, | ||
| baseIndent: base || 0, | ||
| stack: []}; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| if (stream.eatSpace()) return null; | ||
| var style = state.tokenize(stream, state); | ||
|
|
||
| var context = state.stack[state.stack.length-1]; | ||
| if (stream.current() == "[" || type === "doindent" || type == "[") state.stack.push("rule"); | ||
| else if (type === "endtag") state.stack[state.stack.length-1] = "endtag"; | ||
| else if (stream.current() == "]" || type == "]" || (type == ">" && context == "rule")) state.stack.pop(); | ||
| else if (type == "[") state.stack.push("["); | ||
| return style; | ||
| }, | ||
|
|
||
| indent: function(state, textAfter) { | ||
| var n = state.stack.length; | ||
|
|
||
| if( textAfter.match(/\]\s+|\]/) )n=n-1; | ||
| else if(textAfter.substr(textAfter.length-1, textAfter.length) === ">"){ | ||
| if(textAfter.substr(0,1) === "<")n; | ||
| else if( type == "doindent" && textAfter.length > 1 )n; | ||
| else if( type == "doindent")n--; | ||
| else if( type == ">" && textAfter.length > 1)n; | ||
| else if( type == "tag" && textAfter !== ">")n; | ||
| else if( type == "tag" && state.stack[state.stack.length-1] == "rule")n--; | ||
| else if( type == "tag")n++; | ||
| else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule" && type === ">")n--; | ||
| else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule")n; | ||
| else if( textAfter.substr(0,1) !== "<" && textAfter.substr(0,1) === ">" )n=n-1; | ||
| else if( textAfter === ">")n; | ||
| else n=n-1; | ||
| //over rule them all | ||
| if(type == null || type == "]")n--; | ||
| } | ||
|
|
||
| return state.baseIndent + n * indentUnit; | ||
| }, | ||
|
|
||
| electricChars: "]>" | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME("application/xml-dtd", "dtd"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: DTD mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="dtd.js"></script> | ||
| <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/marijnh/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="#">DTD</a> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <article> | ||
| <h2>DTD mode</h2> | ||
| <form><textarea id="code" name="code"><?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!ATTLIST title | ||
| xmlns CDATA #FIXED "http://docbook.org/ns/docbook" | ||
| role CDATA #IMPLIED | ||
| %db.common.attributes; | ||
| %db.common.linking.attributes; | ||
| > | ||
|
|
||
| <!-- | ||
| Try: http://docbook.org/xml/5.0/dtd/docbook.dtd | ||
| --> | ||
|
|
||
| <!DOCTYPE xsl:stylesheet | ||
| [ | ||
| <!ENTITY nbsp "&#160;"> | ||
| <!ENTITY copy "&#169;"> | ||
| <!ENTITY reg "&#174;"> | ||
| <!ENTITY trade "&#8482;"> | ||
| <!ENTITY mdash "&#8212;"> | ||
| <!ENTITY ldquo "&#8220;"> | ||
| <!ENTITY rdquo "&#8221;"> | ||
| <!ENTITY pound "&#163;"> | ||
| <!ENTITY yen "&#165;"> | ||
| <!ENTITY euro "&#8364;"> | ||
| <!ENTITY mathml "http://www.w3.org/1998/Math/MathML"> | ||
| ] | ||
| > | ||
|
|
||
| <!ELEMENT title (#PCDATA|inlinemediaobject|remark|superscript|subscript|xref|link|olink|anchor|biblioref|alt|annotation|indexterm|abbrev|acronym|date|emphasis|footnote|footnoteref|foreignphrase|phrase|quote|wordasword|firstterm|glossterm|coref|trademark|productnumber|productname|database|application|hardware|citation|citerefentry|citetitle|citebiblioid|author|person|personname|org|orgname|editor|jobtitle|replaceable|package|parameter|termdef|nonterminal|systemitem|option|optional|property|inlineequation|tag|markup|token|symbol|literal|code|constant|email|uri|guiicon|guibutton|guimenuitem|guimenu|guisubmenu|guilabel|menuchoice|mousebutton|keycombo|keycap|keycode|keysym|shortcut|accel|prompt|envar|filename|command|computeroutput|userinput|function|varname|returnvalue|type|classname|exceptionname|interfacename|methodname|modifier|initializer|ooclass|ooexception|oointerface|errorcode|errortext|errorname|errortype)*> | ||
|
|
||
| <!ENTITY % db.common.attributes " | ||
| xml:id ID #IMPLIED | ||
| version CDATA #IMPLIED | ||
| xml:lang CDATA #IMPLIED | ||
| xml:base CDATA #IMPLIED | ||
| remap CDATA #IMPLIED | ||
| xreflabel CDATA #IMPLIED | ||
| revisionflag (changed|added|deleted|off) #IMPLIED | ||
| dir (ltr|rtl|lro|rlo) #IMPLIED | ||
| arch CDATA #IMPLIED | ||
| audience CDATA #IMPLIED | ||
| condition CDATA #IMPLIED | ||
| conformance CDATA #IMPLIED | ||
| os CDATA #IMPLIED | ||
| revision CDATA #IMPLIED | ||
| security CDATA #IMPLIED | ||
| userlevel CDATA #IMPLIED | ||
| vendor CDATA #IMPLIED | ||
| wordsize CDATA #IMPLIED | ||
| annotations CDATA #IMPLIED | ||
|
|
||
| "></textarea></form> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| mode: {name: "dtd", alignCDATA: true}, | ||
| lineNumbers: true, | ||
| lineWrapping: true | ||
| }); | ||
| </script> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>application/xml-dtd</code>.</p> | ||
| </article> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| CodeMirror.defineMode("fortran", function() { | ||
| function words(array) { | ||
| var keys = {}; | ||
| for (var i = 0; i < array.length; ++i) { | ||
| keys[array[i]] = true; | ||
| } | ||
| return keys; | ||
| } | ||
|
|
||
| var keywords = words([ | ||
| "abstract", "accept", "allocatable", "allocate", | ||
| "array", "assign", "asynchronous", "backspace", | ||
| "bind", "block", "byte", "call", "case", | ||
| "class", "close", "common", "contains", | ||
| "continue", "cycle", "data", "deallocate", | ||
| "decode", "deferred", "dimension", "do", | ||
| "elemental", "else", "encode", "end", | ||
| "endif", "entry", "enumerator", "equivalence", | ||
| "exit", "external", "extrinsic", "final", | ||
| "forall", "format", "function", "generic", | ||
| "go", "goto", "if", "implicit", "import", "include", | ||
| "inquire", "intent", "interface", "intrinsic", | ||
| "module", "namelist", "non_intrinsic", | ||
| "non_overridable", "none", "nopass", | ||
| "nullify", "open", "optional", "options", | ||
| "parameter", "pass", "pause", "pointer", | ||
| "print", "private", "program", "protected", | ||
| "public", "pure", "read", "recursive", "result", | ||
| "return", "rewind", "save", "select", "sequence", | ||
| "stop", "subroutine", "target", "then", "to", "type", | ||
| "use", "value", "volatile", "where", "while", | ||
| "write"]); | ||
| var builtins = words(["abort", "abs", "access", "achar", "acos", | ||
| "adjustl", "adjustr", "aimag", "aint", "alarm", | ||
| "all", "allocated", "alog", "amax", "amin", | ||
| "amod", "and", "anint", "any", "asin", | ||
| "associated", "atan", "besj", "besjn", "besy", | ||
| "besyn", "bit_size", "btest", "cabs", "ccos", | ||
| "ceiling", "cexp", "char", "chdir", "chmod", | ||
| "clog", "cmplx", "command_argument_count", | ||
| "complex", "conjg", "cos", "cosh", "count", | ||
| "cpu_time", "cshift", "csin", "csqrt", "ctime", | ||
| "c_funloc", "c_loc", "c_associated", "c_null_ptr", | ||
| "c_null_funptr", "c_f_pointer", "c_null_char", | ||
| "c_alert", "c_backspace", "c_form_feed", | ||
| "c_new_line", "c_carriage_return", | ||
| "c_horizontal_tab", "c_vertical_tab", "dabs", | ||
| "dacos", "dasin", "datan", "date_and_time", | ||
| "dbesj", "dbesj", "dbesjn", "dbesy", "dbesy", | ||
| "dbesyn", "dble", "dcos", "dcosh", "ddim", "derf", | ||
| "derfc", "dexp", "digits", "dim", "dint", "dlog", | ||
| "dlog", "dmax", "dmin", "dmod", "dnint", | ||
| "dot_product", "dprod", "dsign", "dsinh", | ||
| "dsin", "dsqrt", "dtanh", "dtan", "dtime", | ||
| "eoshift", "epsilon", "erf", "erfc", "etime", | ||
| "exit", "exp", "exponent", "extends_type_of", | ||
| "fdate", "fget", "fgetc", "float", "floor", | ||
| "flush", "fnum", "fputc", "fput", "fraction", | ||
| "fseek", "fstat", "ftell", "gerror", "getarg", | ||
| "get_command", "get_command_argument", | ||
| "get_environment_variable", "getcwd", | ||
| "getenv", "getgid", "getlog", "getpid", | ||
| "getuid", "gmtime", "hostnm", "huge", "iabs", | ||
| "iachar", "iand", "iargc", "ibclr", "ibits", | ||
| "ibset", "ichar", "idate", "idim", "idint", | ||
| "idnint", "ieor", "ierrno", "ifix", "imag", | ||
| "imagpart", "index", "int", "ior", "irand", | ||
| "isatty", "ishft", "ishftc", "isign", | ||
| "iso_c_binding", "is_iostat_end", "is_iostat_eor", | ||
| "itime", "kill", "kind", "lbound", "len", "len_trim", | ||
| "lge", "lgt", "link", "lle", "llt", "lnblnk", "loc", | ||
| "log", "logical", "long", "lshift", "lstat", "ltime", | ||
| "matmul", "max", "maxexponent", "maxloc", "maxval", | ||
| "mclock", "merge", "move_alloc", "min", "minexponent", | ||
| "minloc", "minval", "mod", "modulo", "mvbits", | ||
| "nearest", "new_line", "nint", "not", "or", "pack", | ||
| "perror", "precision", "present", "product", "radix", | ||
| "rand", "random_number", "random_seed", "range", | ||
| "real", "realpart", "rename", "repeat", "reshape", | ||
| "rrspacing", "rshift", "same_type_as", "scale", | ||
| "scan", "second", "selected_int_kind", | ||
| "selected_real_kind", "set_exponent", "shape", | ||
| "short", "sign", "signal", "sinh", "sin", "sleep", | ||
| "sngl", "spacing", "spread", "sqrt", "srand", "stat", | ||
| "sum", "symlnk", "system", "system_clock", "tan", | ||
| "tanh", "time", "tiny", "transfer", "transpose", | ||
| "trim", "ttynam", "ubound", "umask", "unlink", | ||
| "unpack", "verify", "xor", "zabs", "zcos", "zexp", | ||
| "zlog", "zsin", "zsqrt"]); | ||
|
|
||
| var dataTypes = words(["c_bool", "c_char", "c_double", "c_double_complex", | ||
| "c_float", "c_float_complex", "c_funptr", "c_int", | ||
| "c_int16_t", "c_int32_t", "c_int64_t", "c_int8_t", | ||
| "c_int_fast16_t", "c_int_fast32_t", "c_int_fast64_t", | ||
| "c_int_fast8_t", "c_int_least16_t", "c_int_least32_t", | ||
| "c_int_least64_t", "c_int_least8_t", "c_intmax_t", | ||
| "c_intptr_t", "c_long", "c_long_double", | ||
| "c_long_double_complex", "c_long_long", "c_ptr", | ||
| "c_short", "c_signed_char", "c_size_t", "character", | ||
| "complex", "double", "integer", "logical", "real"]); | ||
| var isOperatorChar = /[+\-*&=<>\/\:]/; | ||
| var litOperator = new RegExp("(\.and\.|\.or\.|\.eq\.|\.lt\.|\.le\.|\.gt\.|\.ge\.|\.ne\.|\.not\.|\.eqv\.|\.neqv\.)", "i"); | ||
|
|
||
| function tokenBase(stream, state) { | ||
|
|
||
| if (stream.match(litOperator)){ | ||
| return 'operator'; | ||
| } | ||
|
|
||
| var ch = stream.next(); | ||
| if (ch == "!") { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } | ||
| if (ch == '"' || ch == "'") { | ||
| state.tokenize = tokenString(ch); | ||
| return state.tokenize(stream, state); | ||
| } | ||
| if (/[\[\]\(\),]/.test(ch)) { | ||
| return null; | ||
| } | ||
| if (/\d/.test(ch)) { | ||
| stream.eatWhile(/[\w\.]/); | ||
| return "number"; | ||
| } | ||
| if (isOperatorChar.test(ch)) { | ||
| stream.eatWhile(isOperatorChar); | ||
| return "operator"; | ||
| } | ||
| stream.eatWhile(/[\w\$_]/); | ||
| var word = stream.current().toLowerCase(); | ||
|
|
||
| if (keywords.hasOwnProperty(word)){ | ||
| return 'keyword'; | ||
| } | ||
| if (builtins.hasOwnProperty(word) || dataTypes.hasOwnProperty(word)) { | ||
| return 'builtin'; | ||
| } | ||
| return "variable"; | ||
| } | ||
|
|
||
| function tokenString(quote) { | ||
| return function(stream, state) { | ||
| var escaped = false, next, end = false; | ||
| while ((next = stream.next()) != null) { | ||
| if (next == quote && !escaped) { | ||
| end = true; | ||
| break; | ||
| } | ||
| escaped = !escaped && next == "\\"; | ||
| } | ||
| if (end || !escaped) state.tokenize = null; | ||
| return "string"; | ||
| }; | ||
| } | ||
|
|
||
| // Interface | ||
|
|
||
| return { | ||
| startState: function() { | ||
| return {tokenize: null}; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| if (stream.eatSpace()) return null; | ||
| var style = (state.tokenize || tokenBase)(stream, state); | ||
| if (style == "comment" || style == "meta") return style; | ||
| return style; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME("text/x-fortran", "fortran"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: Fortran mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="fortran.js"></script> | ||
| <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/marijnh/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="#">Fortran</a> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <article> | ||
| <h2>Fortran mode</h2> | ||
|
|
||
|
|
||
| <div><textarea id="code" name="code"> | ||
| ! Example Fortran code | ||
| program average | ||
|
|
||
| ! Read in some numbers and take the average | ||
| ! As written, if there are no data points, an average of zero is returned | ||
| ! While this may not be desired behavior, it keeps this example simple | ||
|
|
||
| implicit none | ||
|
|
||
| real, dimension(:), allocatable :: points | ||
| integer :: number_of_points | ||
| real :: average_points=0., positive_average=0., negative_average=0. | ||
|
|
||
| write (*,*) "Input number of points to average:" | ||
| read (*,*) number_of_points | ||
|
|
||
| allocate (points(number_of_points)) | ||
|
|
||
| write (*,*) "Enter the points to average:" | ||
| read (*,*) points | ||
|
|
||
| ! Take the average by summing points and dividing by number_of_points | ||
| if (number_of_points > 0) average_points = sum(points) / number_of_points | ||
|
|
||
| ! Now form average over positive and negative points only | ||
| if (count(points > 0.) > 0) then | ||
| positive_average = sum(points, points > 0.) / count(points > 0.) | ||
| end if | ||
|
|
||
| if (count(points < 0.) > 0) then | ||
| negative_average = sum(points, points < 0.) / count(points < 0.) | ||
| end if | ||
|
|
||
| deallocate (points) | ||
|
|
||
| ! Print result to terminal | ||
| write (*,'(a,g12.4)') 'Average = ', average_points | ||
| write (*,'(a,g12.4)') 'Average of positive points = ', positive_average | ||
| write (*,'(a,g12.4)') 'Average of negative points = ', negative_average | ||
| end program average | ||
| </textarea></div> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| lineNumbers: true, | ||
| mode: "text/x-fortran" | ||
| }); | ||
| </script> | ||
| <p><strong>MIME types defined:</strong> <code>text/x-Fortran</code>.</p> | ||
| </article> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: Octave mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="octave.js"></script> | ||
| <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/marijnh/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="#">Octave</a> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <article> | ||
| <h2>Octave mode</h2> | ||
|
|
||
| <div><textarea id="code" name="code"> | ||
| %numbers | ||
| 1234 | ||
| 1234i | ||
| 1234j | ||
| .234 | ||
| .234j | ||
| 2.23i | ||
| 23e2 | ||
| 12E1j | ||
| 123D-4 | ||
| 0x234 | ||
|
|
||
| %strings | ||
| 'asda''a' | ||
| "asda""a" | ||
|
|
||
| %identifiers | ||
| a | ||
| as123 | ||
| __asd__ | ||
|
|
||
| %operators | ||
| - | ||
| + | ||
| = | ||
| == | ||
| > | ||
| < | ||
| >= | ||
| <= | ||
| & | ||
| ~ | ||
| ... | ||
| break zeros default margin round ones rand | ||
| ceil floor size clear zeros eye mean std cov | ||
| error eval function | ||
| abs acos atan asin cos cosh exp log prod sum | ||
| log10 max min sign sin sinh sqrt tan reshape | ||
| return | ||
| case switch | ||
| else elseif end if otherwise | ||
| do for while | ||
| try catch | ||
| classdef properties events methods | ||
| global persistent | ||
|
|
||
| %one line comment | ||
| ...one line comment | ||
| %{ multi | ||
| line commment %} | ||
| 1 | ||
|
|
||
| </textarea></div> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| mode: {name: "octave", | ||
| version: 2, | ||
| singleLineStringErrors: false}, | ||
| lineNumbers: true, | ||
| indentUnit: 4, | ||
| tabMode: "shift", | ||
| matchBrackets: true | ||
| }); | ||
| </script> | ||
|
|
||
| <p><strong>MIME types defined:</strong> <code>text/x-octave</code>.</p> | ||
| </article> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| CodeMirror.defineMode("octave", function() { | ||
| function wordRegexp(words) { | ||
| return new RegExp("^((" + words.join(")|(") + "))\\b"); | ||
| } | ||
|
|
||
| var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]"); | ||
| var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;]'); | ||
| var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))"); | ||
| var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))"); | ||
| var tripleDelimiters = new RegExp("^((>>=)|(<<=))"); | ||
| var expressionEnd = new RegExp("^[\\]\\)]"); | ||
| var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*"); | ||
|
|
||
| var builtins = wordRegexp([ | ||
| 'error', 'eval', 'function', 'abs', 'acos', 'atan', 'asin', 'cos', | ||
| 'cosh', 'exp', 'log', 'prod', 'log10', 'max', 'min', 'sign', 'sin', 'sinh', | ||
| 'sqrt', 'tan', 'reshape', 'break', 'zeros', 'default', 'margin', 'round', 'ones', | ||
| 'rand', 'syn', 'ceil', 'floor', 'size', 'clear', 'zeros', 'eye', 'mean', 'std', 'cov', | ||
| 'det', 'eig', 'inv', 'norm', 'rank', 'trace', 'expm', 'logm', 'sqrtm', 'linspace', 'plot', | ||
| 'title', 'xlabel', 'ylabel', 'legend', 'text', 'meshgrid', 'mesh', 'num2str' | ||
| ]); | ||
|
|
||
| var keywords = wordRegexp([ | ||
| 'return', 'case', 'switch', 'else', 'elseif', 'end', 'endif', 'endfunction', | ||
| 'if', 'otherwise', 'do', 'for', 'while', 'try', 'catch', 'classdef', 'properties', 'events', | ||
| 'methods', 'global', 'persistent', 'endfor', 'endwhile', 'printf', 'disp', 'until', 'continue' | ||
| ]); | ||
|
|
||
|
|
||
| // tokenizers | ||
| function tokenTranspose(stream, state) { | ||
| if (!stream.sol() && stream.peek() === '\'') { | ||
| stream.next(); | ||
| state.tokenize = tokenBase; | ||
| return 'operator'; | ||
| } | ||
| state.tokenize = tokenBase; | ||
| return tokenBase(stream, state); | ||
| } | ||
|
|
||
|
|
||
| function tokenComment(stream, state) { | ||
| if (stream.match(/^.*%}/)) { | ||
| state.tokenize = tokenBase; | ||
| return 'comment'; | ||
| }; | ||
| stream.skipToEnd(); | ||
| return 'comment'; | ||
| } | ||
|
|
||
| function tokenBase(stream, state) { | ||
| // whitespaces | ||
| if (stream.eatSpace()) return null; | ||
|
|
||
| // Handle one line Comments | ||
| if (stream.match('%{')){ | ||
| state.tokenize = tokenComment; | ||
| stream.skipToEnd(); | ||
| return 'comment'; | ||
| } | ||
|
|
||
| if (stream.match(/^(%)|(\.\.\.)/)){ | ||
| stream.skipToEnd(); | ||
| return 'comment'; | ||
| } | ||
|
|
||
| // Handle Number Literals | ||
| if (stream.match(/^[0-9\.+-]/, false)) { | ||
| if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) { | ||
| stream.tokenize = tokenBase; | ||
| return 'number'; }; | ||
| if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; }; | ||
| if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; }; | ||
| } | ||
| if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; }; | ||
|
|
||
| // Handle Strings | ||
| if (stream.match(/^"([^"]|(""))*"/)) { return 'string'; } ; | ||
| if (stream.match(/^'([^']|(''))*'/)) { return 'string'; } ; | ||
|
|
||
| // Handle words | ||
| if (stream.match(keywords)) { return 'keyword'; } ; | ||
| if (stream.match(builtins)) { return 'builtin'; } ; | ||
| if (stream.match(identifiers)) { return 'variable'; } ; | ||
|
|
||
| if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; }; | ||
| if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; }; | ||
|
|
||
| if (stream.match(expressionEnd)) { | ||
| state.tokenize = tokenTranspose; | ||
| return null; | ||
| }; | ||
|
|
||
|
|
||
| // Handle non-detected items | ||
| stream.next(); | ||
| return 'error'; | ||
| }; | ||
|
|
||
|
|
||
| return { | ||
| startState: function() { | ||
| return { | ||
| tokenize: tokenBase | ||
| }; | ||
| }, | ||
|
|
||
| token: function(stream, state) { | ||
| var style = state.tokenize(stream, state); | ||
| if (style === 'number' || style === 'variable'){ | ||
| state.tokenize = tokenTranspose; | ||
| } | ||
| return style; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME("text/x-octave", "octave"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <!doctype html> | ||
|
|
||
| <title>CodeMirror: TOML Mode</title> | ||
| <meta charset="utf-8"/> | ||
| <link rel=stylesheet href="../../doc/docs.css"> | ||
|
|
||
| <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
| <script src="../../lib/codemirror.js"></script> | ||
| <script src="toml.js"></script> | ||
| <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
| <div id=nav> | ||
| <a href="http://codemirror.net"><img id=logo src="../../doc/logo.png"></a> | ||
|
|
||
| <ul> | ||
| <li><a href="../../index.html">Home</a> | ||
| <li><a href="../../doc/manual.html">Manual</a> | ||
| <li><a href="https://github.com/marijnh/codemirror">Code</a> | ||
| </ul> | ||
| <ul> | ||
| <li><a href="../index.html">Language modes</a> | ||
| <li><a class=active href="#">TOML Mode</a> | ||
| </ul> | ||
| </div> | ||
|
|
||
| <article> | ||
| <h2>TOML Mode</h2> | ||
| <form><textarea id="code" name="code"> | ||
| # This is a TOML document. Boom. | ||
|
|
||
| title = "TOML Example" | ||
|
|
||
| [owner] | ||
| name = "Tom Preston-Werner" | ||
| organization = "GitHub" | ||
| bio = "GitHub Cofounder & CEO\nLikes tater tots and beer." | ||
| dob = 1979-05-27T07:32:00Z # First class dates? Why not? | ||
|
|
||
| [database] | ||
| server = "192.168.1.1" | ||
| ports = [ 8001, 8001, 8002 ] | ||
| connection_max = 5000 | ||
| enabled = true | ||
|
|
||
| [servers] | ||
|
|
||
| # You can indent as you please. Tabs or spaces. TOML don't care. | ||
| [servers.alpha] | ||
| ip = "10.0.0.1" | ||
| dc = "eqdc10" | ||
|
|
||
| [servers.beta] | ||
| ip = "10.0.0.2" | ||
| dc = "eqdc10" | ||
|
|
||
| [clients] | ||
| data = [ ["gamma", "delta"], [1, 2] ] | ||
|
|
||
| # Line breaks are OK when inside arrays | ||
| hosts = [ | ||
| "alpha", | ||
| "omega" | ||
| ] | ||
| </textarea></form> | ||
| <script> | ||
| var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
| mode: {name: "toml"}, | ||
| lineNumbers: true | ||
| }); | ||
| </script> | ||
| <h3>The TOML Mode</h3> | ||
| <p> Created by Forbes Lindesay.</p> | ||
| <p><strong>MIME type defined:</strong> <code>text/x-toml</code>.</p> | ||
| </article> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| CodeMirror.defineMode("toml", function () { | ||
| return { | ||
| startState: function () { | ||
| return { | ||
| inString: false, | ||
| stringType: "", | ||
| lhs: true, | ||
| inArray: 0 | ||
| }; | ||
| }, | ||
| token: function (stream, state) { | ||
| //check for state changes | ||
| if (!state.inString && ((stream.peek() == '"') || (stream.peek() == "'"))) { | ||
| state.stringType = stream.peek(); | ||
| stream.next(); // Skip quote | ||
| state.inString = true; // Update state | ||
| } | ||
| if (stream.sol() && state.inArray === 0) { | ||
| state.lhs = true; | ||
| } | ||
| //return state | ||
| if (state.inString) { | ||
| while (state.inString && !stream.eol()) { | ||
| if (stream.peek() === state.stringType) { | ||
| stream.next(); // Skip quote | ||
| state.inString = false; // Clear flag | ||
| } else if (stream.peek() === '\\') { | ||
| stream.next(); | ||
| stream.next(); | ||
| } else { | ||
| stream.match(/^.[^\\\"\']*/); | ||
| } | ||
| } | ||
| return state.lhs ? "property string" : "string"; // Token style | ||
| } else if (state.inArray && stream.peek() === ']') { | ||
| stream.next(); | ||
| state.inArray--; | ||
| return 'bracket'; | ||
| } else if (state.lhs && stream.peek() === '[' && stream.skipTo(']')) { | ||
| stream.next();//skip closing ] | ||
| return "atom"; | ||
| } else if (stream.peek() === "#") { | ||
| stream.skipToEnd(); | ||
| return "comment"; | ||
| } else if (stream.eatSpace()) { | ||
| return null; | ||
| } else if (state.lhs && stream.eatWhile(function (c) { return c != '=' && c != ' '; })) { | ||
| return "property"; | ||
| } else if (state.lhs && stream.peek() === "=") { | ||
| stream.next(); | ||
| state.lhs = false; | ||
| return null; | ||
| } else if (!state.lhs && stream.match(/^\d\d\d\d[\d\-\:\.T]*Z/)) { | ||
| return 'atom'; //date | ||
| } else if (!state.lhs && (stream.match('true') || stream.match('false'))) { | ||
| return 'atom'; | ||
| } else if (!state.lhs && stream.peek() === '[') { | ||
| state.inArray++; | ||
| stream.next(); | ||
| return 'bracket'; | ||
| } else if (!state.lhs && stream.match(/^\-?\d+(?:\.\d+)?/)) { | ||
| return 'number'; | ||
| } else if (!stream.eatSpace()) { | ||
| stream.next(); | ||
| } | ||
| return null; | ||
| } | ||
| }; | ||
| }); | ||
|
|
||
| CodeMirror.defineMIME('text/x-toml', 'toml'); |