quox/syntax.ebnf

87 lines
2.4 KiB
EBNF
Raw Permalink Normal View History

2023-04-23 11:33:50 -04:00
input = {top level}.
top level = load | decl.
decl = namespace | def.
(* top level semicolons are optional because all decls start with a
special word. like in ocaml *)
load = "load", STRING, [";"].
namespace = "namespace", "{", {decl}, "}", [";"].
def = def intro, NAME, [":", term], "=", term, [";"].
def intro = "def0" | "defω" | "def", [qty, "."].
(* "def" with no qty defaults to ω *)
qty = "0" | "1" | "ω".
dim = dim const | name.
dim const = "0" | "1".
dim arg = "@", dim.
pat var = NAME | "_".
2023-12-04 17:35:54 -05:00
term = lambda | pi | sigma | ann | let.
2023-04-23 11:33:50 -04:00
lambda = ("λ" | "δ"), {pat var}+, "⇒", term.
case = case intro, term, "return", case return, "of", case body.
(* default qty is 1 *)
case intro = "case0" | "case1" | "caseω" | "case", [qty, "."].
2023-04-23 11:33:50 -04:00
case return = [pat var, "⇒"], term.
case body = "{", {pattern, "⇒", term / ";"}, [";"], "}".
pattern = "zero" | "0"
| "succ", pat var, [",", [qty, "."], pat var]
(* default qty for IH is 1 *)
2023-04-23 11:33:50 -04:00
| TAG
| "[", pat var, "]"
| "(", pat var, ",", pat var, ")".
(* default qty is 1 *)
pi = [qty, "."], (binder | term arg), "→", term.
2023-04-23 11:33:50 -04:00
binder = "(", {NAME}+, ":", term, ")".
sigma = (binder | ann), "×", (sigma | ann).
ann = infix eq, ["∷", term].
2023-12-04 17:35:54 -05:00
bare let binder = pat var, "=", term.
qty let binder = [qty, "."], bare let binder.
let = ("let0" | "let1" | "letω"), {bare let binder / ";"}+, "in", term
| "let", {qty let binder / ";"}+, "in", term.
2023-04-23 11:33:50 -04:00
infix eq = app term, ["≡", term, ":", app term]. (* dependent is below *)
2023-12-04 17:35:54 -05:00
app term = coe | comp | split universe | dep eq | special app | normal app.
2023-04-23 11:33:50 -04:00
split universe = "★", NAT.
dep eq = "Eq", type line, term arg, term arg.
2023-12-04 17:35:54 -05:00
special app = ("fst" | "snd" | "succ"), {term arg}+.
2023-04-23 11:33:50 -04:00
normal app = term arg, {term arg | dim arg}.
(* direction defaults to @0 @1 *)
coe = "coe", type line, [dim arg, dim arg], term arg.
2023-04-23 11:33:50 -04:00
type line = "[", [pat var, "⇒"], term, "]".
comp = "comp", type line, [dim arg, dim arg],
term arg, dim arg, comp body.
2023-04-23 11:33:50 -04:00
comp body = "{", comp branch, ";", comp branch, [";"], "}".
comp branch = dim const, name, "⇒", term.
2023-05-21 14:09:34 -04:00
displacement = SUPER.
term arg = UNIVERSE | "★", SUPER
| "{", {BARE TAG / ","}, [","], "}"
2023-04-23 11:33:50 -04:00
| TAG
| "[", [qty, "."], term, "]"
| ""
| "zero"
| NAT
2023-05-21 14:09:34 -04:00
| QNAME, displacement
2023-12-04 17:35:54 -05:00
| "(", {term / ","}+, [","], ")"
| case.