5
if (typeof exports == "object" && typeof module == "object")
6
mod(require("../../lib/codemirror"), require("../../addon/mode/multiplex"));
7
else if (typeof define == "function" && define.amd)
8
define(["../../lib/codemirror", "../../addon/mode/multiplex"], mod);
11
})(function(CodeMirror) {
14
CodeMirror.defineMode("twig:inner", function() {
15
var 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"],
16
operator = /^[+\-*&%=<>!?|~^]/,
18
atom = ["true", "false", "null", "empty", "defined", "divisibleby", "divisible by", "even", "odd", "iterable", "sameas", "same as"],
19
number = /^(\d[+\-\*\/])?\d+(\.\d+)?/;
21
keywords = new RegExp("((" + keywords.join(")|(") + "))\\b");
22
atom = new RegExp("((" + atom.join(")|(") + "))\\b");
24
function tokenBase (stream, state) {
25
var ch = stream.peek();
28
if (state.incomment) {
29
if (!stream.skipTo("#}")) {
32
stream.eatWhile(/\#|}/);
33
state.incomment = false;
37
} else if (state.intag) {
40
state.operator = false;
41
if (stream.match(atom)) {
44
if (stream.match(number)) {
51
if (stream.match(atom)) {
54
if (stream.match(number)) {
60
if (ch == state.instring) {
61
state.instring = false;
65
} else if (ch == "'" || ch == '"') {
69
} else if (stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}")) {
72
} else if (stream.match(operator)) {
73
state.operator = true;
75
} else if (stream.match(sign)) {
78
if (stream.eat(" ") || stream.sol()) {
79
if (stream.match(keywords)) {
82
if (stream.match(atom)) {
85
if (stream.match(number)) {
97
} else if (stream.eat("{")) {
98
if (stream.eat("#")) {
99
state.incomment = true;
100
if (!stream.skipTo("#}")) {
103
stream.eatWhile(/\#|}/);
104
state.incomment = false;
108
} else if (ch = stream.eat(/\{|%/)) {
122
startState: function () {
125
token: function (stream, state) {
126
return tokenBase(stream, state);
131
CodeMirror.defineMode("twig", function(config, parserConfig) {
132
var twigInner = CodeMirror.getMode(config, "twig:inner");
133
if (!parserConfig || !parserConfig.base) return twigInner;
134
return CodeMirror.multiplexingMode(
135
CodeMirror.getMode(config, parserConfig.base), {
136
open: /\{[{#%]/, close: /[}#%]\}/, mode: twigInner, parseDelimiters: true
140
CodeMirror.defineMIME("text/x-twig", "twig");