{-# LANGUAGE GeneralizedNewtypeDeriving #-}

-- |
-- Module      : Jikka.Python.Language.Expr
-- Description : contains data types of the standard Python. / 標準の Python のためのデータ型を含みます。
-- Copyright   : (c) Kimiyuki Onaka, 2020
-- License     : Apache License 2.0
-- Maintainer  : kimiyuki95@gmail.com
-- Stability   : experimental
-- Portability : portable
--
-- `Jikka.Python.Language.Expr` module has the basic data types for the standard Python.
-- See the Python's @ast@ module (<https://docs.python.org/ja/3/library/ast.html#abstract-grammar>) for reference.
module Jikka.Python.Language.Expr where

import Data.Int (Int8)
import Data.String (IsString)
import Jikka.Common.Location

newtype Ident = Ident String deriving (Ident -> Ident -> Bool
(Ident -> Ident -> Bool) -> (Ident -> Ident -> Bool) -> Eq Ident
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ident -> Ident -> Bool
$c/= :: Ident -> Ident -> Bool
== :: Ident -> Ident -> Bool
$c== :: Ident -> Ident -> Bool
Eq, Eq Ident
Eq Ident
-> (Ident -> Ident -> Ordering)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Bool)
-> (Ident -> Ident -> Ident)
-> (Ident -> Ident -> Ident)
-> Ord Ident
Ident -> Ident -> Bool
Ident -> Ident -> Ordering
Ident -> Ident -> Ident
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ident -> Ident -> Ident
$cmin :: Ident -> Ident -> Ident
max :: Ident -> Ident -> Ident
$cmax :: Ident -> Ident -> Ident
>= :: Ident -> Ident -> Bool
$c>= :: Ident -> Ident -> Bool
> :: Ident -> Ident -> Bool
$c> :: Ident -> Ident -> Bool
<= :: Ident -> Ident -> Bool
$c<= :: Ident -> Ident -> Bool
< :: Ident -> Ident -> Bool
$c< :: Ident -> Ident -> Bool
compare :: Ident -> Ident -> Ordering
$ccompare :: Ident -> Ident -> Ordering
$cp1Ord :: Eq Ident
Ord, Int -> Ident -> ShowS
[Ident] -> ShowS
Ident -> String
(Int -> Ident -> ShowS)
-> (Ident -> String) -> ([Ident] -> ShowS) -> Show Ident
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ident] -> ShowS
$cshowList :: [Ident] -> ShowS
show :: Ident -> String
$cshow :: Ident -> String
showsPrec :: Int -> Ident -> ShowS
$cshowsPrec :: Int -> Ident -> ShowS
Show, ReadPrec [Ident]
ReadPrec Ident
Int -> ReadS Ident
ReadS [Ident]
(Int -> ReadS Ident)
-> ReadS [Ident]
-> ReadPrec Ident
-> ReadPrec [Ident]
-> Read Ident
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Ident]
$creadListPrec :: ReadPrec [Ident]
readPrec :: ReadPrec Ident
$creadPrec :: ReadPrec Ident
readList :: ReadS [Ident]
$creadList :: ReadS [Ident]
readsPrec :: Int -> ReadS Ident
$creadsPrec :: Int -> ReadS Ident
Read, String -> Ident
(String -> Ident) -> IsString Ident
forall a. (String -> a) -> IsString a
fromString :: String -> Ident
$cfromString :: String -> Ident
IsString)

unIdent :: Ident -> String
unIdent :: Ident -> String
unIdent (Ident String
x) = String
x

type Ident' = WithLoc Ident

data Constant
  = ConstNone
  | ConstInt Integer
  | ConstBool Bool
  | ConstString String
  | ConstBytes [Int8]
  | ConstFloat Double
  | ConstImaginary Double
  deriving (Constant -> Constant -> Bool
(Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool) -> Eq Constant
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Constant -> Constant -> Bool
$c/= :: Constant -> Constant -> Bool
== :: Constant -> Constant -> Bool
$c== :: Constant -> Constant -> Bool
Eq, Eq Constant
Eq Constant
-> (Constant -> Constant -> Ordering)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Bool)
-> (Constant -> Constant -> Constant)
-> (Constant -> Constant -> Constant)
-> Ord Constant
Constant -> Constant -> Bool
Constant -> Constant -> Ordering
Constant -> Constant -> Constant
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Constant -> Constant -> Constant
$cmin :: Constant -> Constant -> Constant
max :: Constant -> Constant -> Constant
$cmax :: Constant -> Constant -> Constant
>= :: Constant -> Constant -> Bool
$c>= :: Constant -> Constant -> Bool
> :: Constant -> Constant -> Bool
$c> :: Constant -> Constant -> Bool
<= :: Constant -> Constant -> Bool
$c<= :: Constant -> Constant -> Bool
< :: Constant -> Constant -> Bool
$c< :: Constant -> Constant -> Bool
compare :: Constant -> Constant -> Ordering
$ccompare :: Constant -> Constant -> Ordering
$cp1Ord :: Eq Constant
Ord, Int -> Constant -> ShowS
[Constant] -> ShowS
Constant -> String
(Int -> Constant -> ShowS)
-> (Constant -> String) -> ([Constant] -> ShowS) -> Show Constant
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Constant] -> ShowS
$cshowList :: [Constant] -> ShowS
show :: Constant -> String
$cshow :: Constant -> String
showsPrec :: Int -> Constant -> ShowS
$cshowsPrec :: Int -> Constant -> ShowS
Show, ReadPrec [Constant]
ReadPrec Constant
Int -> ReadS Constant
ReadS [Constant]
(Int -> ReadS Constant)
-> ReadS [Constant]
-> ReadPrec Constant
-> ReadPrec [Constant]
-> Read Constant
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Constant]
$creadListPrec :: ReadPrec [Constant]
readPrec :: ReadPrec Constant
$creadPrec :: ReadPrec Constant
readList :: ReadS [Constant]
$creadList :: ReadS [Constant]
readsPrec :: Int -> ReadS Constant
$creadsPrec :: Int -> ReadS Constant
Read)

