Make int literals parseable

This commit is contained in:
Danila Fedorin 2023-03-12 00:40:01 -08:00
parent ac37e82979
commit 0c1deb4c8f
2 changed files with 7 additions and 2 deletions

View File

@ -17,6 +17,7 @@ to generate this file without the comments in this block.
, "control"
, "either"
, "foldable-traversable"
, "integers"
, "lazy"
, "lists"
, "logict"

View File

@ -14,9 +14,10 @@ import Parsing.String.Basic (digit, letter, space)
import Parsing.Combinators (many, many1, sepBy, (<|>))
import Data.Array (fromFoldable)
import Data.Either (hush)
import Data.Int (fromString)
import Data.List (List(..))
import Data.List.NonEmpty (NonEmptyList)
import Data.Maybe (Maybe)
import Data.Maybe (Maybe, fromMaybe)
import Data.String (codePointFromChar, fromCodePointArray)
charsToString :: NonEmptyList Char -> String
@ -29,7 +30,10 @@ identifier :: Parser String String
identifier = (charsToString <$> many1 (letter <|> digit <|> char '_' <|> char '\\')) <* whitespace
expr :: Parser String (Expr Metavariable)
expr = (defer $ \_ -> atom) <|> (defer $ \_ -> metavariable)
expr = (defer $ \_ -> intLit) <|> (defer $ \_ -> atom) <|> (defer $ \_ -> metavariable)
intLit :: Parser String (Expr Metavariable)
intLit = (IntLit <<< fromMaybe 0 <<< fromString <<< charsToString) <$> many1 digit
atom :: Parser String (Expr Metavariable)
atom = lift2 Atom (identifier <* whitespace) (args <|> pure Nil)