Skip to content

Commit dfb678d

Browse files
committed
Add "Pascal" lang
Fixes #142
1 parent 27a266a commit dfb678d

File tree

14 files changed

+221
-7
lines changed

14 files changed

+221
-7
lines changed

assets/hole.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* include vendor/codemirror-lua.js */
2424
/* include vendor/codemirror-mllike.js */
2525
/* include vendor/codemirror-nim.js */
26+
/* include vendor/codemirror-pascal.js */
2627
/* include vendor/codemirror-perl.js */
2728
/* include vendor/codemirror-php.js */
2829
/* include vendor/codemirror-powershell.js */
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
// CodeMirror, copyright (c) by Marijn Haverbeke and others
2+
// Distributed under an MIT license: https://codemirror.net/LICENSE
3+
4+
CodeMirror.defineMode("pascal", function() {
5+
function words(str) {
6+
var obj = {}, words = str.split(" ");
7+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
8+
return obj;
9+
}
10+
var keywords = words(
11+
"absolute and array asm begin case const constructor destructor div do " +
12+
"downto else end file for function goto if implementation in inherited " +
13+
"inline interface label mod nil not object of operator or packed procedure " +
14+
"program record reintroduce repeat self set shl shr string then to type " +
15+
"unit until uses var while with xor as class dispinterface except exports " +
16+
"finalization finally initialization inline is library on out packed " +
17+
"property raise resourcestring threadvar try absolute abstract alias " +
18+
"assembler bitpacked break cdecl continue cppdecl cvar default deprecated " +
19+
"dynamic enumerator experimental export external far far16 forward generic " +
20+
"helper implements index interrupt iocheck local message name near " +
21+
"nodefault noreturn nostackframe oldfpccall otherwise overload override " +
22+
"pascal platform private protected public published read register " +
23+
"reintroduce result safecall saveregisters softfloat specialize static " +
24+
"stdcall stored strict unaligned unimplemented varargs virtual write");
25+
var atoms = {"null": true};
26+
27+
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
28+
29+
function tokenBase(stream, state) {
30+
var ch = stream.next();
31+
if (ch == "#" && state.startOfLine) {
32+
stream.skipToEnd();
33+
return "meta";
34+
}
35+
if (ch == '"' || ch == "'") {
36+
state.tokenize = tokenString(ch);
37+
return state.tokenize(stream, state);
38+
}
39+
if (ch == "(" && stream.eat("*")) {
40+
state.tokenize = tokenComment;
41+
return tokenComment(stream, state);
42+
}
43+
if (ch == "{") {
44+
state.tokenize = tokenCommentBraces;
45+
return tokenCommentBraces(stream, state);
46+
}
47+
if (/[\[\]\(\),;\:\.]/.test(ch)) {
48+
return null;
49+
}
50+
if (/\d/.test(ch)) {
51+
stream.eatWhile(/[\w\.]/);
52+
return "number";
53+
}
54+
if (ch == "/") {
55+
if (stream.eat("/")) {
56+
stream.skipToEnd();
57+
return "comment";
58+
}
59+
}
60+
if (isOperatorChar.test(ch)) {
61+
stream.eatWhile(isOperatorChar);
62+
return "operator";
63+
}
64+
stream.eatWhile(/[\w\$_]/);
65+
var cur = stream.current();
66+
if (keywords.propertyIsEnumerable(cur)) return "keyword";
67+
if (atoms.propertyIsEnumerable(cur)) return "atom";
68+
return "variable";
69+
}
70+
71+
function tokenString(quote) {
72+
return function(stream, state) {
73+
var escaped = false, next, end = false;
74+
while ((next = stream.next()) != null) {
75+
if (next == quote && !escaped) {end = true; break;}
76+
escaped = !escaped && next == "\\";
77+
}
78+
if (end || !escaped) state.tokenize = null;
79+
return "string";
80+
};
81+
}
82+
83+
function tokenComment(stream, state) {
84+
var maybeEnd = false, ch;
85+
while (ch = stream.next()) {
86+
if (ch == ")" && maybeEnd) {
87+
state.tokenize = null;
88+
break;
89+
}
90+
maybeEnd = (ch == "*");
91+
}
92+
return "comment";
93+
}
94+
95+
function tokenCommentBraces(stream, state) {
96+
var ch;
97+
while (ch = stream.next()) {
98+
if (ch == "}") {
99+
state.tokenize = null;
100+
break;
101+
}
102+
}
103+
return "comment";
104+
}
105+
106+
// Interface
107+
108+
return {
109+
startState: function() {
110+
return {tokenize: null};
111+
},
112+
113+
token: function(stream, state) {
114+
if (stream.eatSpace()) return null;
115+
var style = (state.tokenize || tokenBase)(stream, state);
116+
if (style == "comment" || style == "meta") return style;
117+
return style;
118+
},
119+
120+
electricChars: "{}"
121+
};
122+
});
123+
124+
CodeMirror.defineMIME("text/x-pascal", "pascal");

