ledger_web 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/LICENSE +7 -0
- data/README.md +140 -0
- data/Rakefile +11 -0
- data/bin/ledger_web +14 -0
- data/ledger_web.gemspec +26 -0
- data/lib/ledger_web/app.rb +69 -0
- data/lib/ledger_web/config.rb +87 -0
- data/lib/ledger_web/db/migrate/20111226180900_initial_schema.rb +38 -0
- data/lib/ledger_web/db/migrate/20111231132900_add_views.rb +37 -0
- data/lib/ledger_web/db.rb +54 -0
- data/lib/ledger_web/helpers.rb +62 -0
- data/lib/ledger_web/public/bootstrap-dropdown.js +55 -0
- data/lib/ledger_web/public/bootstrap.min.css +356 -0
- data/lib/ledger_web/public/codemirror/keymap/emacs.js +29 -0
- data/lib/ledger_web/public/codemirror/keymap/vim.js +76 -0
- data/lib/ledger_web/public/codemirror/lib/codemirror.css +104 -0
- data/lib/ledger_web/public/codemirror/lib/codemirror.js +2761 -0
- data/lib/ledger_web/public/codemirror/lib/util/dialog.css +23 -0
- data/lib/ledger_web/public/codemirror/lib/util/dialog.js +63 -0
- data/lib/ledger_web/public/codemirror/lib/util/foldcode.js +66 -0
- data/lib/ledger_web/public/codemirror/lib/util/formatting.js +291 -0
- data/lib/ledger_web/public/codemirror/lib/util/javascript-hint.js +83 -0
- data/lib/ledger_web/public/codemirror/lib/util/overlay.js +51 -0
- data/lib/ledger_web/public/codemirror/lib/util/runmode.js +27 -0
- data/lib/ledger_web/public/codemirror/lib/util/search.js +114 -0
- data/lib/ledger_web/public/codemirror/lib/util/searchcursor.js +117 -0
- data/lib/ledger_web/public/codemirror/lib/util/simple-hint.css +16 -0
- data/lib/ledger_web/public/codemirror/lib/util/simple-hint.js +66 -0
- data/lib/ledger_web/public/codemirror/mode/clike/clike.js +249 -0
- data/lib/ledger_web/public/codemirror/mode/clike/index.html +101 -0
- data/lib/ledger_web/public/codemirror/mode/clojure/clojure.js +207 -0
- data/lib/ledger_web/public/codemirror/mode/clojure/index.html +66 -0
- data/lib/ledger_web/public/codemirror/mode/coffeescript/LICENSE +22 -0
- data/lib/ledger_web/public/codemirror/mode/coffeescript/coffeescript.js +325 -0
- data/lib/ledger_web/public/codemirror/mode/coffeescript/index.html +721 -0
- data/lib/ledger_web/public/codemirror/mode/css/css.js +124 -0
- data/lib/ledger_web/public/codemirror/mode/css/index.html +55 -0
- data/lib/ledger_web/public/codemirror/mode/diff/diff.css +3 -0
- data/lib/ledger_web/public/codemirror/mode/diff/diff.js +13 -0
- data/lib/ledger_web/public/codemirror/mode/diff/index.html +99 -0
- data/lib/ledger_web/public/codemirror/mode/gfm/gfm.js +108 -0
- data/lib/ledger_web/public/codemirror/mode/gfm/index.html +47 -0
- data/lib/ledger_web/public/codemirror/mode/groovy/groovy.js +210 -0
- data/lib/ledger_web/public/codemirror/mode/groovy/index.html +71 -0
- data/lib/ledger_web/public/codemirror/mode/haskell/haskell.js +242 -0
- data/lib/ledger_web/public/codemirror/mode/haskell/index.html +60 -0
- data/lib/ledger_web/public/codemirror/mode/htmlembedded/htmlembedded.js +68 -0
- data/lib/ledger_web/public/codemirror/mode/htmlembedded/index.html +49 -0
- data/lib/ledger_web/public/codemirror/mode/htmlmixed/htmlmixed.js +83 -0
- data/lib/ledger_web/public/codemirror/mode/htmlmixed/index.html +51 -0
- data/lib/ledger_web/public/codemirror/mode/javascript/index.html +77 -0
- data/lib/ledger_web/public/codemirror/mode/javascript/javascript.js +360 -0
- data/lib/ledger_web/public/codemirror/mode/jinja2/index.html +37 -0
- data/lib/ledger_web/public/codemirror/mode/jinja2/jinja2.js +42 -0
- data/lib/ledger_web/public/codemirror/mode/lua/index.html +72 -0
- data/lib/ledger_web/public/codemirror/mode/lua/lua.js +140 -0
- data/lib/ledger_web/public/codemirror/mode/markdown/index.html +339 -0
- data/lib/ledger_web/public/codemirror/mode/markdown/markdown.js +242 -0
- data/lib/ledger_web/public/codemirror/mode/ntriples/index.html +32 -0
- data/lib/ledger_web/public/codemirror/mode/ntriples/ntriples.js +172 -0
- data/lib/ledger_web/public/codemirror/mode/pascal/LICENSE +7 -0
- data/lib/ledger_web/public/codemirror/mode/pascal/index.html +48 -0
- data/lib/ledger_web/public/codemirror/mode/pascal/pascal.js +138 -0
- data/lib/ledger_web/public/codemirror/mode/perl/LICENSE +19 -0
- data/lib/ledger_web/public/codemirror/mode/perl/index.html +62 -0
- data/lib/ledger_web/public/codemirror/mode/perl/perl.js +816 -0
- data/lib/ledger_web/public/codemirror/mode/php/index.html +48 -0
- data/lib/ledger_web/public/codemirror/mode/php/php.js +120 -0
- data/lib/ledger_web/public/codemirror/mode/plsql/index.html +62 -0
- data/lib/ledger_web/public/codemirror/mode/plsql/plsql.js +217 -0
- data/lib/ledger_web/public/codemirror/mode/python/LICENSE.txt +21 -0
- data/lib/ledger_web/public/codemirror/mode/python/index.html +122 -0
- data/lib/ledger_web/public/codemirror/mode/python/python.js +333 -0
- data/lib/ledger_web/public/codemirror/mode/r/LICENSE +24 -0
- data/lib/ledger_web/public/codemirror/mode/r/index.html +73 -0
- data/lib/ledger_web/public/codemirror/mode/r/r.js +141 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/changes/changes.js +19 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/changes/index.html +53 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/spec/index.html +99 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/spec/spec.css +5 -0
- data/lib/ledger_web/public/codemirror/mode/rpm/spec/spec.js +66 -0
- data/lib/ledger_web/public/codemirror/mode/rst/index.html +525 -0
- data/lib/ledger_web/public/codemirror/mode/rst/rst.js +326 -0
- data/lib/ledger_web/public/codemirror/mode/ruby/LICENSE +24 -0
- data/lib/ledger_web/public/codemirror/mode/ruby/index.html +171 -0
- data/lib/ledger_web/public/codemirror/mode/ruby/ruby.js +195 -0
- data/lib/ledger_web/public/codemirror/mode/rust/index.html +48 -0
- data/lib/ledger_web/public/codemirror/mode/rust/rust.js +411 -0
- data/lib/ledger_web/public/codemirror/mode/scheme/index.html +64 -0
- data/lib/ledger_web/public/codemirror/mode/scheme/scheme.js +202 -0
- data/lib/ledger_web/public/codemirror/mode/smalltalk/index.html +55 -0
- data/lib/ledger_web/public/codemirror/mode/smalltalk/smalltalk.js +139 -0
- data/lib/ledger_web/public/codemirror/mode/sparql/index.html +40 -0
- data/lib/ledger_web/public/codemirror/mode/sparql/sparql.js +143 -0
- data/lib/ledger_web/public/codemirror/mode/stex/index.html +95 -0
- data/lib/ledger_web/public/codemirror/mode/stex/stex.js +167 -0
- data/lib/ledger_web/public/codemirror/mode/tiddlywiki/index.html +183 -0
- data/lib/ledger_web/public/codemirror/mode/tiddlywiki/tiddlywiki.css +21 -0
- data/lib/ledger_web/public/codemirror/mode/tiddlywiki/tiddlywiki.js +374 -0
- data/lib/ledger_web/public/codemirror/mode/velocity/index.html +103 -0
- data/lib/ledger_web/public/codemirror/mode/velocity/velocity.js +146 -0
- data/lib/ledger_web/public/codemirror/mode/xml/index.html +44 -0
- data/lib/ledger_web/public/codemirror/mode/xml/xml.js +252 -0
- data/lib/ledger_web/public/codemirror/mode/xmlpure/index.html +59 -0
- data/lib/ledger_web/public/codemirror/mode/xmlpure/xmlpure.js +485 -0
- data/lib/ledger_web/public/codemirror/mode/yaml/index.html +67 -0
- data/lib/ledger_web/public/codemirror/mode/yaml/yaml.js +95 -0
- data/lib/ledger_web/public/codemirror/theme/cobalt.css +18 -0
- data/lib/ledger_web/public/codemirror/theme/eclipse.css +25 -0
- data/lib/ledger_web/public/codemirror/theme/elegant.css +10 -0
- data/lib/ledger_web/public/codemirror/theme/monokai.css +28 -0
- data/lib/ledger_web/public/codemirror/theme/neat.css +9 -0
- data/lib/ledger_web/public/codemirror/theme/night.css +21 -0
- data/lib/ledger_web/public/codemirror/theme/rubyblue.css +21 -0
- data/lib/ledger_web/public/jquery-1.7.1.min.js +4 -0
- data/lib/ledger_web/public/jquery.tablesorter.min.js +4 -0
- data/lib/ledger_web/public/ledger.css +14 -0
- data/lib/ledger_web/report.rb +187 -0
- data/lib/ledger_web/reports/savings_rate.erb +49 -0
- data/lib/ledger_web/version.rb +3 -0
- data/lib/ledger_web/views/error.erb +5 -0
- data/lib/ledger_web/views/help.erb +6 -0
- data/lib/ledger_web/views/layout.erb +44 -0
- data/lib/ledger_web/views/table.erb +31 -0
- data/lib/ledger_web/watcher.rb +37 -0
- data/lib/ledger_web.rb +20 -0
- metadata +229 -0
@@ -0,0 +1,64 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror: Scheme mode</title>
|
5
|
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
6
|
+
<script src="../../lib/codemirror.js"></script>
|
7
|
+
<script src="scheme.js"></script>
|
8
|
+
<style>.CodeMirror {background: #f8f8f8;}</style>
|
9
|
+
<link rel="stylesheet" href="../../doc/docs.css">
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1>CodeMirror: Scheme mode</h1>
|
13
|
+
<form><textarea id="code" name="code">
|
14
|
+
; See if the input starts with a given symbol.
|
15
|
+
(define (match-symbol input pattern)
|
16
|
+
(cond ((null? (remain input)) #f)
|
17
|
+
((eqv? (car (remain input)) pattern) (r-cdr input))
|
18
|
+
(else #f)))
|
19
|
+
|
20
|
+
; Allow the input to start with one of a list of patterns.
|
21
|
+
(define (match-or input pattern)
|
22
|
+
(cond ((null? pattern) #f)
|
23
|
+
((match-pattern input (car pattern)))
|
24
|
+
(else (match-or input (cdr pattern)))))
|
25
|
+
|
26
|
+
; Allow a sequence of patterns.
|
27
|
+
(define (match-seq input pattern)
|
28
|
+
(if (null? pattern)
|
29
|
+
input
|
30
|
+
(let ((match (match-pattern input (car pattern))))
|
31
|
+
(if match (match-seq match (cdr pattern)) #f))))
|
32
|
+
|
33
|
+
; Match with the pattern but no problem if it does not match.
|
34
|
+
(define (match-opt input pattern)
|
35
|
+
(let ((match (match-pattern input (car pattern))))
|
36
|
+
(if match match input)))
|
37
|
+
|
38
|
+
; Match anything (other than '()), until pattern is found. The rather
|
39
|
+
; clumsy form of requiring an ending pattern is needed to decide where
|
40
|
+
; the end of the match is. If none is given, this will match the rest
|
41
|
+
; of the sentence.
|
42
|
+
(define (match-any input pattern)
|
43
|
+
(cond ((null? (remain input)) #f)
|
44
|
+
((null? pattern) (f-cons (remain input) (clear-remain input)))
|
45
|
+
(else
|
46
|
+
(let ((accum-any (collector)))
|
47
|
+
(define (match-pattern-any input pattern)
|
48
|
+
(cond ((null? (remain input)) #f)
|
49
|
+
(else (accum-any (car (remain input)))
|
50
|
+
(cond ((match-pattern (r-cdr input) pattern))
|
51
|
+
(else (match-pattern-any (r-cdr input) pattern))))))
|
52
|
+
(let ((retval (match-pattern-any input (car pattern))))
|
53
|
+
(if retval
|
54
|
+
(f-cons (accum-any) retval)
|
55
|
+
#f))))))
|
56
|
+
</textarea></form>
|
57
|
+
<script>
|
58
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
|
59
|
+
</script>
|
60
|
+
|
61
|
+
<p><strong>MIME types defined:</strong> <code>text/x-scheme</code>.</p>
|
62
|
+
|
63
|
+
</body>
|
64
|
+
</html>
|
@@ -0,0 +1,202 @@
|
|
1
|
+
/**
|
2
|
+
* Author: Koh Zi Han, based on implementation by Koh Zi Chun
|
3
|
+
*/
|
4
|
+
CodeMirror.defineMode("scheme", function (config, mode) {
|
5
|
+
var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
|
6
|
+
ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword";
|
7
|
+
var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
|
8
|
+
|
9
|
+
function makeKeywords(str) {
|
10
|
+
var obj = {}, words = str.split(" ");
|
11
|
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
12
|
+
return obj;
|
13
|
+
}
|
14
|
+
|
15
|
+
var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
|
16
|
+
var indentKeys = makeKeywords("define let letrec let* lambda");
|
17
|
+
|
18
|
+
|
19
|
+
function stateStack(indent, type, prev) { // represents a state stack object
|
20
|
+
this.indent = indent;
|
21
|
+
this.type = type;
|
22
|
+
this.prev = prev;
|
23
|
+
}
|
24
|
+
|
25
|
+
function pushStack(state, indent, type) {
|
26
|
+
state.indentStack = new stateStack(indent, type, state.indentStack);
|
27
|
+
}
|
28
|
+
|
29
|
+
function popStack(state) {
|
30
|
+
state.indentStack = state.indentStack.prev;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Scheme numbers are complicated unfortunately.
|
35
|
+
* Checks if we're looking at a number, which might be possibly a fraction.
|
36
|
+
* Also checks that it is not part of a longer identifier. Returns true/false accordingly.
|
37
|
+
*/
|
38
|
+
function isNumber(ch, stream){
|
39
|
+
if(/[0-9]/.exec(ch) != null){
|
40
|
+
stream.eatWhile(/[0-9]/);
|
41
|
+
stream.eat(/\//);
|
42
|
+
stream.eatWhile(/[0-9]/);
|
43
|
+
if (stream.eol() || !(/[a-zA-Z\-\_\/]/.exec(stream.peek()))) return true;
|
44
|
+
stream.backUp(stream.current().length - 1); // undo all the eating
|
45
|
+
}
|
46
|
+
return false;
|
47
|
+
}
|
48
|
+
|
49
|
+
return {
|
50
|
+
startState: function () {
|
51
|
+
return {
|
52
|
+
indentStack: null,
|
53
|
+
indentation: 0,
|
54
|
+
mode: false,
|
55
|
+
sExprComment: false
|
56
|
+
};
|
57
|
+
},
|
58
|
+
|
59
|
+
token: function (stream, state) {
|
60
|
+
if (state.indentStack == null && stream.sol()) {
|
61
|
+
// update indentation, but only if indentStack is empty
|
62
|
+
state.indentation = stream.indentation();
|
63
|
+
}
|
64
|
+
|
65
|
+
// skip spaces
|
66
|
+
if (stream.eatSpace()) {
|
67
|
+
return null;
|
68
|
+
}
|
69
|
+
var returnType = null;
|
70
|
+
|
71
|
+
switch(state.mode){
|
72
|
+
case "string": // multi-line string parsing mode
|
73
|
+
var next, escaped = false;
|
74
|
+
while ((next = stream.next()) != null) {
|
75
|
+
if (next == "\"" && !escaped) {
|
76
|
+
|
77
|
+
state.mode = false;
|
78
|
+
break;
|
79
|
+
}
|
80
|
+
escaped = !escaped && next == "\\";
|
81
|
+
}
|
82
|
+
returnType = STRING; // continue on in scheme-string mode
|
83
|
+
break;
|
84
|
+
case "comment": // comment parsing mode
|
85
|
+
var next, maybeEnd = false;
|
86
|
+
while ((next = stream.next()) != null) {
|
87
|
+
if (next == "#" && maybeEnd) {
|
88
|
+
|
89
|
+
state.mode = false;
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
maybeEnd = (next == "|");
|
93
|
+
}
|
94
|
+
returnType = COMMENT;
|
95
|
+
break;
|
96
|
+
case "s-expr-comment": // s-expr commenting mode
|
97
|
+
state.mode = false;
|
98
|
+
if(stream.peek() == "(" || stream.peek() == "["){
|
99
|
+
// actually start scheme s-expr commenting mode
|
100
|
+
state.sExprComment = 0;
|
101
|
+
}else{
|
102
|
+
// if not we just comment the entire of the next token
|
103
|
+
stream.eatWhile(/[^/s]/); // eat non spaces
|
104
|
+
returnType = COMMENT;
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
default: // default parsing mode
|
108
|
+
var ch = stream.next();
|
109
|
+
|
110
|
+
if (ch == "\"") {
|
111
|
+
state.mode = "string";
|
112
|
+
returnType = STRING;
|
113
|
+
|
114
|
+
} else if (ch == "'") {
|
115
|
+
returnType = ATOM;
|
116
|
+
} else if (ch == '#') {
|
117
|
+
if (stream.eat("|")) { // Multi-line comment
|
118
|
+
state.mode = "comment"; // toggle to comment mode
|
119
|
+
returnType = COMMENT;
|
120
|
+
} else if (stream.eat(/[tf]/)) { // #t/#f (atom)
|
121
|
+
returnType = ATOM;
|
122
|
+
} else if (stream.eat(';')) { // S-Expr comment
|
123
|
+
state.mode = "s-expr-comment";
|
124
|
+
returnType = COMMENT;
|
125
|
+
}
|
126
|
+
|
127
|
+
} else if (ch == ";") { // comment
|
128
|
+
stream.skipToEnd(); // rest of the line is a comment
|
129
|
+
returnType = COMMENT;
|
130
|
+
} else if (ch == "-"){
|
131
|
+
|
132
|
+
if(!isNaN(parseInt(stream.peek()))){
|
133
|
+
stream.eatWhile(/[\/0-9]/);
|
134
|
+
returnType = NUMBER;
|
135
|
+
}else{
|
136
|
+
returnType = null;
|
137
|
+
}
|
138
|
+
} else if (isNumber(ch,stream)){
|
139
|
+
returnType = NUMBER;
|
140
|
+
} else if (ch == "(" || ch == "[") {
|
141
|
+
var keyWord = ''; var indentTemp = stream.column();
|
142
|
+
/**
|
143
|
+
Either
|
144
|
+
(indent-word ..
|
145
|
+
(non-indent-word ..
|
146
|
+
(;something else, bracket, etc.
|
147
|
+
*/
|
148
|
+
|
149
|
+
while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
|
150
|
+
keyWord += letter;
|
151
|
+
}
|
152
|
+
|
153
|
+
if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
|
154
|
+
|
155
|
+
pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
|
156
|
+
} else { // non-indent word
|
157
|
+
// we continue eating the spaces
|
158
|
+
stream.eatSpace();
|
159
|
+
if (stream.eol() || stream.peek() == ";") {
|
160
|
+
// nothing significant after
|
161
|
+
// we restart indentation 1 space after
|
162
|
+
pushStack(state, indentTemp + 1, ch);
|
163
|
+
} else {
|
164
|
+
pushStack(state, indentTemp + stream.current().length, ch); // else we match
|
165
|
+
}
|
166
|
+
}
|
167
|
+
stream.backUp(stream.current().length - 1); // undo all the eating
|
168
|
+
|
169
|
+
if(typeof state.sExprComment == "number") state.sExprComment++;
|
170
|
+
|
171
|
+
returnType = BRACKET;
|
172
|
+
} else if (ch == ")" || ch == "]") {
|
173
|
+
returnType = BRACKET;
|
174
|
+
if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
|
175
|
+
popStack(state);
|
176
|
+
|
177
|
+
if(typeof state.sExprComment == "number"){
|
178
|
+
if(--state.sExprComment == 0){
|
179
|
+
returnType = COMMENT; // final closing bracket
|
180
|
+
state.sExprComment = false; // turn off s-expr commenting mode
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
} else {
|
185
|
+
stream.eatWhile(/[\w\$_\-]/);
|
186
|
+
|
187
|
+
if (keywords && keywords.propertyIsEnumerable(stream.current())) {
|
188
|
+
returnType = BUILTIN;
|
189
|
+
}else returnType = null;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
return (typeof state.sExprComment == "number") ? COMMENT : returnType;
|
193
|
+
},
|
194
|
+
|
195
|
+
indent: function (state, textAfter) {
|
196
|
+
if (state.indentStack == null) return state.indentation;
|
197
|
+
return state.indentStack.indent;
|
198
|
+
}
|
199
|
+
};
|
200
|
+
});
|
201
|
+
|
202
|
+
CodeMirror.defineMIME("text/x-scheme", "scheme");
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror: Smalltalk mode</title>
|
5
|
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
6
|
+
<script src="../../lib/codemirror.js"></script>
|
7
|
+
<script src="smalltalk.js"></script>
|
8
|
+
<link rel="stylesheet" href="../../doc/docs.css">
|
9
|
+
<style>
|
10
|
+
.CodeMirror {border: 2px solid #dee; border-right-width: 10px;}
|
11
|
+
.CodeMirror-gutter {border: none; background: #dee;}
|
12
|
+
.CodeMirror-gutter pre {color: white; font-weight: bold;}
|
13
|
+
</style>
|
14
|
+
</head>
|
15
|
+
<body>
|
16
|
+
<h1>CodeMirror: Smalltalk mode</h1>
|
17
|
+
|
18
|
+
<form><textarea id="code" name="code">
|
19
|
+
"
|
20
|
+
This is a test of the Smalltalk code
|
21
|
+
"
|
22
|
+
Seaside.WAComponent subclass: #MyCounter [
|
23
|
+
| count |
|
24
|
+
MyCounter class >> canBeRoot [ ^true ]
|
25
|
+
|
26
|
+
initialize [
|
27
|
+
super initialize.
|
28
|
+
count := 0.
|
29
|
+
]
|
30
|
+
states [ ^{ self } ]
|
31
|
+
renderContentOn: html [
|
32
|
+
html heading: count.
|
33
|
+
html anchor callback: [ count := count + 1 ]; with: '++'.
|
34
|
+
html space.
|
35
|
+
html anchor callback: [ count := count - 1 ]; with: '--'.
|
36
|
+
]
|
37
|
+
]
|
38
|
+
|
39
|
+
MyCounter registerAsApplication: 'mycounter'
|
40
|
+
</textarea></form>
|
41
|
+
|
42
|
+
<script>
|
43
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
44
|
+
lineNumbers: true,
|
45
|
+
matchBrackets: true,
|
46
|
+
mode: "text/x-stsrc",
|
47
|
+
indentUnit: 4
|
48
|
+
});
|
49
|
+
</script>
|
50
|
+
|
51
|
+
<p>Simple Smalltalk mode.</p>
|
52
|
+
|
53
|
+
<p><strong>MIME types defined:</strong> <code>text/x-stsrc</code>.</p>
|
54
|
+
</body>
|
55
|
+
</html>
|
@@ -0,0 +1,139 @@
|
|
1
|
+
CodeMirror.defineMode('smalltalk', function(config, modeConfig) {
|
2
|
+
|
3
|
+
var specialChars = /[+\-/\\*~<>=@%|&?!.:;^]/;
|
4
|
+
var keywords = /true|false|nil|self|super|thisContext/;
|
5
|
+
|
6
|
+
var Context = function(tokenizer, parent) {
|
7
|
+
this.next = tokenizer;
|
8
|
+
this.parent = parent;
|
9
|
+
};
|
10
|
+
|
11
|
+
var Token = function(name, context, eos) {
|
12
|
+
this.name = name;
|
13
|
+
this.context = context;
|
14
|
+
this.eos = eos;
|
15
|
+
};
|
16
|
+
|
17
|
+
var State = function() {
|
18
|
+
this.context = new Context(next, null);
|
19
|
+
this.expectVariable = true;
|
20
|
+
this.indentation = 0;
|
21
|
+
this.userIndentationDelta = 0;
|
22
|
+
};
|
23
|
+
|
24
|
+
State.prototype.userIndent = function(indentation) {
|
25
|
+
this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0;
|
26
|
+
};
|
27
|
+
|
28
|
+
var next = function(stream, context, state) {
|
29
|
+
var token = new Token(null, context, false);
|
30
|
+
var char = stream.next();
|
31
|
+
|
32
|
+
if (char === '"') {
|
33
|
+
token = nextComment(stream, new Context(nextComment, context));
|
34
|
+
|
35
|
+
} else if (char === '\'') {
|
36
|
+
token = nextString(stream, new Context(nextString, context));
|
37
|
+
|
38
|
+
} else if (char === '#') {
|
39
|
+
stream.eatWhile(/[^ .]/);
|
40
|
+
token.name = 'string-2';
|
41
|
+
|
42
|
+
} else if (char === '$') {
|
43
|
+
stream.eatWhile(/[^ ]/);
|
44
|
+
token.name = 'string-2';
|
45
|
+
|
46
|
+
} else if (char === '|' && state.expectVariable) {
|
47
|
+
token.context = new Context(nextTemporaries, context);
|
48
|
+
|
49
|
+
} else if (/[\[\]{}()]/.test(char)) {
|
50
|
+
token.name = 'bracket';
|
51
|
+
token.eos = /[\[{(]/.test(char);
|
52
|
+
|
53
|
+
if (char === '[') {
|
54
|
+
state.indentation++;
|
55
|
+
} else if (char === ']') {
|
56
|
+
state.indentation = Math.max(0, state.indentation - 1);
|
57
|
+
}
|
58
|
+
|
59
|
+
} else if (specialChars.test(char)) {
|
60
|
+
stream.eatWhile(specialChars);
|
61
|
+
token.name = 'operator';
|
62
|
+
token.eos = char !== ';'; // ; cascaded message expression
|
63
|
+
|
64
|
+
} else if (/\d/.test(char)) {
|
65
|
+
stream.eatWhile(/[\w\d]/);
|
66
|
+
token.name = 'number'
|
67
|
+
|
68
|
+
} else if (/[\w_]/.test(char)) {
|
69
|
+
stream.eatWhile(/[\w\d_]/);
|
70
|
+
token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null;
|
71
|
+
|
72
|
+
} else {
|
73
|
+
token.eos = state.expectVariable;
|
74
|
+
}
|
75
|
+
|
76
|
+
return token;
|
77
|
+
};
|
78
|
+
|
79
|
+
var nextComment = function(stream, context) {
|
80
|
+
stream.eatWhile(/[^"]/);
|
81
|
+
return new Token('comment', stream.eat('"') ? context.parent : context, true);
|
82
|
+
};
|
83
|
+
|
84
|
+
var nextString = function(stream, context) {
|
85
|
+
stream.eatWhile(/[^']/);
|
86
|
+
return new Token('string', stream.eat('\'') ? context.parent : context, false);
|
87
|
+
};
|
88
|
+
|
89
|
+
var nextTemporaries = function(stream, context, state) {
|
90
|
+
var token = new Token(null, context, false);
|
91
|
+
var char = stream.next();
|
92
|
+
|
93
|
+
if (char === '|') {
|
94
|
+
token.context = context.parent;
|
95
|
+
token.eos = true;
|
96
|
+
|
97
|
+
} else {
|
98
|
+
stream.eatWhile(/[^|]/);
|
99
|
+
token.name = 'variable';
|
100
|
+
}
|
101
|
+
|
102
|
+
return token;
|
103
|
+
}
|
104
|
+
|
105
|
+
return {
|
106
|
+
startState: function() {
|
107
|
+
return new State;
|
108
|
+
},
|
109
|
+
|
110
|
+
token: function(stream, state) {
|
111
|
+
state.userIndent(stream.indentation());
|
112
|
+
|
113
|
+
if (stream.eatSpace()) {
|
114
|
+
return null;
|
115
|
+
}
|
116
|
+
|
117
|
+
var token = state.context.next(stream, state.context, state);
|
118
|
+
state.context = token.context;
|
119
|
+
state.expectVariable = token.eos;
|
120
|
+
|
121
|
+
state.lastToken = token;
|
122
|
+
return token.name;
|
123
|
+
},
|
124
|
+
|
125
|
+
blankLine: function(state) {
|
126
|
+
state.userIndent(0);
|
127
|
+
},
|
128
|
+
|
129
|
+
indent: function(state, textAfter) {
|
130
|
+
var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta;
|
131
|
+
return (state.indentation + i) * config.indentUnit;
|
132
|
+
},
|
133
|
+
|
134
|
+
electricChars: ']'
|
135
|
+
};
|
136
|
+
|
137
|
+
});
|
138
|
+
|
139
|
+
CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>CodeMirror: SPARQL mode</title>
|
5
|
+
<link rel="stylesheet" href="../../lib/codemirror.css">
|
6
|
+
<script src="../../lib/codemirror.js"></script>
|
7
|
+
<script src="sparql.js"></script>
|
8
|
+
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
|
9
|
+
<link rel="stylesheet" href="../../doc/docs.css">
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1>CodeMirror: SPARQL mode</h1>
|
13
|
+
<form><textarea id="code" name="code">
|
14
|
+
PREFIX a: <http://www.w3.org/2000/10/annotation-ns#>
|
15
|
+
PREFIX dc: <http://purl.org/dc/elements/1.1/>
|
16
|
+
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
|
17
|
+
|
18
|
+
# Comment!
|
19
|
+
|
20
|
+
SELECT ?given ?family
|
21
|
+
WHERE {
|
22
|
+
?annot a:annotates <http://www.w3.org/TR/rdf-sparql-query/> .
|
23
|
+
?annot dc:creator ?c .
|
24
|
+
OPTIONAL {?c foaf:given ?given ;
|
25
|
+
foaf:family ?family } .
|
26
|
+
FILTER isBlank(?c)
|
27
|
+
}
|
28
|
+
</textarea></form>
|
29
|
+
<script>
|
30
|
+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
|
31
|
+
mode: "application/x-sparql-query",
|
32
|
+
tabMode: "indent",
|
33
|
+
matchBrackets: true
|
34
|
+
});
|
35
|
+
</script>
|
36
|
+
|
37
|
+
<p><strong>MIME types defined:</strong> <code>application/x-sparql-query</code>.</p>
|
38
|
+
|
39
|
+
</body>
|
40
|
+
</html>
|
@@ -0,0 +1,143 @@
|
|
1
|
+
CodeMirror.defineMode("sparql", function(config) {
|
2
|
+
var indentUnit = config.indentUnit;
|
3
|
+
var curPunc;
|
4
|
+
|
5
|
+
function wordRegexp(words) {
|
6
|
+
return new RegExp("^(?:" + words.join("|") + ")$", "i");
|
7
|
+
}
|
8
|
+
var ops = wordRegexp(["str", "lang", "langmatches", "datatype", "bound", "sameterm", "isiri", "isuri",
|
9
|
+
"isblank", "isliteral", "union", "a"]);
|
10
|
+
var keywords = wordRegexp(["base", "prefix", "select", "distinct", "reduced", "construct", "describe",
|
11
|
+
"ask", "from", "named", "where", "order", "limit", "offset", "filter", "optional",
|
12
|
+
"graph", "by", "asc", "desc"]);
|
13
|
+
var operatorChars = /[*+\-<>=&|]/;
|
14
|
+
|
15
|
+
function tokenBase(stream, state) {
|
16
|
+
var ch = stream.next();
|
17
|
+
curPunc = null;
|
18
|
+
if (ch == "$" || ch == "?") {
|
19
|
+
stream.match(/^[\w\d]*/);
|
20
|
+
return "variable-2";
|
21
|
+
}
|
22
|
+
else if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) {
|
23
|
+
stream.match(/^[^\s\u00a0>]*>?/);
|
24
|
+
return "atom";
|
25
|
+
}
|
26
|
+
else if (ch == "\"" || ch == "'") {
|
27
|
+
state.tokenize = tokenLiteral(ch);
|
28
|
+
return state.tokenize(stream, state);
|
29
|
+
}
|
30
|
+
else if (/[{}\(\),\.;\[\]]/.test(ch)) {
|
31
|
+
curPunc = ch;
|
32
|
+
return null;
|
33
|
+
}
|
34
|
+
else if (ch == "#") {
|
35
|
+
stream.skipToEnd();
|
36
|
+
return "comment";
|
37
|
+
}
|
38
|
+
else if (operatorChars.test(ch)) {
|
39
|
+
stream.eatWhile(operatorChars);
|
40
|
+
return null;
|
41
|
+
}
|
42
|
+
else if (ch == ":") {
|
43
|
+
stream.eatWhile(/[\w\d\._\-]/);
|
44
|
+
return "atom";
|
45
|
+
}
|
46
|
+
else {
|
47
|
+
stream.eatWhile(/[_\w\d]/);
|
48
|
+
if (stream.eat(":")) {
|
49
|
+
stream.eatWhile(/[\w\d_\-]/);
|
50
|
+
return "atom";
|
51
|
+
}
|
52
|
+
var word = stream.current(), type;
|
53
|
+
if (ops.test(word))
|
54
|
+
return null;
|
55
|
+
else if (keywords.test(word))
|
56
|
+
return "keyword";
|
57
|
+
else
|
58
|
+
return "variable";
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
function tokenLiteral(quote) {
|
63
|
+
return function(stream, state) {
|
64
|
+
var escaped = false, ch;
|
65
|
+
while ((ch = stream.next()) != null) {
|
66
|
+
if (ch == quote && !escaped) {
|
67
|
+
state.tokenize = tokenBase;
|
68
|
+
break;
|
69
|
+
}
|
70
|
+
escaped = !escaped && ch == "\\";
|
71
|
+
}
|
72
|
+
return "string";
|
73
|
+
};
|
74
|
+
}
|
75
|
+
|
76
|
+
function pushContext(state, type, col) {
|
77
|
+
state.context = {prev: state.context, indent: state.indent, col: col, type: type};
|
78
|
+
}
|
79
|
+
function popContext(state) {
|
80
|
+
state.indent = state.context.indent;
|
81
|
+
state.context = state.context.prev;
|
82
|
+
}
|
83
|
+
|
84
|
+
return {
|
85
|
+
startState: function(base) {
|
86
|
+
return {tokenize: tokenBase,
|
87
|
+
context: null,
|
88
|
+
indent: 0,
|
89
|
+
col: 0};
|
90
|
+
},
|
91
|
+
|
92
|
+
token: function(stream, state) {
|
93
|
+
if (stream.sol()) {
|
94
|
+
if (state.context && state.context.align == null) state.context.align = false;
|
95
|
+
state.indent = stream.indentation();
|
96
|
+
}
|
97
|
+
if (stream.eatSpace()) return null;
|
98
|
+
var style = state.tokenize(stream, state);
|
99
|
+
|
100
|
+
if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") {
|
101
|
+
state.context.align = true;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (curPunc == "(") pushContext(state, ")", stream.column());
|
105
|
+
else if (curPunc == "[") pushContext(state, "]", stream.column());
|
106
|
+
else if (curPunc == "{") pushContext(state, "}", stream.column());
|
107
|
+
else if (/[\]\}\)]/.test(curPunc)) {
|
108
|
+
while (state.context && state.context.type == "pattern") popContext(state);
|
109
|
+
if (state.context && curPunc == state.context.type) popContext(state);
|
110
|
+
}
|
111
|
+
else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state);
|
112
|
+
else if (/atom|string|variable/.test(style) && state.context) {
|
113
|
+
if (/[\}\]]/.test(state.context.type))
|
114
|
+
pushContext(state, "pattern", stream.column());
|
115
|
+
else if (state.context.type == "pattern" && !state.context.align) {
|
116
|
+
state.context.align = true;
|
117
|
+
state.context.col = stream.column();
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
return style;
|
122
|
+
},
|
123
|
+
|
124
|
+
indent: function(state, textAfter) {
|
125
|
+
var firstChar = textAfter && textAfter.charAt(0);
|
126
|
+
var context = state.context;
|
127
|
+
if (/[\]\}]/.test(firstChar))
|
128
|
+
while (context && context.type == "pattern") context = context.prev;
|
129
|
+
|
130
|
+
var closing = context && firstChar == context.type;
|
131
|
+
if (!context)
|
132
|
+
return 0;
|
133
|
+
else if (context.type == "pattern")
|
134
|
+
return context.col;
|
135
|
+
else if (context.align)
|
136
|
+
return context.col + (closing ? 0 : 1);
|
137
|
+
else
|
138
|
+
return context.indent + (closing ? 0 : indentUnit);
|
139
|
+
}
|
140
|
+
};
|
141
|
+
});
|
142
|
+
|
143
|
+
CodeMirror.defineMIME("application/x-sparql-query", "sparql");
|