{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
module Language.Lua.Syntax
( module Language.Lua.Syntax
, NumberType(..)
) where
import Control.DeepSeq (NFData)
import Data.Data (Data, Typeable)
import Data.Text (Text)
import GHC.Generics (Generic)
import Prelude hiding (EQ, GT, LT)
import Language.Lua.Utils(NumberType(..))
newtype Name = Name Text
deriving (Show, Eq, Data, Typeable, Generic)
data Stat
= Assign [Var] [Exp]
| FunCall FunCall
| Label Name
| Break
| Goto Name
| Do Block
| While Exp Block
| Repeat Block Exp
| If [(Exp, Block)] (Maybe Block)
| ForRange Name Exp Exp (Maybe Exp) Block
| ForIn [Name] [Exp] Block
| FunAssign FunName FunBody
| LocalFunAssign Name FunBody
| LocalAssign [Name] (Maybe [Exp])
| EmptyStat
deriving (Show, Eq, Data, Typeable, Generic)
data Exp
= Nil
| Bool Bool
| Number NumberType Text
| String Text
| Vararg
| EFunDef FunBody
| PrefixExp PrefixExp
| TableConst [TableField]
| Binop Binop Exp Exp
| Unop Unop Exp
deriving (Show, Eq, Data, Typeable, Generic)
data Var
= VarName Name
| Select PrefixExp Exp
| SelectName PrefixExp Name
deriving (Show, Eq, Data, Typeable, Generic)
data Binop = Add | Sub | Mul | Div | Exp | Mod | Concat
| LT | LTE | GT | GTE | EQ | NEQ | And | Or
| IDiv | ShiftL | ShiftR | BAnd | BOr | BXor
deriving (Show, Eq, Data, Typeable, Generic)
data Unop = Neg | Not | Len | Complement
deriving (Show, Eq, Data, Typeable, Generic)
data PrefixExp
= PEVar Var
| PEFunCall FunCall
| Paren Exp
deriving (Show, Eq, Data, Typeable, Generic)
data TableField
= ExpField Exp Exp
| NamedField Name Exp
| Field Exp
deriving (Show, Eq, Data, Typeable, Generic)
data Block = Block [Stat] (Maybe [Exp])
deriving (Show, Eq, Data, Typeable, Generic)
data FunName = FunName Name [Name] (Maybe Name)
deriving (Show, Eq, Data, Typeable, Generic)
data FunBody = FunBody [Name] Bool Block
deriving (Show, Eq, Data, Typeable, Generic)
data FunCall
= NormalFunCall PrefixExp FunArg
| MethodCall PrefixExp Name FunArg
deriving (Show, Eq, Data, Typeable, Generic)
data FunArg
= Args [Exp]
| TableArg [TableField]
| StringArg Text
deriving (Show, Eq, Data, Typeable, Generic)
instance NFData Name
instance NFData Stat
instance NFData Exp
instance NFData Var
instance NFData Binop
instance NFData Unop
instance NFData PrefixExp
instance NFData TableField
instance NFData Block
instance NFData FunName
instance NFData FunBody
instance NFData FunCall
instance NFData FunArg