From eaa183b7dfc841df75d42ace7a90ada1e40ff282 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 4 Nov 2025 18:58:28 -0800 Subject: Add lists --- Parser.sml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'Parser.sml') diff --git a/Parser.sml b/Parser.sml index 8f43352..9f31f8d 100644 --- a/Parser.sml +++ b/Parser.sml @@ -28,8 +28,18 @@ struct , "signature", "struct", "structure", "where", ":>" ] - val emptyInfixOperators : infixTable = - Vector.tabulate (10, fn _ => ([], [])) + val defaultInfixOperators : infixTable = Vector.fromList + [ ([], []) + , ([], []) + , ([], []) + , ([], []) + , ([], []) + , ([], ["::"]) + , ([], []) + , ([], []) + , ([], []) + , ([], []) + ] fun printSourceLoc ({file, row, column} : sourceLoc) : string = file ^ ":" ^ Int.toString row ^ "." ^ Int.toString column @@ -69,7 +79,7 @@ struct fun newState (fileName : string) (fileStream : TextIO.instream) : state = { stream = TextIO.getInstream fileStream, loc = newLoc fileName, - userState = {infixTable = emptyInfixOperators} + userState = {infixTable = defaultInfixOperators} } fun updateUserState (f : userState -> userState) : userState parser = @@ -414,6 +424,10 @@ struct val rec atpat : Syntax.pat parser = fn st => (Syntax.PWild <$ reserved "_" <|> Syntax.PInt <$> integer + <|> (symbol "[" >> + bind (sepBy pat (symbol ",")) (fn pats => + symbol "]" >> + const (Syntax.PList pats))) <|> bind (between (symbol "(") (symbol ")") (sepBy pat (symbol ","))) (fn pats => const (case pats of @@ -476,6 +490,10 @@ struct bind expr (fn e => reserved "end" >> const (Syntax.ELet (List.mapPartial (fn x => x) decs, e))))) + <|> (symbol "[" >> + bind (sepBy expr (symbol ",")) (fn exprs => + symbol "]" >> + const (Syntax.EList exprs))) <|> (symbol "(" >> bind (sepBy expr (symbol ",")) (fn exprs => symbol ")" >> -- cgit v1.3.1