aboutsummaryrefslogtreecommitdiff
path: root/Sil/Parse.icl
diff options
context:
space:
mode:
Diffstat (limited to 'Sil/Parse.icl')
-rw-r--r--Sil/Parse.icl29
1 files changed, 19 insertions, 10 deletions
diff --git a/Sil/Parse.icl b/Sil/Parse.icl
index c9521bf..cdd117f 100644
--- a/Sil/Parse.icl
+++ b/Sil/Parse.icl
@@ -33,9 +33,12 @@ instance toString Token
where
toString TParenOpen = "("
toString TParenClose = ")"
+ toString TBrackOpen = "["
+ toString TBrackClose = "]"
toString TBraceOpen = "{"
toString TBraceClose = "}"
toString TComma = ","
+ toString TColon = ":"
toString TSemicolon = ";"
toString (TField f) = "." +++ f
toString TAssign = ":="
@@ -78,9 +81,12 @@ where
tks ['&':'&':r] t = tks r [TDoubleAmpersand:t]
tks ['(':r] t = tks r [TParenOpen :t]
tks [')':r] t = tks r [TParenClose :t]
+ tks ['[':r] t = tks r [TBrackOpen :t]
+ tks [']':r] t = tks r [TBrackClose :t]
tks ['{':r] t = tks r [TBraceOpen :t]
tks ['}':r] t = tks r [TBraceClose :t]
tks [',':r] t = tks r [TComma :t]
+ tks [':':r] t = tks r [TColon :t]
tks [';':r] t = tks r [TSemicolon :t]
tks ['!':r] t = tks r [TExclamation:t]
tks ['~':r] t = tks r [TTilde :t]
@@ -192,15 +198,12 @@ expression
= rightAssoc (op TDoubleBar LogOr)
$ rightAssoc (op TDoubleAmpersand LogAnd)
$ rightAssoc (op TDoubleEquals Equals)
- $ leftAssoc
- ( op TPlus Add
- <|> op TMinus Sub
- )
- $ leftAssoc
- ( op TStar Mul
- <|> op TSlash Div
- <|> op TPercent Rem
- )
+ $ rightAssoc (op TColon Cons)
+ $ leftAssoc (op TPlus Add
+ <|> op TMinus Sub)
+ $ leftAssoc (op TStar Mul
+ <|> op TSlash Div)
+ $ leftAssoc (op TPercent Rem)
$ noInfix
where
op :: Token Op2 -> Parser Token Op2
@@ -219,7 +222,7 @@ where
= liftM2 App name (item TParenOpen *> seplist TComma expression <* item TParenClose)
<|> op TTilde Neg
<|> op TExclamation Not
- <|> (simpleExpr >>= \e -> many field >>= \fs -> pure $ foldr Field e fs)
+ <|> (simpleExpr >>= \e -> foldl (flip Field) e <$> many field)
where
op :: Token Op1 -> Parser Token Expression
op token operator = liftM (BuiltinApp operator) (item token *> noInfix)
@@ -231,6 +234,8 @@ where
simpleExpr = liftM Literal literal
<|> liftM Name name
<|> (parenthised (min2seplist TComma expression) >>= \es -> pure $ Tuple (length es) es)
+ <|> flip List [] o pure <$> bracked type
+ <|> List Nothing <$> bracked (seplist TComma expression)
<|> parenthised expression
name :: Parser Token Name
@@ -249,6 +254,7 @@ type
<|> simpletype "Int" TInt
<|> simpletype "Void" TVoid
<|> (parenthised (min2seplist TComma type) >>= \ts -> pure $ TTuple (length ts) ts)
+ <|> TList <$> bracked type
<?> P_Expected "type"
where
simpletype s t = item (TName s) $> t
@@ -263,6 +269,9 @@ where
parenthised :: (Parser Token a) -> Parser Token a
parenthised p = item TParenOpen *> p <* item TParenClose
+bracked :: (Parser Token a) -> Parser Token a
+bracked p = item TBrackOpen *> p <* item TBrackClose
+
braced :: (Parser Token a) -> Parser Token a
braced p = item TBraceOpen *> p <* item TBraceClose