module Language.JS.Types where

data ObjectProperty = OPI Expression
                    | OPKV Expression Expression
                    | OP Expression
                    | OPM Expression
                    deriving (Int -> ObjectProperty -> ShowS
[ObjectProperty] -> ShowS
ObjectProperty -> String
(Int -> ObjectProperty -> ShowS)
-> (ObjectProperty -> String)
-> ([ObjectProperty] -> ShowS)
-> Show ObjectProperty
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ObjectProperty] -> ShowS
$cshowList :: [ObjectProperty] -> ShowS
show :: ObjectProperty -> String
$cshow :: ObjectProperty -> String
showsPrec :: Int -> ObjectProperty -> ShowS
$cshowsPrec :: Int -> ObjectProperty -> ShowS
Show)

type IsPrefix = Bool

data SwitchCase = Case Expression | DefaultCase
                deriving (Int -> SwitchCase -> ShowS
[SwitchCase] -> ShowS
SwitchCase -> String
(Int -> SwitchCase -> ShowS)
-> (SwitchCase -> String)
-> ([SwitchCase] -> ShowS)
-> Show SwitchCase
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SwitchCase] -> ShowS
$cshowList :: [SwitchCase] -> ShowS
show :: SwitchCase -> String
$cshow :: SwitchCase -> String
showsPrec :: Int -> SwitchCase -> ShowS
$cshowsPrec :: Int -> SwitchCase -> ShowS
Show)

type ExpressionOpt = Maybe Expression
type StatementOpt = Maybe Statement

data ForStyle = ForIn  BindExpression Expression
              | ForInV String BindExpression Expression
              | ForOf  BindExpression Expression
              | ForOfV String BindExpression Expression
              | ForRegular (Maybe BindExpression) ExpressionOpt ExpressionOpt
              deriving (Int -> ForStyle -> ShowS
[ForStyle] -> ShowS
ForStyle -> String
(Int -> ForStyle -> ShowS)
-> (ForStyle -> String) -> ([ForStyle] -> ShowS) -> Show ForStyle
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ForStyle] -> ShowS
$cshowList :: [ForStyle] -> ShowS
show :: ForStyle -> String
$cshow :: ForStyle -> String
showsPrec :: Int -> ForStyle -> ShowS
$cshowsPrec :: Int -> ForStyle -> ShowS
Show)

-- | import and export binds
-- * as identifier
-- A, ...
-- {x,...}
data ImportClause = Namespace Expression
                  | DefaultName Expression
                  | BindNames [Expression]
                  deriving (Int -> ImportClause -> ShowS
[ImportClause] -> ShowS
ImportClause -> String
(Int -> ImportClause -> ShowS)
-> (ImportClause -> String)
-> ([ImportClause] -> ShowS)
-> Show ImportClause
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportClause] -> ShowS
$cshowList :: [ImportClause] -> ShowS
show :: ImportClause -> String
$cshow :: ImportClause -> String
showsPrec :: Int -> ImportClause -> ShowS
$cshowsPrec :: Int -> ImportClause -> ShowS
Show)

-- possible binds
-- <<expty>>
-- a
-- a=1
-- {a}
-- {a}={a:1}
-- ...a
-- ...{a}
-- ...[a]
data BindExpression = BindVar Expression (Maybe Expression)
                    | BindPattern Expression (Maybe Expression)
                    | BindRest Expression
                    deriving (Int -> BindExpression -> ShowS
[BindExpression] -> ShowS
BindExpression -> String
(Int -> BindExpression -> ShowS)
-> (BindExpression -> String)
-> ([BindExpression] -> ShowS)
-> Show BindExpression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindExpression] -> ShowS
$cshowList :: [BindExpression] -> ShowS
show :: BindExpression -> String
$cshow :: BindExpression -> String
showsPrec :: Int -> BindExpression -> ShowS
$cshowsPrec :: Int -> BindExpression -> ShowS
Show)

