aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/smarty/smarty.js
diff options
context:
space:
mode:
authorArmen Kesablyan2012-05-08 16:43:43 -0700
committerArmen Kesablyan2012-05-08 16:43:43 -0700
commitdc075ffcc6dd03c090d90fad999eee9b924d56ee (patch)
tree867f8bdd588c8f9076979233ca46a688ff70523e /imports/codemirror/mode/smarty/smarty.js
parent5d7e470351fd150d5e70a97332fa2f2553797499 (diff)
parent4d949f141247215b5f2a6ec0cfc7d2d31cf2bb1f (diff)
downloadninja-dc075ffcc6dd03c090d90fad999eee9b924d56ee.tar.gz
Merge branch 'refs/heads/dom-architecture' into binding
Conflicts: js/components/layout/tools-properties.reel/tools-properties.html Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'imports/codemirror/mode/smarty/smarty.js')
-rw-r--r--imports/codemirror/mode/smarty/smarty.js148
1 files changed, 148 insertions, 0 deletions
diff --git a/imports/codemirror/mode/smarty/smarty.js b/imports/codemirror/mode/smarty/smarty.js
new file mode 100644
index 00000000..9da7da62
--- /dev/null
+++ b/imports/codemirror/mode/smarty/smarty.js
@@ -0,0 +1,148 @@
1CodeMirror.defineMode("smarty", function(config, parserConfig) {
2 var keyFuncs = ["debug", "extends", "function", "include", "literal"];
3 var last;
4 var regs = {
5 operatorChars: /[+\-*&%=<>!?]/,
6 validIdentifier: /[a-zA-Z0-9\_]/,
7 stringChar: /[\'\"]/
8 }
9 var leftDelim = (typeof config.mode.leftDelimiter != 'undefined') ? config.mode.leftDelimiter : "{";
10 var rightDelim = (typeof config.mode.rightDelimiter != 'undefined') ? config.mode.rightDelimiter : "}";
11 function ret(style, lst) { last = lst; return style; }
12
13
14 function tokenizer(stream, state) {
15 function chain(parser) {
16 state.tokenize = parser;
17 return parser(stream, state);
18 }
19
20 if (stream.match(leftDelim, true)) {
21 if (stream.eat("*")) {
22 return chain(inBlock("comment", "*" + rightDelim));
23 }
24 else {
25 state.tokenize = inSmarty;
26 return "tag";
27 }
28 }
29 else {
30 // I'd like to do an eatWhile() here, but I can't get it to eat only up to the rightDelim string/char
31 stream.next();
32 return null;
33 }
34 }
35
36 function inSmarty(stream, state) {
37 if (stream.match(rightDelim, true)) {
38 state.tokenize = tokenizer;
39 return ret("tag", null);
40 }
41
42 var ch = stream.next();
43 if (ch == "$") {
44 stream.eatWhile(regs.validIdentifier);
45 return ret("variable-2", "variable");
46 }
47 else if (ch == ".") {
48 return ret("operator", "property");
49 }
50 else if (regs.stringChar.test(ch)) {
51 state.tokenize = inAttribute(ch);
52 return ret("string", "string");
53 }
54 else if (regs.operatorChars.test(ch)) {
55 stream.eatWhile(regs.operatorChars);
56 return ret("operator", "operator");
57 }
58 else if (ch == "[" || ch == "]") {
59 return ret("bracket", "bracket");
60 }
61 else if (/\d/.test(ch)) {
62 stream.eatWhile(/\d/);
63 return ret("number", "number");
64 }
65 else {
66 if (state.last == "variable") {
67 if (ch == "@") {
68 stream.eatWhile(regs.validIdentifier);
69 return ret("property", "property");
70 }
71 else if (ch == "|") {
72 stream.eatWhile(regs.validIdentifier);
73 return ret("qualifier", "modifier");
74 }
75 }
76 else if (state.last == "whitespace") {
77 stream.eatWhile(regs.validIdentifier);
78 return ret("attribute", "modifier");
79 }
80 else if (state.last == "property") {
81 stream.eatWhile(regs.validIdentifier);
82 return ret("property", null);
83 }
84 else if (/\s/.test(ch)) {
85 last = "whitespace";
86 return null;
87 }
88
89 var str = "";
90 if (ch != "/") {
91 str += ch;
92 }
93 var c = "";
94 while ((c = stream.eat(regs.validIdentifier))) {
95 str += c;
96 }
97 var i, j;
98 for (i=0, j=keyFuncs.length; i<j; i++) {
99 if (keyFuncs[i] == str) {
100 return ret("keyword", "keyword");
101 }
102 }
103 if (/\s/.test(ch)) {
104 return null;
105 }
106 return ret("tag", "tag");
107 }
108 }
109
110 function inAttribute(quote) {
111 return function(stream, state) {
112 while (!stream.eol()) {
113 if (stream.next() == quote) {
114 state.tokenize = inSmarty;
115 break;
116 }
117 }
118 return "string";
119 };
120 }
121
122 function inBlock(style, terminator) {
123 return function(stream, state) {
124 while (!stream.eol()) {
125 if (stream.match(terminator)) {
126 state.tokenize = tokenizer;
127 break;
128 }
129 stream.next();
130 }
131 return style;
132 };
133 }
134
135 return {
136 startState: function() {
137 return { tokenize: tokenizer, mode: "smarty", last: null };
138 },
139 token: function(stream, state) {
140 var style = state.tokenize(stream, state);
141 state.last = last;
142 return style;
143 },
144 electricChars: ""
145 }
146});
147
148CodeMirror.defineMIME("text/x-smarty", "smarty"); \ No newline at end of file