data Statement
  = FunctionDef Ident' Arguments [Statement'] [Decorator] (Maybe Type')
  | AsyncFunctionDef Ident' Arguments [Statement'] [Decorator] (Maybe Type')
  | ClassDef Ident' [Expr'] [Keyword'] [Statement'] [Decorator]
  | Return (Maybe Expr')
  | Delete [Target']
  | Assign [Target'] Expr'
  | AugAssign Target' Operator Expr'
  | AnnAssign Target' Type' (Maybe Expr')
  | -- | @For target iter body orelse@
    For Target' Expr' [Statement'] [Statement']
  | AsyncFor Target' Expr' [Statement'] [Statement']
  | -- | @While test body orelse@
    While Expr' [Statement'] [Statement']
  | If Expr' [Statement'] [Statement']
  | With [WithItem] [Statement']
  | AsyncWith [WithItem] [Statement']
  | -- | @Raise exc cause@ represents @raise exc from cause@.
    Raise (Maybe Expr') (Maybe Expr')
  | -- | @Try body handlers orelse finalbody@
    Try [Statement'] [ExceptHandler'] [Statement'] [Statement']
  | -- | @Assert test msg@
    Assert Expr' (Maybe Expr')
  | Import [Alias]
  | ImportFrom [Ident'] [Alias]
  | Global [Ident']
  | Nonlocal [Ident']
  | Expr' Expr'
  | Pass
  | Break
  | Continue
  deriving (Statement -> Statement -> Bool
(Statement -> Statement -> Bool)
-> (Statement -> Statement -> Bool) -> Eq Statement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Statement -> Statement -> Bool
$c/= :: Statement -> Statement -> Bool
== :: Statement -> Statement -> Bool
$c== :: Statement -> Statement -> Bool
Eq, Eq Statement
Eq Statement
-> (Statement -> Statement -> Ordering)
-> (Statement -> Statement -> Bool)
-> (Statement -> Statement -> Bool)
-> (Statement -> Statement -> Bool)
-> (Statement -> Statement -> Bool)
-> (Statement -> Statement -> Statement)
-> (Statement -> Statement -> Statement)
-> Ord Statement
Statement -> Statement -> Bool
Statement -> Statement -> Ordering
Statement -> Statement -> Statement
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Statement -> Statement -> Statement
$cmin :: Statement -> Statement -> Statement
max :: Statement -> Statement -> Statement
$cmax :: Statement -> Statement -> Statement
>= :: Statement -> Statement -> Bool
$c>= :: Statement -> Statement -> Bool
> :: Statement -> Statement -> Bool
$c> :: Statement -> Statement -> Bool
<= :: Statement -> Statement -> Bool
$c<= :: Statement -> Statement -> Bool
< :: Statement -> Statement -> Bool
$c< :: Statement -> Statement -> Bool
compare :: Statement -> Statement -> Ordering
$ccompare :: Statement -> Statement -> Ordering
$cp1Ord :: Eq Statement
Ord, 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, ReadPrec [Statement]
ReadPrec Statement
Int -> ReadS Statement
ReadS [Statement]
(Int -> ReadS Statement)
-> ReadS [Statement]
-> ReadPrec Statement
-> ReadPrec [Statement]
-> Read Statement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Statement]
$creadListPrec :: ReadPrec [Statement]
readPrec :: ReadPrec Statement
$creadPrec :: ReadPrec Statement
readList :: ReadS [Statement]
$creadList :: ReadS [Statement]
readsPrec :: Int -> ReadS Statement
$creadsPrec :: Int -> ReadS Statement
Read)

type Statement' = WithLoc Statement

data Expr
  = BoolOp Expr' BoolOp Expr'
  | -- | produced by the walrus operator @:=@
    NamedExpr Target' Expr'
  | BinOp Expr' Operator Expr'
  | UnaryOp UnaryOp Expr'
  | Lambda Arguments Expr'
  | -- | @IfExp test body orelse@
    IfExp Expr' Expr' Expr'
  | -- | NULL key is for @**d@.
    Dict [(Maybe Expr', Expr')]
  | Set [Expr']
  | ListComp Expr' [Comprehension]
  | SetComp Expr' [Comprehension]
  | DictComp Expr' Expr' [Comprehension]
  | GeneratorExp Expr' [Comprehension]
  | Await Expr'
  | Yield (Maybe Expr')
  | YieldFrom Expr'
  | Compare Expr' [(CmpOp, Expr')]
  | Call Expr' [Expr'] [Keyword']
  | -- | @FormattedValue value conversion format_spec@ for f-strings
    FormattedValue Expr' (Maybe Char) (Maybe Expr')
  | JoinedStr [Expr'] -- for f-strings
  | Constant Constant
  | -- | can appear in assignment context
    Attribute Expr' Ident'
  | -- | can appear in assignment context
    Subscript Expr' Expr'
  | -- | can appear in assignment context
    Starred Expr'
  | -- | can appear in assignment context
    Name Ident'
  | -- | can appear in assignment context
    List [Expr']
  | -- | can appear in assignment context
    Tuple [Expr']
  | -- | @Slice lower upper step@ can appear only in Subscript
    Slice (Maybe Expr') (Maybe Expr') (Maybe Expr')
  deriving (Expr -> Expr -> Bool
(Expr -> Expr -> Bool) -> (Expr -> Expr -> Bool) -> Eq Expr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Expr -> Expr -> Bool
$c/= :: Expr -> Expr -> Bool
== :: Expr -> Expr -> Bool
$c== :: Expr -> Expr -> Bool
Eq, Eq Expr
Eq Expr
-> (Expr -> Expr -> Ordering)
-> (Expr -> Expr -> Bool)
-> (Expr -> Expr -> Bool)
-> (Expr -> Expr -> Bool)
-> (Expr -> Expr -> Bool)
-> (Expr -> Expr -> Expr)
-> (Expr -> Expr -> Expr)
-> Ord Expr
Expr -> Expr -> Bool
Expr -> Expr -> Ordering
Expr -> Expr -> Expr
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Expr -> Expr -> Expr
$cmin :: Expr -> Expr -> Expr
max :: Expr -> Expr -> Expr
$cmax :: Expr -> Expr -> Expr
>= :: Expr -> Expr -> Bool
$c>= :: Expr -> Expr -> Bool
> :: Expr -> Expr -> Bool
$c> :: Expr -> Expr -> Bool
<= :: Expr -> Expr -> Bool
$c<= :: Expr -> Expr -> Bool
< :: Expr -> Expr -> Bool
$c< :: Expr -> Expr -> Bool
compare :: Expr -> Expr -> Ordering
$ccompare :: Expr -> Expr -> Ordering
$cp1Ord :: Eq Expr
Ord, Int -> Expr -> ShowS
[Expr] -> ShowS
Expr -> String
(Int -> Expr -> ShowS)
-> (Expr -> String) -> ([Expr] -> ShowS) -> Show Expr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Expr] -> ShowS
$cshowList :: [Expr] -> ShowS
show :: Expr -> String
$cshow :: Expr -> String
showsPrec :: Int -> Expr -> ShowS
$cshowsPrec :: Int -> Expr -> ShowS
Show, ReadPrec [Expr]
ReadPrec Expr
Int -> ReadS Expr
ReadS [Expr]
(Int -> ReadS Expr)
-> ReadS [Expr] -> ReadPrec Expr -> ReadPrec [Expr] -> Read Expr
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Expr]
$creadListPrec :: ReadPrec [Expr]
readPrec :: ReadPrec Expr
$creadPrec :: ReadPrec Expr
readList :: ReadS [Expr]
$creadList :: ReadS [Expr]
readsPrec :: Int -> ReadS Expr
$creadsPrec :: Int -> ReadS Expr
Read)

type Expr' = WithLoc Expr

type Target = Expr'

type Target' = Expr'

type Type = Expr'

type Type' = Expr'

type Decorator = Expr'

type Decorator' = Expr'

data ExprContext = Load | Store | Del
  deriving (ExprContext -> ExprContext -> Bool
(ExprContext -> ExprContext -> Bool)
-> (ExprContext -> ExprContext -> Bool) -> Eq ExprContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExprContext -> ExprContext -> Bool
$c/= :: ExprContext -> ExprContext -> Bool
== :: ExprContext -> ExprContext -> Bool
$c== :: ExprContext -> ExprContext -> Bool
Eq, Eq ExprContext
Eq ExprContext
-> (ExprContext -> ExprContext -> Ordering)
-> (ExprContext -> ExprContext -> Bool)
-> (ExprContext -> ExprContext -> Bool)
-> (ExprContext -> ExprContext -> Bool)
-> (ExprContext -> ExprContext -> Bool)
-> (ExprContext -> ExprContext -> ExprContext)
-> (ExprContext -> ExprContext -> ExprContext)
-> Ord ExprContext
ExprContext -> ExprContext -> Bool
ExprContext -> ExprContext -> Ordering
ExprContext -> ExprContext -> ExprContext
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ExprContext -> ExprContext -> ExprContext
$cmin :: ExprContext -> ExprContext -> ExprContext
max :: ExprContext -> ExprContext -> ExprContext
$cmax :: ExprContext -> ExprContext -> ExprContext
>= :: ExprContext -> ExprContext -> Bool
$c>= :: ExprContext -> ExprContext -> Bool
> :: ExprContext -> ExprContext -> Bool
$c> :: ExprContext -> ExprContext -> Bool
<= :: ExprContext -> ExprContext -> Bool
$c<= :: ExprContext -> ExprContext -> Bool
< :: ExprContext -> ExprContext -> Bool
$c< :: ExprContext -> ExprContext -> Bool
compare :: ExprContext -> ExprContext -> Ordering
$ccompare :: ExprContext -> ExprContext -> Ordering
$cp1Ord :: Eq ExprContext
Ord, Int -> ExprContext -> ShowS
[ExprContext] -> ShowS
ExprContext -> String
(Int -> ExprContext -> ShowS)
-> (ExprContext -> String)
-> ([ExprContext] -> ShowS)
-> Show ExprContext
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExprContext] -> ShowS
$cshowList :: [ExprContext] -> ShowS
show :: ExprContext -> String
$cshow :: ExprContext -> String
showsPrec :: Int -> ExprContext -> ShowS
$cshowsPrec :: Int -> ExprContext -> ShowS
Show, ReadPrec [ExprContext]
ReadPrec ExprContext
Int -> ReadS ExprContext
ReadS [ExprContext]
(Int -> ReadS ExprContext)
-> ReadS [ExprContext]
-> ReadPrec ExprContext
-> ReadPrec [ExprContext]
-> Read ExprContext
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExprContext]
$creadListPrec :: ReadPrec [ExprContext]
readPrec :: ReadPrec ExprContext
$creadPrec :: ReadPrec ExprContext
readList :: ReadS [ExprContext]
$creadList :: ReadS [ExprContext]
readsPrec :: Int -> ReadS ExprContext
$creadsPrec :: Int -> ReadS ExprContext
Read)

data BoolOp
  = And
  | Or
  | -- | our extension
    Implies
  deriving (BoolOp -> BoolOp -> Bool
(BoolOp -> BoolOp -> Bool)
-> (BoolOp -> BoolOp -> Bool) -> Eq BoolOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BoolOp -> BoolOp -> Bool
$c/= :: BoolOp -> BoolOp -> Bool
== :: BoolOp -> BoolOp -> Bool
$c== :: BoolOp -> BoolOp -> Bool
Eq, Eq BoolOp
Eq BoolOp
-> (BoolOp -> BoolOp -> Ordering)
-> (BoolOp -> BoolOp -> Bool)
-> (BoolOp -> BoolOp -> Bool)
-> (BoolOp -> BoolOp -> Bool)
-> (BoolOp -> BoolOp -> Bool)
-> (BoolOp -> BoolOp -> BoolOp)
-> (BoolOp -> BoolOp -> BoolOp)
-> Ord BoolOp
BoolOp -> BoolOp -> Bool
BoolOp -> BoolOp -> Ordering
BoolOp -> BoolOp -> BoolOp
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: BoolOp -> BoolOp -> BoolOp
$cmin :: BoolOp -> BoolOp -> BoolOp
max :: BoolOp -> BoolOp -> BoolOp
$cmax :: BoolOp -> BoolOp -> BoolOp
>= :: BoolOp -> BoolOp -> Bool
$c>= :: BoolOp -> BoolOp -> Bool
> :: BoolOp -> BoolOp -> Bool
$c> :: BoolOp -> BoolOp -> Bool
<= :: BoolOp -> BoolOp -> Bool
$c<= :: BoolOp -> BoolOp -> Bool
< :: BoolOp -> BoolOp -> Bool
$c< :: BoolOp -> BoolOp -> Bool
compare :: BoolOp -> BoolOp -> Ordering
$ccompare :: BoolOp -> BoolOp -> Ordering
$cp1Ord :: Eq BoolOp
Ord, Int -> BoolOp -> ShowS
[BoolOp] -> ShowS
BoolOp -> String
(Int -> BoolOp -> ShowS)
-> (BoolOp -> String) -> ([BoolOp] -> ShowS) -> Show BoolOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BoolOp] -> ShowS
$cshowList :: [BoolOp] -> ShowS
show :: BoolOp -> String
$cshow :: BoolOp -> String
showsPrec :: Int -> BoolOp -> ShowS
$cshowsPrec :: Int -> BoolOp -> ShowS
Show, ReadPrec [BoolOp]
ReadPrec BoolOp
Int -> ReadS BoolOp
ReadS [BoolOp]
(Int -> ReadS BoolOp)
-> ReadS [BoolOp]
-> ReadPrec BoolOp
-> ReadPrec [BoolOp]
-> Read BoolOp
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BoolOp]
$creadListPrec :: ReadPrec [BoolOp]
readPrec :: ReadPrec BoolOp
$creadPrec :: ReadPrec BoolOp
readList :: ReadS [BoolOp]
$creadList :: ReadS [BoolOp]
readsPrec :: Int -> ReadS BoolOp
$creadsPrec :: Int -> ReadS BoolOp
Read)

data Operator
  = Add
  | Sub
  | Mult
  | MatMult
  | Div
  | FloorDiv
  | FloorMod
  | -- | our extension
    CeilDiv
  | -- | our extension
    CeilMod
  | Pow
  | BitLShift
  | BitRShift
  | BitOr
  | BitXor
  | BitAnd
  | -- | our extension
    Max
  | -- | our extension
    Min
  deriving (Operator -> Operator -> Bool
(Operator -> Operator -> Bool)
-> (Operator -> Operator -> Bool) -> Eq Operator
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Operator -> Operator -> Bool
$c/= :: Operator -> Operator -> Bool
== :: Operator -> Operator -> Bool
$c== :: Operator -> Operator -> Bool
Eq, Eq Operator
Eq Operator
-> (Operator -> Operator -> Ordering)
-> (Operator -> Operator -> Bool)
-> (Operator -> Operator -> Bool)
-> (Operator -> Operator -> Bool)
-> (Operator -> Operator -> Bool)
-> (Operator -> Operator -> Operator)
-> (Operator -> Operator -> Operator)
-> Ord Operator
Operator -> Operator -> Bool
Operator -> Operator -> Ordering
Operator -> Operator -> Operator
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Operator -> Operator -> Operator
$cmin :: Operator -> Operator -> Operator
max :: Operator -> Operator -> Operator
$cmax :: Operator -> Operator -> Operator
>= :: Operator -> Operator -> Bool
$c>= :: Operator -> Operator -> Bool
> :: Operator -> Operator -> Bool
$c> :: Operator -> Operator -> Bool
<= :: Operator -> Operator -> Bool
$c<= :: Operator -> Operator -> Bool
< :: Operator -> Operator -> Bool
$c< :: Operator -> Operator -> Bool
compare :: Operator -> Operator -> Ordering
$ccompare :: Operator -> Operator -> Ordering
$cp1Ord :: Eq Operator
Ord, Int -> Operator -> ShowS
[Operator] -> ShowS
Operator -> String
(Int -> Operator -> ShowS)
-> (Operator -> String) -> ([Operator] -> ShowS) -> Show Operator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Operator] -> ShowS
$cshowList :: [Operator] -> ShowS
show :: Operator -> String
$cshow :: Operator -> String
showsPrec :: Int -> Operator -> ShowS
$cshowsPrec :: Int -> Operator -> ShowS
Show, ReadPrec [Operator]
ReadPrec Operator
Int -> ReadS Operator
ReadS [Operator]
(Int -> ReadS Operator)
-> ReadS [Operator]
-> ReadPrec Operator
-> ReadPrec [Operator]
-> Read Operator
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Operator]
$creadListPrec :: ReadPrec [Operator]
readPrec :: ReadPrec Operator
$creadPrec :: ReadPrec Operator
readList :: ReadS [Operator]
$creadList :: ReadS [Operator]
readsPrec :: Int -> ReadS Operator
$creadsPrec :: Int -> ReadS Operator
Read)

data UnaryOp
  = -- | on int
    Invert
  | -- | on bool
    Not
  | UAdd
  | USub
  deriving (UnaryOp -> UnaryOp -> Bool
(UnaryOp -> UnaryOp -> Bool)
-> (UnaryOp -> UnaryOp -> Bool) -> Eq UnaryOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UnaryOp -> UnaryOp -> Bool
$c/= :: UnaryOp -> UnaryOp -> Bool
== :: UnaryOp -> UnaryOp -> Bool
$c== :: UnaryOp -> UnaryOp -> Bool
Eq, Eq UnaryOp
Eq UnaryOp
-> (UnaryOp -> UnaryOp -> Ordering)
-> (UnaryOp -> UnaryOp -> Bool)
-> (UnaryOp -> UnaryOp -> Bool)
-> (UnaryOp -> UnaryOp -> Bool)
-> (UnaryOp -> UnaryOp -> Bool)
-> (UnaryOp -> UnaryOp -> UnaryOp)
-> (UnaryOp -> UnaryOp -> UnaryOp)
-> Ord UnaryOp
UnaryOp -> UnaryOp -> Bool
UnaryOp -> UnaryOp -> Ordering
UnaryOp -> UnaryOp -> UnaryOp
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: UnaryOp -> UnaryOp -> UnaryOp
$cmin :: UnaryOp -> UnaryOp -> UnaryOp
max :: UnaryOp -> UnaryOp -> UnaryOp
$cmax :: UnaryOp -> UnaryOp -> UnaryOp
>= :: UnaryOp -> UnaryOp -> Bool
$c>= :: UnaryOp -> UnaryOp -> Bool
> :: UnaryOp -> UnaryOp -> Bool
$c> :: UnaryOp -> UnaryOp -> Bool
<= :: UnaryOp -> UnaryOp -> Bool
$c<= :: UnaryOp -> UnaryOp -> Bool
< :: UnaryOp -> UnaryOp -> Bool
$c< :: UnaryOp -> UnaryOp -> Bool
compare :: UnaryOp -> UnaryOp -> Ordering
$ccompare :: UnaryOp -> UnaryOp -> Ordering
$cp1Ord :: Eq UnaryOp
Ord, Int -> UnaryOp -> ShowS
[UnaryOp] -> ShowS
UnaryOp -> String
(Int -> UnaryOp -> ShowS)
-> (UnaryOp -> String) -> ([UnaryOp] -> ShowS) -> Show UnaryOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UnaryOp] -> ShowS
$cshowList :: [UnaryOp] -> ShowS
show :: UnaryOp -> String
$cshow :: UnaryOp -> String
showsPrec :: Int -> UnaryOp -> ShowS
$cshowsPrec :: Int -> UnaryOp -> ShowS
Show, ReadPrec [UnaryOp]
ReadPrec UnaryOp
Int -> ReadS UnaryOp
ReadS [UnaryOp]
(Int -> ReadS UnaryOp)
-> ReadS [UnaryOp]
-> ReadPrec UnaryOp
-> ReadPrec [UnaryOp]
-> Read UnaryOp
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UnaryOp]
$creadListPrec :: ReadPrec [UnaryOp]
readPrec :: ReadPrec UnaryOp
$creadPrec :: ReadPrec UnaryOp
readList :: ReadS [UnaryOp]
$creadList :: ReadS [UnaryOp]
readsPrec :: Int -> ReadS UnaryOp
$creadsPrec :: Int -> ReadS UnaryOp
Read)

