diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-17 12:36:56 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2024-05-17 12:36:56 -0700 |
| commit | c39c43e144733973ebf9cd6842df75b5a5ceee0b (patch) | |
| tree | 91712d2b3dd9dfe30806e447830e1f8665286c05 /syntax.sml | |
| parent | 8ec4edc977e0ed87f86c7e74c13d3633cb788069 (diff) | |
| download | sml-c39c43e144733973ebf9cd6842df75b5a5ceee0b.tar.zst | |
Add datatypes.
Diffstat (limited to 'syntax.sml')
| -rw-r--r-- | syntax.sml | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -12,6 +12,7 @@ struct | PVar of string | PInt of int | PTuple of pat list + | PCon of string * pat datatype expr = EIdent of string list @@ -31,6 +32,7 @@ struct and dec = DVal of pat * expr | DValRec of pat * expr + | DDatatype of string * (string * etype option) list (* Lambda language *) type var = int @@ -101,6 +103,11 @@ struct fun quote (s : string) : string = "\"" ^ String.toString s ^ "\"" + fun optionToString (show : 'a -> string) (x : 'a option) = + case x of + NONE => "NONE" + | SOME x => "SOME " ^ show x + fun etypeToString (x : etype) : string = case x of Tyvar s => "Tyvar " ^ quote s @@ -114,6 +121,7 @@ struct | PVar v => "PVar " ^ quote v | PInt i => "PInt " ^ Int.toString i | PTuple pats => "PTuple " ^ listToString patToString pats + | PCon (con, v) => "PCon " ^ "(" ^ quote con ^ ", " ^ patToString v ^ ")" fun exprToStringI (indent : string) (x : expr) : string = let val self = exprToStringI indent @@ -137,6 +145,7 @@ struct case x of DVal (p, e) => "DVal (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")" | DValRec (p, e) => "DValRec (" ^ patToString p ^ ", " ^ exprToStringI indent e ^ ")" + | DDatatype (name, arms) => "DDatatype (" ^ quote name ^ ", " ^ listToString (fn (con, v) => "(" ^ quote con ^ ", " ^ optionToString etypeToString v ^ ")") arms ^ ")" val exprToString : expr -> string = exprToStringI "" |
