Skip to content

Commit 86478ce

Browse files
committed
Add codemirror mode
0 parents  commit 86478ce

File tree

7 files changed

+10913
-0
lines changed

7 files changed

+10913
-0
lines changed

demo/index.html

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!doctype html>
2+
3+
<title>CodeMirror: Lambda Calculus mode</title>
4+
<meta charset="utf-8"/>
5+
<link rel=stylesheet href="src/docs.css">
6+
7+
<link rel="stylesheet" href="src/codemirror.css">
8+
<link rel="stylesheet" href="src/3024-night.css">
9+
<script src="src/codemirror.js"></script>
10+
<script src="src/matchbrackets.js"></script>
11+
<script src="../lambdacalc.js"></script>
12+
<style>.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
13+
<div id=nav>
14+
<a href="https://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png" alt=""></a>
15+
<ul>
16+
<li><a class=active href="#">Lambda Calculus</a>
17+
</ul>
18+
</div>
19+
20+
<article>
21+
<h2>Lambda Calculus mode</h2>
22+
<form><textarea id="code" name="code">
23+
24+
# Some code (with ignored arguments)
25+
false = \ _a b . b
26+
true = \ a _b . a
27+
not = \ b . b false true
28+
const = true
29+
30+
# Invalid - multiple definition
31+
true = not false
32+
33+
# Invalid names
34+
%value = ()
35+
36+
# Invalid args - unbound
37+
someFunc = \ local . true nonexistant local
38+
39+
# Invalid args - scoped
40+
otherFunc = \ x . const (\ scopedArg . x ()) scopedArg x
41+
42+
# More code
43+
zero = false
44+
succ = \ n f x . f (n f x)
45+
isZ = \ n . n (const false) true
46+
add = \ a b f x . a f (b f x)
47+
mul = \ a b f . a (b f)
48+
three = succ (succ (succ zero))
49+
mt = mul three
50+
nine = mul three three
51+
52+
pair = \ a b c . c a b
53+
fst = \ c . c true
54+
snd = \ c . c false
55+
56+
nil = pair false ()
57+
null = \ l . not (fst l)
58+
head = \ l . fst (snd l)
59+
tail = \ l . snd (snd l)
60+
cons = \ x xs . pair true (pair x xs)
61+
replicate = \ n v . n (cons v) nil
62+
repeat = \ v . cons v (repeat v)
63+
foldr = \ f b as . null as b (f (head as) (foldr f b (tail as)))
64+
pred = \ n f x . foldr (const f) x (tail (replicate n ())) # Bit janky lol
65+
map = \ f xs . null xs nil (cons (f (head xs)) (map f (tail xs)))
66+
sum = foldr add zero
67+
drop = \ n . n tail
68+
take = \ n xs . isZ n nil (cons (head xs) (take (pred n) (tail xs)))
69+
col = \ n xs . head (drop n xs)
70+
colS = \ n xs . cons (col n xs) (cons (col (succ n) xs) (cons (col (succ (succ n)) xs) (nil)))
71+
row = \ n xs . map (col n) xs
72+
rowS = \ n xs . cons (row n xs) (cons (row (succ n) xs) (cons (row (succ (succ n)) xs) (nil)))
73+
chunk = \ a b xs . rowS a (colS b xs)
74+
append = \ as bs . null as bs (cons (head as) (append (tail as) bs))
75+
concat = foldr append nil
76+
eq = \ a b . isZ a (isZ b) (isZ b false (eq (pred a) (pred b)))
77+
all = foldr (\ a b . a b false) true
78+
allf = \ f xs . all (map f xs)
79+
</textarea></form>
80+
81+
<script>
82+
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
83+
lineNumbers: true,
84+
matchBrackets: true,
85+
theme: "3024-night",
86+
specialChars: /\\/,
87+
specialCharPlaceholder: () => {
88+
const elem = document.createElement("span");
89+
elem.setAttribute("cm-text", "\\");
90+
elem.innerHTML = "λ";
91+
return elem;
92+
}
93+
});
94+
editor.setSize(500, 500);
95+
</script>
96+
97+
<p><strong>MIME types defined:</strong> <code>text/lambda-calc</code>.</p>
98+
</article>

demo/src/3024-night.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
3+
Name: 3024 night
4+
Author: Jan T. Sott (http://github.com/idleberg)
5+
6+
CodeMirror template by Jan T. Sott (https://github.com/idleberg/base16-codemirror)
7+
Original Base16 color scheme by Chris Kempson (https://github.com/chriskempson/base16)
8+
9+
*/
10+
11+
.cm-s-3024-night.CodeMirror { background: #090300; color: #d6d5d4; }
12+
.cm-s-3024-night div.CodeMirror-selected { background: #3a3432; }
13+
.cm-s-3024-night .CodeMirror-line::selection, .cm-s-3024-night .CodeMirror-line > span::selection, .cm-s-3024-night .CodeMirror-line > span > span::selection { background: rgba(58, 52, 50, .99); }
14+
.cm-s-3024-night .CodeMirror-line::-moz-selection, .cm-s-3024-night .CodeMirror-line > span::-moz-selection, .cm-s-3024-night .CodeMirror-line > span > span::-moz-selection { background: rgba(58, 52, 50, .99); }
15+
.cm-s-3024-night .CodeMirror-gutters { background: #090300; border-right: 0px; }
16+
.cm-s-3024-night .CodeMirror-guttermarker { color: #db2d20; }
17+
.cm-s-3024-night .CodeMirror-guttermarker-subtle { color: #5c5855; }
18+
.cm-s-3024-night .CodeMirror-linenumber { color: #5c5855; }
19+
20+
.cm-s-3024-night .CodeMirror-cursor { border-left: 1px solid #807d7c; }
21+
22+
.cm-s-3024-night span.cm-comment { color: #cdab53; }
23+
.cm-s-3024-night span.cm-atom { color: #a16a94; }
24+
.cm-s-3024-night span.cm-number { color: #a16a94; }
25+
26+
.cm-s-3024-night span.cm-property, .cm-s-3024-night span.cm-attribute { color: #01a252; }
27+
.cm-s-3024-night span.cm-keyword { color: #db2d20; }
28+
.cm-s-3024-night span.cm-string { color: #fded02; }
29+
30+
.cm-s-3024-night span.cm-variable { color: #01a252; }
31+
.cm-s-3024-night span.cm-variable-2 { color: #01a0e4; }
32+
.cm-s-3024-night span.cm-def { color: #e8bbd0; }
33+
.cm-s-3024-night span.cm-bracket { color: #d6d5d4; }
34+
.cm-s-3024-night span.cm-tag { color: #db2d20; }
35+
.cm-s-3024-night span.cm-link { color: #a16a94; }
36+
.cm-s-3024-night span.cm-error { background: #db2d20; color: #807d7c; }
37+
38+
.cm-s-3024-night .CodeMirror-activeline-background { background: #2F2F2F; }
39+
.cm-s-3024-night .CodeMirror-matchingbracket { text-decoration: underline; color: white !important; }

0 commit comments

Comments
 (0)