data CmpOp
  = Eq'
  | NotEq
  | Lt
  | LtE
  | Gt
  | GtE
  | Is
  | IsNot
  | In
  | NotIn
  deriving (CmpOp -> CmpOp -> Bool
(CmpOp -> CmpOp -> Bool) -> (CmpOp -> CmpOp -> Bool) -> Eq CmpOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CmpOp -> CmpOp -> Bool
$c/= :: CmpOp -> CmpOp -> Bool
== :: CmpOp -> CmpOp -> Bool
$c== :: CmpOp -> CmpOp -> Bool
Eq, Eq CmpOp
Eq CmpOp
-> (CmpOp -> CmpOp -> Ordering)
-> (CmpOp -> CmpOp -> Bool)
-> (CmpOp -> CmpOp -> Bool)
-> (CmpOp -> CmpOp -> Bool)
-> (CmpOp -> CmpOp -> Bool)
-> (CmpOp -> CmpOp -> CmpOp)
-> (CmpOp -> CmpOp -> CmpOp)
-> Ord CmpOp
CmpOp -> CmpOp -> Bool
CmpOp -> CmpOp -> Ordering
CmpOp -> CmpOp -> CmpOp
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CmpOp -> CmpOp -> CmpOp
$cmin :: CmpOp -> CmpOp -> CmpOp
max :: CmpOp -> CmpOp -> CmpOp
$cmax :: CmpOp -> CmpOp -> CmpOp
>= :: CmpOp -> CmpOp -> Bool
$c>= :: CmpOp -> CmpOp -> Bool
> :: CmpOp -> CmpOp -> Bool
$c> :: CmpOp -> CmpOp -> Bool
<= :: CmpOp -> CmpOp -> Bool
$c<= :: CmpOp -> CmpOp -> Bool
< :: CmpOp -> CmpOp -> Bool
$c< :: CmpOp -> CmpOp -> Bool
compare :: CmpOp -> CmpOp -> Ordering
$ccompare :: CmpOp -> CmpOp -> Ordering
$cp1Ord :: Eq CmpOp
Ord, Int -> CmpOp -> ShowS
[CmpOp] -> ShowS
CmpOp -> String
(Int -> CmpOp -> ShowS)
-> (CmpOp -> String) -> ([CmpOp] -> ShowS) -> Show CmpOp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CmpOp] -> ShowS
$cshowList :: [CmpOp] -> ShowS
show :: CmpOp -> String
$cshow :: CmpOp -> String
showsPrec :: Int -> CmpOp -> ShowS
$cshowsPrec :: Int -> CmpOp -> ShowS
Show, ReadPrec [CmpOp]
ReadPrec CmpOp
Int -> ReadS CmpOp
ReadS [CmpOp]
(Int -> ReadS CmpOp)
-> ReadS [CmpOp]
-> ReadPrec CmpOp
-> ReadPrec [CmpOp]
-> Read CmpOp
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CmpOp]
$creadListPrec :: ReadPrec [CmpOp]
readPrec :: ReadPrec CmpOp
$creadPrec :: ReadPrec CmpOp
readList :: ReadS [CmpOp]
$creadList :: ReadS [CmpOp]
readsPrec :: Int -> ReadS CmpOp
$creadsPrec :: Int -> ReadS CmpOp
Read)