data TemplateString = TString String
                    | TExpression Expression
                    deriving (Int -> TemplateString -> ShowS
[TemplateString] -> ShowS
TemplateString -> String
(Int -> TemplateString -> ShowS)
-> (TemplateString -> String)
-> ([TemplateString] -> ShowS)
-> Show TemplateString
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemplateString] -> ShowS
$cshowList :: [TemplateString] -> ShowS
show :: TemplateString -> String
$cshow :: TemplateString -> String
showsPrec :: Int -> TemplateString -> ShowS
$cshowsPrec :: Int -> TemplateString -> ShowS
Show)

data Expression = -- literals
  LThis
  | LNull
  | LI String
  | LN String
  | LS String
  | LTS [TemplateString] -- LS + Expression
  | LB Bool
  | RegExp String String
  | UnaryUpdate String IsPrefix Expression
  | Unary String Expression
  | Spread Expression
  | Elision -- single comma
  | LA [Expression]
  | LO [ObjectProperty]
  | LP Expression
  | Condition Expression Expression Expression -- exp ? exp : exp
  | Assignment String Expression Expression
  | Operation String Expression Expression
    -- function expression
  | Function ExpressionOpt [BindExpression] Statement
  | Arrow (Either BindExpression [BindExpression]) Statement -- arrow function
    -- class expression
  | Class ExpressionOpt ExpressionOpt Statement
  | ClassProperty Expression Expression
  | PropertyMethod Expression [BindExpression] Statement
  | ClassStatic Expression
  | ClassGetMethod Expression
  | ClassSetMethod Expression
    -- async expression
  | Async Expression
    -- member expression
  | Dot Expression Expression
  | Acc Expression Expression
  | FCall Expression [Expression]
  | New Expression -- new + expression
    -- comma / sequence
  | Comma Expression Expression
    -- empty expression ;
  | Empty
  | Comment String
  | MultilineComment String
  deriving (Int -> Expression -> ShowS
[Expression] -> ShowS
Expression -> String
(Int -> Expression -> ShowS)
-> (Expression -> String)
-> ([Expression] -> ShowS)
-> Show Expression
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Expression] -> ShowS
$cshowList :: [Expression] -> ShowS
show :: Expression -> String
$cshow :: Expression -> String
showsPrec :: Int -> Expression -> ShowS
$cshowsPrec :: Int -> Expression -> ShowS
Show)

data Statement = SExp Expression
               -- module statements
               | SImportFile Expression
               | SImport (Either ImportClause [ImportClause]) Expression
               | SRExport Expression Expression
               | SExport Statement
               | SExportDefault Expression
               -- function and class declaration
               | SC String ExpressionOpt Statement
               | SF String [BindExpression] Statement
               -- variable statements
               | SVariable String [BindExpression]
               -- iteration statements
               | SWhile [Expression] Statement
               | SDoWhile Statement [Expression]
               | SFor ForStyle Statement
               | SLabel Expression Statement -- identifier: statement
               | SDebugger
               -- control statements
               | SContinue ExpressionOpt
               | SBreak ExpressionOpt
               -- general block statement
               | SBlock [Statement]
               | SIf Expression Statement StatementOpt
               -- switch statement
               | SSwitch Expression [Statement]
               | SCase [SwitchCase] [Statement] -- cases + statementslist
               -- try/catch/finally/throw statement
               | SThrow Expression
               | STry Statement Statement StatementOpt
               | SCatch ExpressionOpt Statement
               | SFinally Statement
               -- return statement
               | SReturn Expression
               -- with statement
               | SWith Expression Statement
               deriving (Int -> Statement -> ShowS
[Statement] -> ShowS
Statement -> String
(Int -> Statement -> ShowS)
-> (Statement -> String)
-> ([Statement] -> ShowS)
-> Show Statement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Statement] -> ShowS
$cshowList :: [Statement] -> ShowS
show :: Statement -> String
$cshow :: Statement -> String
showsPrec :: Int -> Statement -> ShowS
$cshowsPrec :: Int -> Statement -> ShowS
Show)