LaravelTest
146 строк · 4.3 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("jinja2", function() {15var keywords = ["and", "as", "block", "endblock", "by", "cycle", "debug", "else", "elif",16"extends", "filter", "endfilter", "firstof", "for",17"endfor", "if", "endif", "ifchanged", "endifchanged",18"ifequal", "endifequal", "ifnotequal",19"endifnotequal", "in", "include", "load", "not", "now", "or",20"parsed", "regroup", "reversed", "spaceless",21"endspaceless", "ssi", "templatetag", "openblock",22"closeblock", "openvariable", "closevariable",23"openbrace", "closebrace", "opencomment",24"closecomment", "widthratio", "url", "with", "endwith",25"get_current_language", "trans", "endtrans", "noop", "blocktrans",26"endblocktrans", "get_available_languages",27"get_current_language_bidi", "plural"],28operator = /^[+\-*&%=<>!?|~^]/,29sign = /^[:\[\(\{]/,30atom = ["true", "false"],31number = /^(\d[+\-\*\/])?\d+(\.\d+)?/;32
33keywords = new RegExp("((" + keywords.join(")|(") + "))\\b");34atom = new RegExp("((" + atom.join(")|(") + "))\\b");35
36function tokenBase (stream, state) {37var ch = stream.peek();38
39//Comment40if (state.incomment) {41if(!stream.skipTo("#}")) {42stream.skipToEnd();43} else {44stream.eatWhile(/\#|}/);45state.incomment = false;46}47return "comment";48//Tag49} else if (state.intag) {50//After operator51if(state.operator) {52state.operator = false;53if(stream.match(atom)) {54return "atom";55}56if(stream.match(number)) {57return "number";58}59}60//After sign61if(state.sign) {62state.sign = false;63if(stream.match(atom)) {64return "atom";65}66if(stream.match(number)) {67return "number";68}69}70
71if(state.instring) {72if(ch == state.instring) {73state.instring = false;74}75stream.next();76return "string";77} else if(ch == "'" || ch == '"') {78state.instring = ch;79stream.next();80return "string";81} else if(stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}")) {82state.intag = false;83return "tag";84} else if(stream.match(operator)) {85state.operator = true;86return "operator";87} else if(stream.match(sign)) {88state.sign = true;89} else {90if(stream.eat(" ") || stream.sol()) {91if(stream.match(keywords)) {92return "keyword";93}94if(stream.match(atom)) {95return "atom";96}97if(stream.match(number)) {98return "number";99}100if(stream.sol()) {101stream.next();102}103} else {104stream.next();105}106
107}108return "variable";109} else if (stream.eat("{")) {110if (stream.eat("#")) {111state.incomment = true;112if(!stream.skipTo("#}")) {113stream.skipToEnd();114} else {115stream.eatWhile(/\#|}/);116state.incomment = false;117}118return "comment";119//Open tag120} else if (ch = stream.eat(/\{|%/)) {121//Cache close tag122state.intag = ch;123if(ch == "{") {124state.intag = "}";125}126stream.eat("-");127return "tag";128}129}130stream.next();131};132
133return {134startState: function () {135return {tokenize: tokenBase};136},137token: function (stream, state) {138return state.tokenize(stream, state);139},140blockCommentStart: "{#",141blockCommentEnd: "#}"142};143});144
145CodeMirror.defineMIME("text/jinja2", "jinja2");146});147