-- | @Comprehension target iter ifs is_async@
data Comprehension = Comprehension
  { Comprehension -> Target'
compTarget :: Target',
    Comprehension -> Target'
compIter :: Expr',
    Comprehension -> Maybe Target'
compIfs :: Maybe Expr'
  }
  deriving (Comprehension -> Comprehension -> Bool
(Comprehension -> Comprehension -> Bool)
-> (Comprehension -> Comprehension -> Bool) -> Eq Comprehension
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Comprehension -> Comprehension -> Bool
$c/= :: Comprehension -> Comprehension -> Bool
== :: Comprehension -> Comprehension -> Bool
$c== :: Comprehension -> Comprehension -> Bool
Eq, Eq Comprehension
Eq Comprehension
-> (Comprehension -> Comprehension -> Ordering)
-> (Comprehension -> Comprehension -> Bool)
-> (Comprehension -> Comprehension -> Bool)
-> (Comprehension -> Comprehension -> Bool)
-> (Comprehension -> Comprehension -> Bool)
-> (Comprehension -> Comprehension -> Comprehension)
-> (Comprehension -> Comprehension -> Comprehension)
-> Ord Comprehension
Comprehension -> Comprehension -> Bool
Comprehension -> Comprehension -> Ordering
Comprehension -> Comprehension -> Comprehension
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Comprehension -> Comprehension -> Comprehension
$cmin :: Comprehension -> Comprehension -> Comprehension
max :: Comprehension -> Comprehension -> Comprehension
$cmax :: Comprehension -> Comprehension -> Comprehension
>= :: Comprehension -> Comprehension -> Bool
$c>= :: Comprehension -> Comprehension -> Bool
> :: Comprehension -> Comprehension -> Bool
$c> :: Comprehension -> Comprehension -> Bool
<= :: Comprehension -> Comprehension -> Bool
$c<= :: Comprehension -> Comprehension -> Bool
< :: Comprehension -> Comprehension -> Bool
$c< :: Comprehension -> Comprehension -> Bool
compare :: Comprehension -> Comprehension -> Ordering
$ccompare :: Comprehension -> Comprehension -> Ordering
$cp1Ord :: Eq Comprehension
Ord, Int -> Comprehension -> ShowS
[Comprehension] -> ShowS
Comprehension -> String
(Int -> Comprehension -> ShowS)
-> (Comprehension -> String)
-> ([Comprehension] -> ShowS)
-> Show Comprehension
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Comprehension] -> ShowS
$cshowList :: [Comprehension] -> ShowS
show :: Comprehension -> String
$cshow :: Comprehension -> String
showsPrec :: Int -> Comprehension -> ShowS
$cshowsPrec :: Int -> Comprehension -> ShowS
Show, ReadPrec [Comprehension]
ReadPrec Comprehension
Int -> ReadS Comprehension
ReadS [Comprehension]
(Int -> ReadS Comprehension)
-> ReadS [Comprehension]
-> ReadPrec Comprehension
-> ReadPrec [Comprehension]
-> Read Comprehension
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Comprehension]
$creadListPrec :: ReadPrec [Comprehension]
readPrec :: ReadPrec Comprehension
$creadPrec :: ReadPrec Comprehension
readList :: ReadS [Comprehension]
$creadList :: ReadS [Comprehension]
readsPrec :: Int -> ReadS Comprehension
$creadsPrec :: Int -> ReadS Comprehension
Read)