build-langs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ for %langs{ @langs || * }:p.sort -> (:key($name), :value(%lang)) {
3636
%lang<version> = $id eq 'assembly' ?? "DefAssembler $0" !! $0;
3737
}
3838
else {
39-
( my $proc = run «docker run --rm --tmpfs /tmp $img», :out ).sink;
39+
( my $proc = run «docker run --rm --tmpfs '/tmp:exec' $img», :out ).sink;
4040

4141
my $ver = $proc.out.slurp(:close).chomp.trans: "\n" => ' ';
4242

css/golfer/holes.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ input.julia:not(:checked) ~ .julia,
5252
input.lisp:not(:checked) ~ .lisp,
5353
input.lua:not(:checked) ~ .lua,
5454
input.nim:not(:checked) ~ .nim,
55+
input.pascal:not(:checked) ~ .pascal,
5556
input.perl:not(:checked) ~ .perl,
5657
input.php:not(:checked) ~ .php,
5758
input.powershell:not(:checked) ~ .powershell,
@@ -87,7 +88,7 @@ main svg:nth-of-type(2) {
8788

8889
@media (min-width: 95rem) {
8990
/* Increase this number when adding a language. */
90-
main { grid-template-columns: 4fr repeat(31, 1fr) }
91+
main { grid-template-columns: 4fr repeat(32, 1fr) }
9192

9293
main a { height: 1.9rem }
9394

db/a-schema.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ CREATE TYPE keymap AS ENUM ('default', 'vim');
3333
CREATE TYPE lang AS ENUM (
3434
'assembly', 'bash', 'brainfuck', 'c', 'c-sharp', 'cobol', 'crystal',
3535
'f-sharp', 'fish', 'fortran', 'go', 'haskell', 'hexagony', 'j', 'java',
36-
'javascript', 'julia', 'lisp', 'lua', 'nim', 'perl', 'php', 'powershell',
37-
'python', 'raku', 'ruby', 'rust', 'sql', 'swift', 'v', 'zig'
36+
'javascript', 'julia', 'lisp', 'lua', 'nim', 'pascal', 'perl', 'php',
37+
'powershell', 'python', 'raku', 'ruby', 'rust', 'sql', 'swift', 'v', 'zig'
3838
);
3939

4040
CREATE TYPE medal AS ENUM ('diamond', 'gold', 'silver', 'bronze');

docker/dev.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ COPY --from=codegolf/lang-python ["/", "/langs/python/rootfs/" ] # 57 M
2424
COPY --from=codegolf/lang-raku ["/", "/langs/raku/rootfs/" ] # 54 MiB
2525
COPY --from=codegolf/lang-assembly ["/", "/langs/assembly/rootfs/" ] # 48.7 MiB
2626
COPY --from=codegolf/lang-lisp ["/", "/langs/lisp/rootfs/" ] # 33.6 MiB
27+
COPY --from=codegolf/lang-pascal ["/", "/langs/pascal/rootfs/" ] # 31.3 MiB
2728
COPY --from=codegolf/lang-nim ["/", "/langs/nim/rootfs/" ] # 21.6 MiB
2829
COPY --from=codegolf/lang-javascript ["/", "/langs/javascript/rootfs/"] # 20.8 MiB
2930
COPY --from=codegolf/lang-ruby ["/", "/langs/ruby/rootfs/" ] # 14.4 MiB

docker/live.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ COPY --from=codegolf/lang-python ["/", "/langs/python/rootfs/" ] # 57 M
3737
COPY --from=codegolf/lang-raku ["/", "/langs/raku/rootfs/" ] # 54 MiB
3838
COPY --from=codegolf/lang-assembly ["/", "/langs/assembly/rootfs/" ] # 48.7 MiB
3939
COPY --from=codegolf/lang-lisp ["/", "/langs/lisp/rootfs/" ] # 33.6 MiB
40+
COPY --from=codegolf/lang-pascal ["/", "/langs/pascal/rootfs/" ] # 31.3 MiB
4041
COPY --from=codegolf/lang-nim ["/", "/langs/nim/rootfs/" ] # 21.6 MiB
4142
COPY --from=codegolf/lang-javascript ["/", "/langs/javascript/rootfs/"] # 20.8 MiB
4243
COPY --from=codegolf/lang-ruby ["/", "/langs/ruby/rootfs/" ] # 14.4 MiB

js/hole-ng.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { javascript } from '@codemirror/lang-javascript';
3232
import { julia } from '@codemirror/legacy-modes/mode/julia';
3333
import { lua } from '@codemirror/legacy-modes/mode/lua';
3434
import { nim } from 'nim-codemirror-mode';
35+
import { pascal } from '@codemirror/legacy-modes/mode/pascal';
3536
import { perl } from '@codemirror/legacy-modes/mode/perl';
3637
import { powerShell } from '@codemirror/legacy-modes/mode/powershell';
3738
import { python } from '@codemirror/lang-python';
@@ -105,6 +106,7 @@ const extensions = {
105106
'lisp': StreamLanguage.define(commonLisp),
106107
'lua': StreamLanguage.define(lua),
107108
'nim': StreamLanguage.define(nim( {}, {} )),
109+
'pascal': StreamLanguage.define(pascal),
108110
'perl': StreamLanguage.define(perl),
109111
// TODO php
110112
'powershell': StreamLanguage.define(powerShell),

langs.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,27 @@ for arg in commandLineParams():
459459
echo arg
460460
'''
461461

462+
[Pascal]
463+
size = '31.3 MiB'
464+
version = '3.2.2'
465+
website = 'https://freepascal.org'
466+
example = '''
467+
var
468+
i: integer;
469+
begin
470+
{ Printing }
471+
writeLn('Hello, World!');
472+
473+
{ Looping }
474+
for i := 0 to 9 do
475+
writeLn(i);
476+
477+
{ Accessing arguments }
478+
for i := 1 to paramCount() do
479+
writeLn(paramStr(i));
480+
end.
481+
'''
482+
462483
[Perl]
463484
size = '4.32 MiB'
464485
version = '5.34.0'

langs/pascal/Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM alpine:3.14 as builder
2+
3+
RUN mkdir /empty
4+
5+
RUN apk add --no-cache binutils curl
6+
7+
ENV ARCH=x86_64-linux VERSION=3.2.2
8+
9+
RUN curl -L https://downloads.sourceforge.net/project/freepascal/Linux/$VERSION/fpc-$VERSION.$ARCH.tar | tar x
10+
11+
# Workaround musl vs glibc entrypoint for fpcmkcfg.
12+
RUN mkdir /lib64 \
13+
&& ln -s /lib/ld-musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
14+
15+
RUN cd fpc-$VERSION.$ARCH && echo -e '/usr\nN\nN\nN\n' | sh install.sh
16+
17+
# Remove some unneeded units.
18+
RUN find /usr/lib/fpc/$VERSION/units/$ARCH \
19+
-type d -mindepth 1 -maxdepth 1 \
20+
-not -name fcl-base \
21+
-not -name rtl \
22+
-not -name rtl-console \
23+
-not -name rtl-objpas \
24+
-exec rm -r {} +
25+
26+
FROM scratch
27+
28+
COPY --from=0 /bin /bin
29+
COPY --from=0 /lib/ld-musl-x86_64.so.1 \
30+
/lib/libz.so.1 /lib/
31+
COPY --from=0 /etc/fpc.cfg /etc/
32+
COPY --from=0 /empty /proc
33+
COPY --from=0 /empty /tmp
34+
COPY --from=0 /usr/bin/fpc \
35+
/usr/bin/ld /usr/bin/
36+
COPY --from=0 /usr/lib/libbfd-2.35.2.so \
37+
/usr/lib/libctf.so.0 /usr/lib/
38+
COPY --from=0 /usr/lib/fpc /usr/lib/fpc
39+
40+
COPY pascal /usr/bin/
41+
42+
ENTRYPOINT ["/usr/bin/pascal"]
43+
44+
CMD ["version"]

0 commit comments

Comments
 (0)