aboutsummaryrefslogtreecommitdiff
path: root/imports/codemirror/mode/php
diff options
context:
space:
mode:
authorAnanya Sen2012-02-27 14:41:21 -0800
committerAnanya Sen2012-02-27 14:41:21 -0800
commit51ed781953bc44bba3c70938aa57b856394cbc88 (patch)
tree483bcacdcdcc6802d2d048b576406b111656fa05 /imports/codemirror/mode/php
parent15d00c49b522aa471d1ccfbbd33f5c0e721eb89e (diff)
downloadninja-51ed781953bc44bba3c70938aa57b856394cbc88.tar.gz
updating to codemirror 2.22
Signed-off-by: Ananya Sen <Ananya.Sen@motorola.com>
Diffstat (limited to 'imports/codemirror/mode/php')
-rw-r--r--[-rwxr-xr-x]imports/codemirror/mode/php/index.html0
-rw-r--r--[-rwxr-xr-x]imports/codemirror/mode/php/php.js78
2 files changed, 54 insertions, 24 deletions
diff --git a/imports/codemirror/mode/php/index.html b/imports/codemirror/mode/php/index.html
index 7949044e..7949044e 100755..100644
--- a/imports/codemirror/mode/php/index.html
+++ b/imports/codemirror/mode/php/index.html
diff --git a/imports/codemirror/mode/php/php.js b/imports/codemirror/mode/php/php.js
index f88b3f84..5406a5ce 100755..100644
--- a/imports/codemirror/mode/php/php.js
+++ b/imports/codemirror/mode/php/php.js
@@ -13,11 +13,12 @@
13 } 13 }
14 var phpConfig = { 14 var phpConfig = {
15 name: "clike", 15 name: "clike",
16 keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " + 16 keywords: keywords("abstract and array as break case catch class clone const continue declare default " +
17 "default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends " + 17 "do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
18 "final for foreach function global goto if implements interface instanceof namespace " + 18 "for foreach function global goto if implements interface instanceof namespace " +
19 "new or private protected public static switch throw try use var while xor return" + 19 "new or private protected public static switch throw trait try use var while xor " +
20 "die echo empty exit eval include include_once isset list require require_once print unset"), 20 "die echo empty exit eval include include_once isset list require require_once return " +
21 "print unset __halt_compiler self static parent"),
21 blockKeywords: keywords("catch do else elseif for foreach if switch try while"), 22 blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
22 atoms: keywords("true false null TRUE FALSE NULL"), 23 atoms: keywords("true false null TRUE FALSE NULL"),
23 multiLineStrings: true, 24 multiLineStrings: true,
@@ -35,8 +36,15 @@
35 return false; 36 return false;
36 }, 37 },
37 "#": function(stream, state) { 38 "#": function(stream, state) {
38 stream.skipToEnd(); 39 while (!stream.eol() && !stream.match("?>", false)) stream.next();
39 return "comment"; 40 return "comment";
41 },
42 "/": function(stream, state) {
43 if (stream.eat("/")) {
44 while (!stream.eol() && !stream.match("?>", false)) stream.next();
45 return "comment";
46 }
47 return false;
40 } 48 }
41 } 49 }
42 }; 50 };
@@ -48,38 +56,57 @@
48 var phpMode = CodeMirror.getMode(config, phpConfig); 56 var phpMode = CodeMirror.getMode(config, phpConfig);
49 57
50 function dispatch(stream, state) { // TODO open PHP inside text/css 58 function dispatch(stream, state) { // TODO open PHP inside text/css
59 var isPHP = state.mode == "php";
60 if (stream.sol() && state.pending != '"') state.pending = null;
51 if (state.curMode == htmlMode) { 61 if (state.curMode == htmlMode) {
52 var style = htmlMode.token(stream, state.curState); 62 if (stream.match(/^<\?\w*/)) {
53 if (style == "meta" && /^<\?/.test(stream.current())) {
54 state.curMode = phpMode; 63 state.curMode = phpMode;
55 state.curState = state.php; 64 state.curState = state.php;
56 state.curClose = /^\?>/; 65 state.curClose = "?>";
57 state.mode = 'php'; 66 state.mode = "php";
67 return "meta";
58 } 68 }
59 else if (style == "tag" && stream.current() == ">" && state.curState.context) { 69 if (state.pending == '"') {
70 while (!stream.eol() && stream.next() != '"') {}
71 var style = "string";
72 } else if (state.pending && stream.pos < state.pending.end) {
73 stream.pos = state.pending.end;
74 var style = state.pending.style;
75 } else {
76 var style = htmlMode.token(stream, state.curState);
77 }
78 state.pending = null;
79 var cur = stream.current(), openPHP = cur.search(/<\?/);
80 if (openPHP != -1) {
81 if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"';
82 else state.pending = {end: stream.pos, style: style};
83 stream.backUp(cur.length - openPHP);
84 } else if (style == "tag" && stream.current() == ">" && state.curState.context) {
60 if (/^script$/i.test(state.curState.context.tagName)) { 85 if (/^script$/i.test(state.curState.context.tagName)) {
61 state.curMode = jsMode; 86 state.curMode = jsMode;
62 state.curState = jsMode.startState(htmlMode.indent(state.curState, "")); 87 state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
63 state.curClose = /^<\/\s*script\s*>/i; 88 state.curClose = /^<\/\s*script\s*>/i;
64 state.mode = 'javascript'; 89 state.mode = "javascript";
65 } 90 }
66 else if (/^style$/i.test(state.curState.context.tagName)) { 91 else if (/^style$/i.test(state.curState.context.tagName)) {
67 state.curMode = cssMode; 92 state.curMode = cssMode;
68 state.curState = cssMode.startState(htmlMode.indent(state.curState, "")); 93 state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
69 state.curClose = /^<\/\s*style\s*>/i; 94 state.curClose = /^<\/\s*style\s*>/i;
70 state.mode = 'css'; 95 state.mode = "css";
71 } 96 }
72 } 97 }
73 return style; 98 return style;
74 } 99 } else if ((!isPHP || state.php.tokenize == null) &&
75 else if (stream.match(state.curClose, false)) { 100 stream.match(state.curClose, isPHP)) {
76 state.curMode = htmlMode; 101 state.curMode = htmlMode;
77 state.curState = state.html; 102 state.curState = state.html;
78 state.curClose = null; 103 state.curClose = null;
79 state.mode = 'html'; 104 state.mode = "html";
80 return dispatch(stream, state); 105 if (isPHP) return "meta";
106 else return dispatch(stream, state);
107 } else {
108 return state.curMode.token(stream, state.curState);
81 } 109 }
82 else return state.curMode.token(stream, state.curState);
83 } 110 }
84 111
85 return { 112 return {
@@ -87,10 +114,11 @@
87 var html = htmlMode.startState(); 114 var html = htmlMode.startState();
88 return {html: html, 115 return {html: html,
89 php: phpMode.startState(), 116 php: phpMode.startState(),
90 curMode: parserConfig.startOpen ? phpMode : htmlMode, 117 curMode: parserConfig.startOpen ? phpMode : htmlMode,
91 curState: parserConfig.startOpen ? phpMode.startState() : html, 118 curState: parserConfig.startOpen ? phpMode.startState() : html,
92 curClose: parserConfig.startOpen ? /^\?>/ : null, 119 curClose: parserConfig.startOpen ? /^\?>/ : null,
93 mode: parserConfig.startOpen ? 'php' : 'html'} 120 mode: parserConfig.startOpen ? "php" : "html",
121 pending: null}
94 }, 122 },
95 123
96 copyState: function(state) { 124 copyState: function(state) {
@@ -99,7 +127,9 @@
99 if (state.curState == html) cur = htmlNew; 127 if (state.curState == html) cur = htmlNew;
100 else if (state.curState == php) cur = phpNew; 128 else if (state.curState == php) cur = phpNew;
101 else cur = CodeMirror.copyState(state.curMode, state.curState); 129 else cur = CodeMirror.copyState(state.curMode, state.curState);
102 return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur, curClose: state.curClose}; 130 return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
131 curClose: state.curClose, mode: state.mode,
132 pending: state.pending};
103 }, 133 },
104 134
105 token: dispatch, 135 token: dispatch,