diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-07-04 11:19:55 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-07-04 11:19:55 -0700 |
| commit | ed48b02873f3ea3cab0107176d00eb00c9519766 (patch) | |
| tree | b8520790160c42466b5bef7644365259c6076bc4 /Parser.sml | |
| parent | 73d1d16befe44d7d73db40b47aef0fd61285501d (diff) | |
| download | sml-ed48b02873f3ea3cab0107176d00eb00c9519766.tar.zst | |
Add signatures
Diffstat (limited to 'Parser.sml')
| -rw-r--r-- | Parser.sml | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -619,9 +619,28 @@ struct val rec strdec : Syntax.dec option parser = fn st => ((reserved "structure" >> bind identifier (fn strID => + bind + (((reserved ":" <|> reserved ":>") >> + SOME <$> identifier) + <|> const NONE) + (fn s => reserved "=" >> bind structExpr (fn str => - const (SOME (Syntax.DStruct (strID, str)))))) + const (SOME (Syntax.DStruct (strID, s, str))))))) + <|> (reserved "signature" >> + bind identifier (fn sigID => + reserved "=" >> + reserved "sig" >> + bind + (many + (reserved "val" >> + bind identifier (fn id => + reserved ":" >> + bind parseType (fn ty => + const (id, ty))))) + (fn bindings => + reserved "end" >> + const (SOME (Syntax.DSig (sigID, bindings)))))) <|> dec) st and structExpr : Syntax.structExpr parser = fn st => ((reserved "struct" >> @@ -655,7 +674,8 @@ struct Syntax.DFun (f, map (fn (args, body) => (map (fixPatConstructors constructors) args, fixConstructors constructors body)) arms) | fixDecConstructors _ (decl as Syntax.DDatatype _) = decl | fixDecConstructors _ (decl as Syntax.DType _) = decl - | fixDecConstructors constructors (Syntax.DStruct (name, str)) = Syntax.DStruct (name, fixStructExprConstructors constructors str) + | fixDecConstructors constructors (Syntax.DStruct (name, s, str)) = Syntax.DStruct (name, s, fixStructExprConstructors constructors str) + | fixDecConstructors constructors (s as Syntax.DSig _) = s and fixStructExprConstructors (constructors : unit StringMap.map) (Syntax.SStruct decls) : Syntax.structExpr = let val constructors = ref constructors in |
