diff options
author | Jose Antonio Marquez | 2012-01-27 12:05:17 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-01-27 12:05:17 -0800 |
commit | 3a754133dbc138390503341fd2e9beba3e43aa4b (patch) | |
tree | cdeae7d7dd9a30d7b4fab5afb7efad68d4ec7508 /imports/codemirror/mode/lua | |
parent | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (diff) | |
download | ninja-3a754133dbc138390503341fd2e9beba3e43aa4b.tar.gz |
Merged old FileIO
Diffstat (limited to 'imports/codemirror/mode/lua')
-rwxr-xr-x | imports/codemirror/mode/lua/index.html | 72 | ||||
-rwxr-xr-x | imports/codemirror/mode/lua/lua.js | 140 |
2 files changed, 212 insertions, 0 deletions
diff --git a/imports/codemirror/mode/lua/index.html b/imports/codemirror/mode/lua/index.html new file mode 100755 index 00000000..600ddb0e --- /dev/null +++ b/imports/codemirror/mode/lua/index.html | |||
@@ -0,0 +1,72 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: 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="../../doc/docs.css"> | ||
11 | </head> | ||
12 | <body> | ||
13 | <h1>CodeMirror: Lua mode</h1> | ||
14 | <form><textarea id="code" name="code"> | ||
15 | --[[ | ||
16 | example useless code to show lua syntax highlighting | ||
17 | this is multiline comment | ||
18 | ]] | ||
19 | |||
20 | function 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 | |||
36 | end | ||
37 | |||
38 | function 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 | |||
53 | end | ||
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/imports/codemirror/mode/lua/lua.js b/imports/codemirror/mode/lua/lua.js new file mode 100755 index 00000000..60e84a92 --- /dev/null +++ b/imports/codemirror/mode/lua/lua.js | |||
@@ -0,0 +1,140 @@ | |||
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 | |||
5 | CodeMirror.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","do", "\\(", "{"]); | ||
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 ((style != "comment") && (style != "string")){ | ||
127 | if (indentTokens.test(word)) ++state.indentDepth; | ||
128 | else if (dedentTokens.test(word)) --state.indentDepth; | ||
129 | } | ||
130 | return style; | ||
131 | }, | ||
132 | |||
133 | indent: function(state, textAfter) { | ||
134 | var closing = dedentPartial.test(textAfter); | ||
135 | return state.basecol + indentUnit * (state.indentDepth - (closing ? 1 : 0)); | ||
136 | } | ||
137 | }; | ||
138 | }); | ||
139 | |||
140 | CodeMirror.defineMIME("text/x-lua", "lua"); | ||