From 0b3469b49afc9b54e8f861d071082063869b6bba Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 26 Dec 2023 13:15:56 -0800 Subject: [PATCH] Add string and float literals to the object language Signed-off-by: Danila Fedorin --- src/Bergamot/ObjectLanguage.elm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Bergamot/ObjectLanguage.elm b/src/Bergamot/ObjectLanguage.elm index e17b060..624a508 100644 --- a/src/Bergamot/ObjectLanguage.elm +++ b/src/Bergamot/ObjectLanguage.elm @@ -1,6 +1,7 @@ module Bergamot.ObjectLanguage exposing (..) import Bergamot.Syntax as Syntax exposing (Metavariable) +import Bergamot.Parser exposing (strLit) import Parser exposing (Parser, Trailing(..), (|.), (|=)) import Set @@ -13,6 +14,7 @@ type Type type Expr = IntLit Int + | FloatLit Float | StrLit String | Plus Expr Expr | Pair Expr Expr @@ -99,7 +101,15 @@ exprApps = exprBasic : Parser Expr exprBasic = Parser.lazy <| \() -> Parser.oneOf - [ Parser.backtrackable (Parser.succeed IntLit |= Parser.int) + [ Parser.backtrackable <| + Parser.number + { int = Just IntLit + , hex = Nothing + , octal = Nothing + , binary = Nothing + , float = Just FloatLit + } + , Parser.backtrackable (Parser.succeed StrLit |= strLit) , Parser.backtrackable <| Parser.map (\(a, b) -> Pair a b) <| pair expr , Parser.succeed Fst |. Parser.keyword "fst" @@ -137,6 +147,7 @@ exprToTerm : Expr -> Syntax.Term Metavariable exprToTerm e = case e of IntLit i -> Syntax.Call "intlit" [Syntax.IntLit i] + FloatLit f -> Syntax.Call "floatlit" [Syntax.FloatLit f] StrLit s -> Syntax.Call "strlit" [Syntax.StringLit s] Plus e1 e2 -> Syntax.Call "plus" [exprToTerm e1, exprToTerm e2] Pair e1 e2 -> Syntax.Call "pair" [exprToTerm e1, exprToTerm e2]