LaravelTest
141 строка · 4.5 Кб
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"), require("../../addon/mode/multiplex"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../../addon/mode/multiplex"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("twig:inner", function() {15var keywords = ["and", "as", "autoescape", "endautoescape", "block", "do", "endblock", "else", "elseif", "extends", "for", "endfor", "embed", "endembed", "filter", "endfilter", "flush", "from", "if", "endif", "in", "is", "include", "import", "not", "or", "set", "spaceless", "endspaceless", "with", "endwith", "trans", "endtrans", "blocktrans", "endblocktrans", "macro", "endmacro", "use", "verbatim", "endverbatim"],16operator = /^[+\-*&%=<>!?|~^]/,17sign = /^[:\[\(\{]/,18atom = ["true", "false", "null", "empty", "defined", "divisibleby", "divisible by", "even", "odd", "iterable", "sameas", "same as"],19number = /^(\d[+\-\*\/])?\d+(\.\d+)?/;20
21keywords = new RegExp("((" + keywords.join(")|(") + "))\\b");22atom = new RegExp("((" + atom.join(")|(") + "))\\b");23
24function tokenBase (stream, state) {25var ch = stream.peek();26
27//Comment28if (state.incomment) {29if (!stream.skipTo("#}")) {30stream.skipToEnd();31} else {32stream.eatWhile(/\#|}/);33state.incomment = false;34}35return "comment";36//Tag37} else if (state.intag) {38//After operator39if (state.operator) {40state.operator = false;41if (stream.match(atom)) {42return "atom";43}44if (stream.match(number)) {45return "number";46}47}48//After sign49if (state.sign) {50state.sign = false;51if (stream.match(atom)) {52return "atom";53}54if (stream.match(number)) {55return "number";56}57}58
59if (state.instring) {60if (ch == state.instring) {61state.instring = false;62}63stream.next();64return "string";65} else if (ch == "'" || ch == '"') {66state.instring = ch;67stream.next();68return "string";69} else if (stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}")) {70state.intag = false;71return "tag";72} else if (stream.match(operator)) {73state.operator = true;74return "operator";75} else if (stream.match(sign)) {76state.sign = true;77} else {78if (stream.eat(" ") || stream.sol()) {79if (stream.match(keywords)) {80return "keyword";81}82if (stream.match(atom)) {83return "atom";84}85if (stream.match(number)) {86return "number";87}88if (stream.sol()) {89stream.next();90}91} else {92stream.next();93}94
95}96return "variable";97} else if (stream.eat("{")) {98if (stream.eat("#")) {99state.incomment = true;100if (!stream.skipTo("#}")) {101stream.skipToEnd();102} else {103stream.eatWhile(/\#|}/);104state.incomment = false;105}106return "comment";107//Open tag108} else if (ch = stream.eat(/\{|%/)) {109//Cache close tag110state.intag = ch;111if (ch == "{") {112state.intag = "}";113}114stream.eat("-");115return "tag";116}117}118stream.next();119};120
121return {122startState: function () {123return {};124},125token: function (stream, state) {126return tokenBase(stream, state);127}128};129});130
131CodeMirror.defineMode("twig", function(config, parserConfig) {132var twigInner = CodeMirror.getMode(config, "twig:inner");133if (!parserConfig || !parserConfig.base) return twigInner;134return CodeMirror.multiplexingMode(135CodeMirror.getMode(config, parserConfig.base), {136open: /\{[{#%]/, close: /[}#%]\}/, mode: twigInner, parseDelimiters: true137}138);139});140CodeMirror.defineMIME("text/x-twig", "twig");141});142