Skip to content

Commit

Permalink
Use generic Literal in the AST
Browse files Browse the repository at this point in the history
  • Loading branch information
garyb committed Mar 8, 2016
1 parent c4ae1cf commit e5655c8
Show file tree
Hide file tree
Showing 19 changed files with 374 additions and 367 deletions.
2 changes: 1 addition & 1 deletion psci/PSCi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ handleDecls :: [P.Declaration] -> PSCI ()
handleDecls ds = do
st <- PSCI $ lift get
let st' = updateLets ds st
let m = createTemporaryModule False st' (P.ObjectLiteral [])
let m = createTemporaryModule False st' (P.Literal (P.ObjectLiteral []))
e <- psciIO . runMake $ make st' [m]
case e of
Left err -> PSCI $ printErrors err
Expand Down
2 changes: 1 addition & 1 deletion purescript.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ library
Language.PureScript.AST.Binders
Language.PureScript.AST.Declarations
Language.PureScript.AST.Operators
Language.PureScript.AST.Literals
Language.PureScript.AST.SourcePos
Language.PureScript.AST.Traversals
Language.PureScript.AST.Exported
Expand All @@ -119,7 +120,6 @@ library
Language.PureScript.CoreFn.Binders
Language.PureScript.CoreFn.Desugar
Language.PureScript.CoreFn.Expr
Language.PureScript.CoreFn.Literals
Language.PureScript.CoreFn.Meta
Language.PureScript.CoreFn.Module
Language.PureScript.CoreFn.Traversals
Expand Down
18 changes: 4 additions & 14 deletions src/Language/PureScript/AST.hs
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
-----------------------------------------------------------------------------
-- |
-- The initial PureScript AST
--
-- Module : Language.PureScript.AST
-- Copyright : (c) 2013-14 Phil Freeman, (c) 2014 Gary Burgess, and other contributors
-- License : MIT
--
-- Maintainer : Phil Freeman <paf31@cantab.net>
-- Stability : experimental
-- Portability :
--
-- | The initial PureScript AST
--
-----------------------------------------------------------------------------

module Language.PureScript.AST (
module AST
) where

import Language.PureScript.AST.Binders as AST
import Language.PureScript.AST.Declarations as AST
import Language.PureScript.AST.Exported as AST
import Language.PureScript.AST.Literals as AST
import Language.PureScript.AST.Operators as AST
import Language.PureScript.AST.SourcePos as AST
import Language.PureScript.AST.Traversals as AST
import Language.PureScript.AST.Exported as AST
31 changes: 7 additions & 24 deletions src/Language/PureScript/AST/Binders.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Language.PureScript.AST.Binders where

import Language.PureScript.AST.SourcePos
import Language.PureScript.AST.Literals
import Language.PureScript.Names
import Language.PureScript.Comments
import Language.PureScript.Types
Expand All @@ -17,21 +18,9 @@ data Binder
--
= NullBinder
-- |
-- A binder which matches a boolean literal
-- A binder which matches a literal
--
| BooleanBinder Bool
-- |
-- A binder which matches a string literal
--
| StringBinder String
-- |
-- A binder which matches a character literal
--
| CharBinder Char
-- |
-- A binder which matches a numeric literal
--
| NumberBinder (Either Integer Double)
| LiteralBinder (Literal Binder)
-- |
-- A binder which binds an identifier
--
Expand Down Expand Up @@ -59,14 +48,6 @@ data Binder
--
| ParensInBinder Binder
-- |
-- A binder which matches a record and binds its properties
--
| ObjectBinder [(String, Binder)]
-- |
-- A binder which matches an array and binds its elements
--
| ArrayBinder [Binder]
-- |
-- A binder which binds its input to an identifier
--
| NamedBinder Ident Binder
Expand All @@ -86,13 +67,15 @@ data Binder
binderNames :: Binder -> [Ident]
binderNames = go []
where
go ns (LiteralBinder b) = lit ns b
go ns (VarBinder name) = name : ns
go ns (ConstructorBinder _ bs) = foldl go ns bs
go ns (BinaryNoParensBinder b1 b2 b3) = foldl go ns [b1, b2, b3]
go ns (ParensInBinder b) = go ns b
go ns (ObjectBinder bs) = foldl go ns (map snd bs)
go ns (ArrayBinder bs) = foldl go ns bs
go ns (NamedBinder name b) = go (name : ns) b
go ns (PositionedBinder _ _ b) = go ns b
go ns (TypedBinder _ b) = go ns b
go ns _ = ns
lit ns (ObjectLiteral bs) = foldl go ns (map snd bs)
lit ns (ArrayLiteral bs) = foldl go ns bs
lit ns _ = ns
25 changes: 3 additions & 22 deletions src/Language/PureScript/AST/Declarations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import qualified Data.Map as M
import Control.Monad.Identity

import Language.PureScript.AST.Binders
import Language.PureScript.AST.Literals
import Language.PureScript.AST.Operators
import Language.PureScript.AST.SourcePos
import Language.PureScript.Types
Expand Down Expand Up @@ -309,21 +310,9 @@ type Guard = Expr
--
data Expr
-- |
-- A numeric literal
-- A literal value
--
= NumericLiteral (Either Integer Double)
-- |
-- A string literal
--
| StringLiteral String
-- |
-- A character literal
--
| CharLiteral Char
-- |
-- A boolean literal
--
| BooleanLiteral Bool
= Literal (Literal Expr)
-- |
-- A prefix -, will be desugared
--
Expand All @@ -347,14 +336,6 @@ data Expr
--
| OperatorSection Expr (Either Expr Expr)
-- |
-- An array literal
--
| ArrayLiteral [Expr]
-- |
-- An object literal
--
| ObjectLiteral [(String, Expr)]
-- |
-- An object property getter (e.g. `_.x`). This will be removed during
-- desugaring and expanded into a lambda that reads a property from an object.
--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-- |
-- The core functional representation for literal values.
--
module Language.PureScript.CoreFn.Literals where
module Language.PureScript.AST.Literals where

-- |
-- Data type for literal values. Parameterised so it can be used for Exprs and
Expand Down Expand Up @@ -34,4 +34,4 @@ data Literal a
-- An object literal
--
| ObjectLiteral [(String, a)]
deriving (Show, Read, Functor)
deriving (Eq, Ord, Show, Read, Functor)

0 comments on commit e5655c8

Please sign in to comment.