data ExceptHandler = ExceptHandler
  { ExceptHandler -> Maybe Target'
exchType :: Maybe Type',
    ExceptHandler -> Maybe Ident'
exchName :: Maybe Ident',
    ExceptHandler -> [Statement']
exchBody :: [Statement']
  }
  deriving (ExceptHandler -> ExceptHandler -> Bool
(ExceptHandler -> ExceptHandler -> Bool)
-> (ExceptHandler -> ExceptHandler -> Bool) -> Eq ExceptHandler
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExceptHandler -> ExceptHandler -> Bool
$c/= :: ExceptHandler -> ExceptHandler -> Bool
== :: ExceptHandler -> ExceptHandler -> Bool
$c== :: ExceptHandler -> ExceptHandler -> Bool
Eq, Eq ExceptHandler
Eq ExceptHandler
-> (ExceptHandler -> ExceptHandler -> Ordering)
-> (ExceptHandler -> ExceptHandler -> Bool)
-> (ExceptHandler -> ExceptHandler -> Bool)
-> (ExceptHandler -> ExceptHandler -> Bool)
-> (ExceptHandler -> ExceptHandler -> Bool)
-> (ExceptHandler -> ExceptHandler -> ExceptHandler)
-> (ExceptHandler -> ExceptHandler -> ExceptHandler)
-> Ord ExceptHandler
ExceptHandler -> ExceptHandler -> Bool
ExceptHandler -> ExceptHandler -> Ordering
ExceptHandler -> ExceptHandler -> ExceptHandler
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ExceptHandler -> ExceptHandler -> ExceptHandler
$cmin :: ExceptHandler -> ExceptHandler -> ExceptHandler
max :: ExceptHandler -> ExceptHandler -> ExceptHandler
$cmax :: ExceptHandler -> ExceptHandler -> ExceptHandler
>= :: ExceptHandler -> ExceptHandler -> Bool
$c>= :: ExceptHandler -> ExceptHandler -> Bool
> :: ExceptHandler -> ExceptHandler -> Bool
$c> :: ExceptHandler -> ExceptHandler -> Bool
<= :: ExceptHandler -> ExceptHandler -> Bool
$c<= :: ExceptHandler -> ExceptHandler -> Bool
< :: ExceptHandler -> ExceptHandler -> Bool
$c< :: ExceptHandler -> ExceptHandler -> Bool
compare :: ExceptHandler -> ExceptHandler -> Ordering
$ccompare :: ExceptHandler -> ExceptHandler -> Ordering
$cp1Ord :: Eq ExceptHandler
Ord, Int -> ExceptHandler -> ShowS
[ExceptHandler] -> ShowS
ExceptHandler -> String
(Int -> ExceptHandler -> ShowS)
-> (ExceptHandler -> String)
-> ([ExceptHandler] -> ShowS)
-> Show ExceptHandler
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExceptHandler] -> ShowS
$cshowList :: [ExceptHandler] -> ShowS
show :: ExceptHandler -> String
$cshow :: ExceptHandler -> String
showsPrec :: Int -> ExceptHandler -> ShowS
$cshowsPrec :: Int -> ExceptHandler -> ShowS
Show, ReadPrec [ExceptHandler]
ReadPrec ExceptHandler
Int -> ReadS ExceptHandler
ReadS [ExceptHandler]
(Int -> ReadS ExceptHandler)
-> ReadS [ExceptHandler]
-> ReadPrec ExceptHandler
-> ReadPrec [ExceptHandler]
-> Read ExceptHandler
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExceptHandler]
$creadListPrec :: ReadPrec [ExceptHandler]
readPrec :: ReadPrec ExceptHandler
$creadPrec :: ReadPrec ExceptHandler
readList :: ReadS [ExceptHandler]
$creadList :: ReadS [ExceptHandler]
readsPrec :: Int -> ReadS ExceptHandler
$creadsPrec :: Int -> ReadS ExceptHandler
Read)

