diff options
author | Valerio Virgillito | 2012-02-14 11:07:21 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-14 11:07:21 -0800 |
commit | f060190a3bffd9a16718f2ce0499699103d46372 (patch) | |
tree | a308fe7eacec2156c8212dff0892a3de925d5f9a /imports/codemirror/mode/pascal | |
parent | f766cc203f30ea43ae8b83cf4b65d45cc4435ee9 (diff) | |
parent | 33bc9d62b8e6694500bf14d5b18187bd99a520a3 (diff) | |
download | ninja-f060190a3bffd9a16718f2ce0499699103d46372.tar.gz |
Merge branch 'FileIO' of https://github.com/joseeight/ninja-internal into integration
Diffstat (limited to 'imports/codemirror/mode/pascal')
-rwxr-xr-x | imports/codemirror/mode/pascal/LICENSE | 7 | ||||
-rwxr-xr-x | imports/codemirror/mode/pascal/index.html | 48 | ||||
-rwxr-xr-x | imports/codemirror/mode/pascal/pascal.js | 138 |
3 files changed, 193 insertions, 0 deletions
diff --git a/imports/codemirror/mode/pascal/LICENSE b/imports/codemirror/mode/pascal/LICENSE new file mode 100755 index 00000000..8e3747e7 --- /dev/null +++ b/imports/codemirror/mode/pascal/LICENSE | |||
@@ -0,0 +1,7 @@ | |||
1 | Copyright (c) 2011 souceLair <support@sourcelair.com> | ||
2 | |||
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
4 | |||
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
6 | |||
7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
diff --git a/imports/codemirror/mode/pascal/index.html b/imports/codemirror/mode/pascal/index.html new file mode 100755 index 00000000..6af6b460 --- /dev/null +++ b/imports/codemirror/mode/pascal/index.html | |||
@@ -0,0 +1,48 @@ | |||
1 | <!doctype html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <title>CodeMirror: Pascal mode</title> | ||
5 | <link rel="stylesheet" href="../../lib/codemirror.css"> | ||
6 | <script src="../../lib/codemirror.js"></script> | ||
7 | <script src="pascal.js"></script> | ||
8 | <link rel="stylesheet" href="../../doc/docs.css"> | ||
9 | <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style> | ||
10 | </head> | ||
11 | <body> | ||
12 | <h1>CodeMirror: Pascal mode</h1> | ||
13 | |||
14 | <div><textarea id="code" name="code"> | ||
15 | (* Example Pascal code *) | ||
16 | |||
17 | while a <> b do writeln('Waiting'); | ||
18 | |||
19 | if a > b then | ||
20 | writeln('Condition met') | ||
21 | else | ||
22 | writeln('Condition not met'); | ||
23 | |||
24 | for i := 1 to 10 do | ||
25 | writeln('Iteration: ', i:1); | ||
26 | |||
27 | repeat | ||
28 | a := a + 1 | ||
29 | until a = 10; | ||
30 | |||
31 | case i of | ||
32 | 0: write('zero'); | ||
33 | 1: write('one'); | ||
34 | 2: write('two') | ||
35 | end; | ||
36 | </textarea></div> | ||
37 | |||
38 | <script> | ||
39 | var editor = CodeMirror.fromTextArea(document.getElementById("code"), { | ||
40 | lineNumbers: true, | ||
41 | matchBrackets: true, | ||
42 | mode: "text/x-pascal" | ||
43 | }); | ||
44 | </script> | ||
45 | |||
46 | <p><strong>MIME types defined:</strong> <code>text/x-pascal</code>.</p> | ||
47 | </body> | ||
48 | </html> | ||
diff --git a/imports/codemirror/mode/pascal/pascal.js b/imports/codemirror/mode/pascal/pascal.js new file mode 100755 index 00000000..86c6f71c --- /dev/null +++ b/imports/codemirror/mode/pascal/pascal.js | |||
@@ -0,0 +1,138 @@ | |||
1 | CodeMirror.defineMode("pascal", function(config) { | ||
2 | function words(str) { | ||
3 | var obj = {}, words = str.split(" "); | ||
4 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; | ||
5 | return obj; | ||
6 | } | ||
7 | var keywords = words("and array begin case const div do downto else end file for forward integer " + | ||
8 | "boolean char function goto if in label mod nil not of or packed procedure " + | ||
9 | "program record repeat set string then to type until var while with"); | ||
10 | var blockKeywords = words("case do else for if switch while struct then of"); | ||
11 | var atoms = {"null": true}; | ||
12 | |||
13 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; | ||
14 | var curPunc; | ||
15 | |||
16 | function tokenBase(stream, state) { | ||
17 | var ch = stream.next(); | ||
18 | if (ch == "#" && state.startOfLine) { | ||
19 | stream.skipToEnd(); | ||
20 | return "meta"; | ||
21 | } | ||
22 | if (ch == '"' || ch == "'") { | ||
23 | state.tokenize = tokenString(ch); | ||
24 | return state.tokenize(stream, state); | ||
25 | } | ||
26 | if (ch == "(" && stream.eat("*")) { | ||
27 | state.tokenize = tokenComment; | ||
28 | return tokenComment(stream, state); | ||
29 | } | ||
30 | if (/[\[\]{}\(\),;\:\.]/.test(ch)) { | ||
31 | curPunc = ch; | ||
32 | return null | ||
33 | } | ||
34 | if (/\d/.test(ch)) { | ||
35 | stream.eatWhile(/[\w\.]/); | ||
36 | return "number"; | ||
37 | } | ||
38 | if (ch == "/") { | ||
39 | if (stream.eat("/")) { | ||
40 | stream.skipToEnd(); | ||
41 | return "comment"; | ||
42 | } | ||
43 | } | ||
44 | if (isOperatorChar.test(ch)) { | ||
45 | stream.eatWhile(isOperatorChar); | ||
46 | return "operator"; | ||
47 | } | ||
48 | stream.eatWhile(/[\w\$_]/); | ||
49 | var cur = stream.current(); | ||
50 | if (keywords.propertyIsEnumerable(cur)) { | ||
51 | if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement"; | ||
52 | return "keyword"; | ||
53 | } | ||
54 | if (atoms.propertyIsEnumerable(cur)) return "atom"; | ||
55 | return "word"; | ||
56 | } | ||
57 | |||
58 | function tokenString(quote) { | ||
59 | return function(stream, state) { | ||
60 | var escaped = false, next, end = false; | ||
61 | while ((next = stream.next()) != null) { | ||
62 | if (next == quote && !escaped) {end = true; break;} | ||
63 | escaped = !escaped && next == "\\"; | ||
64 | } | ||
65 | if (end || !escaped) state.tokenize = null; | ||
66 | return "string"; | ||
67 | }; | ||
68 | } | ||
69 | |||
70 | function tokenComment(stream, state) { | ||
71 | var maybeEnd = false, ch; | ||
72 | while (ch = stream.next()) { | ||
73 | if (ch == ")" && maybeEnd) { | ||
74 | state.tokenize = null; | ||
75 | break; | ||
76 | } | ||
77 | maybeEnd = (ch == "*"); | ||
78 | } | ||
79 | return "comment"; | ||
80 | } | ||
81 | |||
82 | function Context(indented, column, type, align, prev) { | ||
83 | this.indented = indented; | ||
84 | this.column = column; | ||
85 | this.type = type; | ||
86 | this.align = align; | ||
87 | this.prev = prev; | ||
88 | } | ||
89 | function pushContext(state, col, type) { | ||
90 | return state.context = new Context(state.indented, col, type, null, state.context); | ||
91 | } | ||
92 | function popContext(state) { | ||
93 | var t = state.context.type; | ||
94 | if (t == ")" || t == "]" ) | ||
95 | state.indented = state.context.indented; | ||
96 | return state.context = state.context.prev; | ||
97 | } | ||
98 | |||
99 | // Interface | ||
100 | |||
101 | return { | ||
102 | startState: function(basecolumn) { | ||
103 | return { | ||
104 | tokenize: null, | ||
105 | context: new Context((basecolumn || 0) - config.indentUnit, 0, "top", false), | ||
106 | indented: 0, | ||
107 | startOfLine: true | ||
108 | }; | ||
109 | }, | ||
110 | |||
111 | token: function(stream, state) { | ||
112 | var ctx = state.context; | ||
113 | if (stream.sol()) { | ||
114 | if (ctx.align == null) ctx.align = false; | ||
115 | state.indented = stream.indentation(); | ||
116 | state.startOfLine = true; | ||
117 | } | ||
118 | if (stream.eatSpace()) return null; | ||
119 | curPunc = null; | ||
120 | var style = (state.tokenize || tokenBase)(stream, state); | ||
121 | if (style == "comment" || style == "meta") return style; | ||
122 | if (ctx.align == null) ctx.align = true; | ||
123 | |||
124 | if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state); | ||
125 | else if (curPunc == "[") pushContext(state, stream.column(), "]"); | ||
126 | else if (curPunc == "(") pushContext(state, stream.column(), ")"); | ||
127 | else if (curPunc == ctx.type) popContext(state); | ||
128 | else if ( ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement")) | ||
129 | pushContext(state, stream.column(), "statement"); | ||
130 | state.startOfLine = false; | ||
131 | return style; | ||
132 | }, | ||
133 | |||
134 | electricChars: "{}" | ||
135 | }; | ||
136 | }); | ||
137 | |||
138 | CodeMirror.defineMIME("text/x-pascal", "pascal"); | ||