aboutsummaryrefslogtreecommitdiff
path: root/js/codemirror/mode/lua
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-15 20:37:48 -0800
committerJose Antonio Marquez2012-02-15 20:37:48 -0800
commit89b5e793ea88ef235b54b6e1d1c379698d3e612b (patch)
tree4d29118f35df77ca6b423119a4ff61694a442cbf /js/codemirror/mode/lua
parent9d2c2a80483415d7560b00cda5519153db23e241 (diff)
parentd366c0bd1af6471511217ed574083e15059519b5 (diff)
downloadninja-89b5e793ea88ef235b54b6e1d1c379698d3e612b.tar.gz
Merge branch 'refs/heads/NinjaInternal' into Color
Diffstat (limited to 'js/codemirror/mode/lua')
-rw-r--r--js/codemirror/mode/lua/index.html72
-rw-r--r--js/codemirror/mode/lua/lua.js138
2 files changed, 0 insertions, 210 deletions
diff --git a/js/codemirror/mode/lua/index.html b/js/codemirror/mode/lua/index.html
deleted file mode 100644
index 532973a8..00000000
--- a/js/codemirror/mode/lua/index.html
+++ /dev/null
@@ -1,72 +0,0 @@
1<!doctype html>
2<html>
3 <head>
4 <title>CodeMirror 2: Lua mode</title>
5 <link rel="stylesheet" href="../../lib/codemirror.css">
6 <script src="../../lib/codemirror.js"></script>
7 <script src="lua.js"></script>
8 <link rel="stylesheet" href="../../theme/neat.css">
9 <style>.CodeMirror {border: 1px solid black;}</style>
10 <link rel="stylesheet" href="../../css/docs.css">
11 </head>
12 <body>
13 <h1>CodeMirror 2: Lua mode</h1>
14 <form><textarea id="code" name="code">
15--[[
16example useless code to show lua syntax highlighting
17this is multiline comment
18]]
19
20function blahblahblah(x)
21
22 local table = {
23 "asd" = 123,
24 "x" = 0.34,
25 }
26 if x ~= 3 then
27 print( x )
28 elseif x == "string"
29 my_custom_function( 0x34 )
30 else
31 unknown_function( "some string" )
32 end
33
34 --single line comment
35
36end
37
38function blablabla3()
39
40 for k,v in ipairs( table ) do
41 --abcde..
42 y=[=[
43 x=[[
44 x is a multi line string
45 ]]
46 but its definition is iside a highest level string!
47 ]=]
48 print(" \"\" ")
49
50 s = math.sin( x )
51 end
52
53end
54</textarea></form>
55 <script>
56 var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
57 tabMode: "indent",
58 matchBrackets: true,
59 theme: "neat"
60 });
61 </script>
62
63 <p>Loosely based on Franciszek
64 Wawrzak's <a href="http://codemirror.net/1/contrib/lua">CodeMirror
65 1 mode</a>. One configuration parameter is
66 supported, <code>specials</code>, to which you can provide an
67 array of strings to have those identifiers highlighted with
68 the <code>lua-special</code> style.</p>
69 <p><strong>MIME types defined:</strong> <code>text/x-lua</code>.</p>
70
71 </body>
72</html>
diff --git a/js/codemirror/mode/lua/lua.js b/js/codemirror/mode/lua/lua.js
deleted file mode 100644
index 491ad59a..00000000
--- a/js/codemirror/mode/lua/lua.js
+++ /dev/null
@@ -1,138 +0,0 @@
1// LUA mode. Ported to CodeMirror 2 from Franciszek Wawrzak's
2// CodeMirror 1 mode.
3// highlights keywords, strings, comments (no leveling supported! ("[==[")), tokens, basic indenting
4
5CodeMirror.defineMode("lua", function(config, parserConfig) {
6 var indentUnit = config.indentUnit;
7
8 function prefixRE(words) {
9 return new RegExp("^(?:" + words.join("|") + ")", "i");
10 }
11 function wordRE(words) {
12 return new RegExp("^(?:" + words.join("|") + ")$", "i");
13 }
14 var specials = wordRE(parserConfig.specials || []);
15
16 // long list of standard functions from lua manual
17 var builtins = wordRE([
18 "_G","_VERSION","assert","collectgarbage","dofile","error","getfenv","getmetatable","ipairs","load",
19 "loadfile","loadstring","module","next","pairs","pcall","print","rawequal","rawget","rawset","require",
20 "select","setfenv","setmetatable","tonumber","tostring","type","unpack","xpcall",
21
22 "coroutine.create","coroutine.resume","coroutine.running","coroutine.status","coroutine.wrap","coroutine.yield",
23
24 "debug.debug","debug.getfenv","debug.gethook","debug.getinfo","debug.getlocal","debug.getmetatable",
25 "debug.getregistry","debug.getupvalue","debug.setfenv","debug.sethook","debug.setlocal","debug.setmetatable",
26 "debug.setupvalue","debug.traceback",
27
28 "close","flush","lines","read","seek","setvbuf","write",
29
30 "io.close","io.flush","io.input","io.lines","io.open","io.output","io.popen","io.read","io.stderr","io.stdin",
31 "io.stdout","io.tmpfile","io.type","io.write",
32
33 "math.abs","math.acos","math.asin","math.atan","math.atan2","math.ceil","math.cos","math.cosh","math.deg",
34 "math.exp","math.floor","math.fmod","math.frexp","math.huge","math.ldexp","math.log","math.log10","math.max",
35 "math.min","math.modf","math.pi","math.pow","math.rad","math.random","math.randomseed","math.sin","math.sinh",
36 "math.sqrt","math.tan","math.tanh",
37
38 "os.clock","os.date","os.difftime","os.execute","os.exit","os.getenv","os.remove","os.rename","os.setlocale",
39 "os.time","os.tmpname",
40
41 "package.cpath","package.loaded","package.loaders","package.loadlib","package.path","package.preload",
42 "package.seeall",
43
44 "string.byte","string.char","string.dump","string.find","string.format","string.gmatch","string.gsub",
45 "string.len","string.lower","string.match","string.rep","string.reverse","string.sub","string.upper",
46
47 "table.concat","table.insert","table.maxn","table.remove","table.sort"
48 ]);
49 var keywords = wordRE(["and","break","elseif","false","nil","not","or","return",
50 "true","function", "end", "if", "then", "else", "do",
51 "while", "repeat", "until", "for", "in", "local" ]);
52
53 var indentTokens = wordRE(["function", "if","repeat","for","while", "\\(", "{"]);
54 var dedentTokens = wordRE(["end", "until", "\\)", "}"]);
55 var dedentPartial = prefixRE(["end", "until", "\\)", "}", "else", "elseif"]);
56
57 function readBracket(stream) {
58 var level = 0;
59 while (stream.eat("=")) ++level;
60 stream.eat("[");
61 return level;
62 }
63
64 function normal(stream, state) {
65 var ch = stream.next();
66 if (ch == "-" && stream.eat("-")) {
67 if (stream.eat("["))
68 return (state.cur = bracketed(readBracket(stream), "comment"))(stream, state);
69 stream.skipToEnd();
70 return "comment";
71 }
72 if (ch == "\"" || ch == "'")
73 return (state.cur = string(ch))(stream, state);
74 if (ch == "[" && /[\[=]/.test(stream.peek()))
75 return (state.cur = bracketed(readBracket(stream), "string"))(stream, state);
76 if (/\d/.test(ch)) {
77 stream.eatWhile(/[\w.%]/);
78 return "number";
79 }
80 if (/[\w_]/.test(ch)) {
81 stream.eatWhile(/[\w\\\-_.]/);
82 return "variable";
83 }
84 return null;
85 }
86
87 function bracketed(level, style) {
88 return function(stream, state) {
89 var curlev = null, ch;
90 while ((ch = stream.next()) != null) {
91 if (curlev == null) {if (ch == "]") curlev = 0;}
92 else if (ch == "=") ++curlev;
93 else if (ch == "]" && curlev == level) { state.cur = normal; break; }
94 else curlev = null;
95 }
96 return style;
97 };
98 }
99
100 function string(quote) {
101 return function(stream, state) {
102 var escaped = false, ch;
103 while ((ch = stream.next()) != null) {
104 if (ch == quote && !escaped) break;
105 escaped = !escaped && ch == "\\";
106 }
107 if (!escaped) state.cur = normal;
108 return "string";
109 };
110 }
111
112 return {
113 startState: function(basecol) {
114 return {basecol: basecol || 0, indentDepth: 0, cur: normal};
115 },
116
117 token: function(stream, state) {
118 if (stream.eatSpace()) return null;
119 var style = state.cur(stream, state);
120 var word = stream.current();
121 if (style == "variable") {
122 if (keywords.test(word)) style = "keyword";
123 else if (builtins.test(word)) style = "builtin";
124 else if (specials.test(word)) style = "variable-2";
125 }
126 if (indentTokens.test(word)) ++state.indentDepth;
127 else if (dedentTokens.test(word)) --state.indentDepth;
128 return style;
129 },
130
131 indent: function(state, textAfter) {
132 var closing = dedentPartial.test(textAfter);
133 return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0));
134 }
135 };
136});
137
138CodeMirror.defineMIME("text/x-lua", "lua");