aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMalte Voos <git@mal.tc>2024-02-20 14:00:27 +0100
committerMalte Voos <git@mal.tc>2024-02-20 14:00:27 +0100
commit4b2a72d01b48b9e5fd4743b98b0c6bf6422cfc0c (patch)
treecddb4b01dec26679ecdbb190286ac45fed78161a /lib
parent5252fe93e5e7ef77888c06c97de4e350dce90448 (diff)
downloadtoytt-4b2a72d01b48b9e5fd4743b98b0c6bf6422cfc0c.tar.gz
toytt-4b2a72d01b48b9e5fd4743b98b0c6bf6422cfc0c.zip
use yuujinchou for identifiers
Diffstat (limited to 'lib')
-rw-r--r--lib/Ast.ml29
-rw-r--r--lib/Parser.mly6
-rw-r--r--lib/dune2
3 files changed, 21 insertions, 16 deletions
diff --git a/lib/Ast.ml b/lib/Ast.ml
index d26cc0f..2f6536d 100644
--- a/lib/Ast.ml
+++ b/lib/Ast.ml
@@ -1,4 +1,4 @@
-type raw_ident = string
+type raw_ident = Yuujinchou.Trie.path
type ident = raw_ident Asai.Range.located
type raw_arg = { name : ident; ty : expr }
@@ -27,7 +27,9 @@ and raw_expr =
and expr = raw_expr Asai.Range.located
-let pp_raw_ident fmt (id : raw_ident) = Format.fprintf fmt "@[%s@]" id
+let pp_raw_ident fmt (id : raw_ident) = Format.pp_print_list
+ ~pp_sep:(fun fmt () -> Format.pp_print_char fmt '.')
+ Format.pp_print_string fmt id
let pp_ident fmt ({ value; _ } : ident) = pp_raw_ident fmt value
let rec pp_raw_arg fmt ({ name; ty } : raw_arg) =
@@ -41,22 +43,23 @@ and pp_raw_expr fmt = function
| True -> Format.pp_print_string fmt "True"
| False -> Format.pp_print_string fmt "False"
| BoolElim { motive_var; motive_body; true_case; false_case; scrut } ->
- Format.fprintf fmt
- "@[<10>BoolElim (@[%a@] ->@ @[%a@],@ @[%a@],@ @[%a@],@ @[%a@])@]" pp_ident
- motive_var pp_expr motive_body pp_expr true_case pp_expr
- false_case pp_expr scrut
+ Format.fprintf fmt
+ "@[<10>BoolElim (@[%a@] ->@ @[%a@],@ @[%a@],@ @[%a@],@ @[%a@])@]"
+ pp_ident motive_var
+ pp_expr motive_body
+ pp_expr true_case
+ pp_expr false_case
+ pp_expr scrut
| Pi (dom, cod) ->
- Format.fprintf fmt "@[<4>Pi (@[%a@],@ @[%a@])@]" pp_arg dom pp_expr cod
+ Format.fprintf fmt "@[<4>Pi (@[%a@],@ @[%a@])@]" pp_arg dom pp_expr cod
| Lam (var, body) ->
- Format.fprintf fmt "@[<5>Lam (@[%a@].@ @[%a@])@]" pp_ident var pp_expr
- body
+ Format.fprintf fmt "@[<5>Lam (@[%a@].@ @[%a@])@]" pp_ident var pp_expr body
| App (fn, arg) ->
- Format.fprintf fmt "@[<5>App (@[%a@],@ @[%a@])@]" pp_expr fn pp_expr arg
+ Format.fprintf fmt "@[<5>App (@[%a@],@ @[%a@])@]" pp_expr fn pp_expr arg
| Sg (fst, snd) ->
- Format.fprintf fmt "@[<4>Sg (@[%a@],@ @[%a@])@]" pp_arg fst pp_expr snd
+ Format.fprintf fmt "@[<4>Sg (@[%a@],@ @[%a@])@]" pp_arg fst pp_expr snd
| Pair (fst, snd) ->
- Format.fprintf fmt "@[<6>Pair (@[%a@],@ @[%a@])@]" pp_expr fst pp_expr
- snd
+ Format.fprintf fmt "@[<6>Pair (@[%a@],@ @[%a@])@]" pp_expr fst pp_expr snd
| Fst p -> Format.fprintf fmt "@[<5>Fst (@[%a@])@]" pp_expr p
| Snd p -> Format.fprintf fmt "@[<5>Snd (@[%a@])@]" pp_expr p
| Type -> Format.pp_print_string fmt "Type"
diff --git a/lib/Parser.mly b/lib/Parser.mly
index d0395ac..0390b3c 100644
--- a/lib/Parser.mly
+++ b/lib/Parser.mly
@@ -21,8 +21,10 @@ open Ast
%inline
locate(X): e = X { Asai.Range.locate_lex $loc e }
+raw_ident: id = separated_nonempty_list(DOT, IDENT) { id }
+
%inline
-ident: id = locate(IDENT) { id }
+ident: id = locate(raw_ident) { id }
raw_arg: LPR; name = ident; COLON; ty = expr; RPR
{ { name; ty } }
@@ -31,7 +33,7 @@ raw_arg: LPR; name = ident; COLON; ty = expr; RPR
arg: a = locate(raw_arg) { a }
raw_expr:
- | name = IDENT
+ | name = raw_ident
{ Var name }
| LPR; e = raw_expr; RPR
{ e }
diff --git a/lib/dune b/lib/dune
index 7a54f53..7889c59 100644
--- a/lib/dune
+++ b/lib/dune
@@ -6,5 +6,5 @@
(library
(name toytt)
- (libraries asai)
+ (libraries asai yuujinchou)
(preprocess (pps ppx_deriving.std)))