-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammer.pegjs
35 lines (33 loc) · 1.01 KB
/
grammer.pegjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
const {
emitProgram,
emitmoOToken,
emitmOoToken,
emitMoOToken,
emitMOoToken,
emitoomToken,
emitOOMToken,
emitMOOToken,
emitmOOToken,
emitOOOToken,
emitMMMToken,
emitMooToken,
} = require("./helper");
}
start = body:line* { return emitProgram(body); }
line = sp* instr:instruction* nl { return instr; }
instruction = tkn:token sp* { return tkn; }
token = moO / mOo / MoO / MOo / oom / OOM / Moo / MMM / OOO / MOO
moO = "moO" { return emitmoOToken(); }
mOo = "mOo" { return emitmOoToken(); }
MoO = "MoO" { return emitMoOToken(); }
MOo = "MOo" { return emitMOoToken(); }
oom = "oom" { return emitoomToken(); }
OOM = "OOM" { return emitOOMToken(); }
Moo = "Moo" { return emitMooToken(); }
MMM = "MMM" { return emitMMMToken(); }
OOO = "OOO" { return emitOOOToken(); }
MOO = "MOO" line:line* sp* instr:instruction* "moo"
{ const content = line.concat(instr); return emitMOOToken(content); }
sp = "\t" / " "
nl = "\r" / "\n"