summaryrefslogtreecommitdiffstats
path: root/Parser.sml
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-11-04 18:58:28 -0800
committerRose Hogenson <rosehogenson@posteo.net>2025-11-04 21:05:18 -0800
commiteaa183b7dfc841df75d42ace7a90ada1e40ff282 (patch)
tree1d627b8088d5996a7bbf7c0a7439360e31de3dc3 /Parser.sml
parentc48a992a6ed6ebd79c344b37364a680ddd948dea (diff)
downloadsml-main.tar.zst
Add listsHEADmain
Diffstat (limited to 'Parser.sml')
-rw-r--r--Parser.sml24
1 files changed, 21 insertions, 3 deletions
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 ")" >>