module Language.Lua.Syntax where
import Control.DeepSeq (NFData)
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)
import Prelude hiding (EQ, GT, LT)
type Name = String
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 String
| String String
| 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
deriving (Show, Eq, Data, Typeable, Generic)
data Unop = Neg | Not | Len
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 String
deriving (Show, Eq, Data, Typeable, Generic)
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