summaryrefslogtreecommitdiffstats
path: root/Parser.sml
diff options
context:
space:
mode:
Diffstat (limited to 'Parser.sml')
-rw-r--r--Parser.sml24
1 files changed, 22 insertions, 2 deletions
diff --git a/Parser.sml b/Parser.sml
index 8a1e1f3..a967880 100644
--- a/Parser.sml
+++ b/Parser.sml
@@ -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