type ExceptHandler' = WithLoc ExceptHandler

data Arguments = Arguments
  { Arguments -> [Arg]
argsPosonlyargs :: [Arg],
    Arguments -> [Arg]
argsArgs :: [Arg],
    Arguments -> Maybe Arg
argsVarargs :: Maybe Arg,
    Arguments -> [Arg]
argsKwonlyargs :: [Arg],
    Arguments -> [Target']
argsKwDefaults :: [Expr'],
    Arguments -> Maybe Arg
argsKwarg :: Maybe Arg,
    Arguments -> [Target']
argsDefaults :: [Expr']
  }
  deriving (Arguments -> Arguments -> Bool
(Arguments -> Arguments -> Bool)
-> (Arguments -> Arguments -> Bool) -> Eq Arguments
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Arguments -> Arguments -> Bool
$c/= :: Arguments -> Arguments -> Bool
== :: Arguments -> Arguments -> Bool
$c== :: Arguments -> Arguments -> Bool
Eq, Eq Arguments
Eq Arguments
-> (Arguments -> Arguments -> Ordering)
-> (Arguments -> Arguments -> Bool)
-> (Arguments -> Arguments -> Bool)
-> (Arguments -> Arguments -> Bool)
-> (Arguments -> Arguments -> Bool)
-> (Arguments -> Arguments -> Arguments)
-> (Arguments -> Arguments -> Arguments)
-> Ord Arguments
Arguments -> Arguments -> Bool
Arguments -> Arguments -> Ordering
Arguments -> Arguments -> Arguments
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Arguments -> Arguments -> Arguments
$cmin :: Arguments -> Arguments -> Arguments
max :: Arguments -> Arguments -> Arguments
$cmax :: Arguments -> Arguments -> Arguments
>= :: Arguments -> Arguments -> Bool
$c>= :: Arguments -> Arguments -> Bool
> :: Arguments -> Arguments -> Bool
$c> :: Arguments -> Arguments -> Bool
<= :: Arguments -> Arguments -> Bool
$c<= :: Arguments -> Arguments -> Bool
< :: Arguments -> Arguments -> Bool
$c< :: Arguments -> Arguments -> Bool
compare :: Arguments -> Arguments -> Ordering
$ccompare :: Arguments -> Arguments -> Ordering
$cp1Ord :: Eq Arguments
Ord, Int -> Arguments -> ShowS
[Arguments] -> ShowS
Arguments -> String
(Int -> Arguments -> ShowS)
-> (Arguments -> String)
-> ([Arguments] -> ShowS)
-> Show Arguments
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Arguments] -> ShowS
$cshowList :: [Arguments] -> ShowS
show :: Arguments -> String
$cshow :: Arguments -> String
showsPrec :: Int -> Arguments -> ShowS
$cshowsPrec :: Int -> Arguments -> ShowS
Show, ReadPrec [Arguments]
ReadPrec Arguments
Int -> ReadS Arguments
ReadS [Arguments]
(Int -> ReadS Arguments)
-> ReadS [Arguments]
-> ReadPrec Arguments
-> ReadPrec [Arguments]
-> Read Arguments
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Arguments]
$creadListPrec :: ReadPrec [Arguments]
readPrec :: ReadPrec Arguments
$creadPrec :: ReadPrec Arguments
readList :: ReadS [Arguments]
$creadList :: ReadS [Arguments]
readsPrec :: Int -> ReadS Arguments
$creadsPrec :: Int -> ReadS Arguments
Read)

emptyArguments :: Arguments
emptyArguments :: Arguments
emptyArguments =
  Arguments :: [Arg]
-> [Arg]
-> Maybe Arg
-> [Arg]
-> [Target']
-> Maybe Arg
-> [Target']
-> Arguments
Arguments
    { argsPosonlyargs :: [Arg]
argsPosonlyargs = [],
      argsArgs :: [Arg]
argsArgs = [],
      argsVarargs :: Maybe Arg
argsVarargs = Maybe Arg
forall a. Maybe a
Nothing,
      argsKwonlyargs :: [Arg]
argsKwonlyargs = [],
      argsKwDefaults :: [Target']
argsKwDefaults = [],
      argsKwarg :: Maybe Arg
argsKwarg = Maybe Arg
forall a. Maybe a
Nothing,
      argsDefaults :: [Target']
argsDefaults = []
    }

type Arg = (Ident', Maybe Type')

-- | NULL identifier is for @**kwargs@.
type Keyword = (Maybe Ident', Expr')

type Keyword' = WithLoc Keyword

-- | @(name, asname)@. `Alias` is used for `Import` and `ImportFrom`.
type Alias = (Ident', Maybe Ident')

-- | @(context_expr, optional_vars)@
type WithItem = (Expr', Maybe Expr')

type Program = [Statement']