hpython-0.3: Python language tools

Copyright(C) CSIRO 2017-2019
LicenseBSD3
MaintainerIsaac Elliott <isaace71295@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Language.Python.Syntax.Operator.Binary

Description

This module contains a datatype for binary operators and a precedence table with associated operations. This presentation of operators is simpler and more flexible than hard-coding them into the syntax tree.

Synopsis

Documentation

data BinOp a Source #

A Python binary operator, such as +, along with its trailing Whitespace

Constructors

Is (Ann a) [Whitespace]
a is b
IsNot (Ann a) [Whitespace] [Whitespace]
a is not b
In (Ann a) [Whitespace]
a in b
NotIn (Ann a) [Whitespace] [Whitespace]
a not in b
Minus (Ann a) [Whitespace]
a - b
Exp (Ann a) [Whitespace]
a ** b
BoolAnd (Ann a) [Whitespace]
a and b
BoolOr (Ann a) [Whitespace]
a or b
Eq (Ann a) [Whitespace]
a == b
Lt (Ann a) [Whitespace]
a < b
LtEq (Ann a) [Whitespace]
a <= b
Gt (Ann a) [Whitespace]
a > b
GtEq (Ann a) [Whitespace]
a >= b
NotEq (Ann a) [Whitespace]
a != b
Multiply (Ann a) [Whitespace]
a * b
Divide (Ann a) [Whitespace]
a / b
FloorDivide (Ann a) [Whitespace]
a // b
Percent (Ann a) [Whitespace]
a % b
Plus (Ann a) [Whitespace]
a + b
BitOr (Ann a) [Whitespace]
a | b
BitXor (Ann a) [Whitespace]
a ^ b
BitAnd (Ann a) [Whitespace]
a & b
ShiftLeft (Ann a) [Whitespace]
a << b
ShiftRight (Ann a) [Whitespace]
a >> b
At (Ann a) [Whitespace]

a b@

Instances
Functor BinOp Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

fmap :: (a -> b) -> BinOp a -> BinOp b #

(<$) :: a -> BinOp b -> BinOp a #

Foldable BinOp Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

fold :: Monoid m => BinOp m -> m #

foldMap :: Monoid m => (a -> m) -> BinOp a -> m #

foldr :: (a -> b -> b) -> b -> BinOp a -> b #

foldr' :: (a -> b -> b) -> b -> BinOp a -> b #

foldl :: (b -> a -> b) -> b -> BinOp a -> b #

foldl' :: (b -> a -> b) -> b -> BinOp a -> b #

foldr1 :: (a -> a -> a) -> BinOp a -> a #

foldl1 :: (a -> a -> a) -> BinOp a -> a #

toList :: BinOp a -> [a] #

null :: BinOp a -> Bool #

length :: BinOp a -> Int #

elem :: Eq a => a -> BinOp a -> Bool #

maximum :: Ord a => BinOp a -> a #

minimum :: Ord a => BinOp a -> a #

sum :: Num a => BinOp a -> a #

product :: Num a => BinOp a -> a #

Traversable BinOp Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

traverse :: Applicative f => (a -> f b) -> BinOp a -> f (BinOp b) #

sequenceA :: Applicative f => BinOp (f a) -> f (BinOp a) #

mapM :: Monad m => (a -> m b) -> BinOp a -> m (BinOp b) #

sequence :: Monad m => BinOp (m a) -> m (BinOp a) #

HasAnn BinOp Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

annot :: Lens' (BinOp a) (Ann a) Source #

Eq a => Eq (BinOp a) Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

(==) :: BinOp a -> BinOp a -> Bool #

(/=) :: BinOp a -> BinOp a -> Bool #

Show a => Show (BinOp a) Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

showsPrec :: Int -> BinOp a -> ShowS #

show :: BinOp a -> String #

showList :: [BinOp a] -> ShowS #

Generic (BinOp a) Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Associated Types

type Rep (BinOp a) :: Type -> Type #

Methods

from :: BinOp a -> Rep (BinOp a) x #

to :: Rep (BinOp a) x -> BinOp a #

HasTrailingWhitespace (BinOp a) Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

HasNewlines (BinOp a) Source # 
Instance details

Defined in Language.Python.Optics.Newlines

type Rep (BinOp a) Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

type Rep (BinOp a) = D1 (MetaData "BinOp" "Language.Python.Syntax.Operator.Binary" "hpython-0.3-inplace" False) ((((C1 (MetaCons "Is" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "IsNot" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: C1 (MetaCons "In" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: (C1 (MetaCons "NotIn" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: (C1 (MetaCons "Minus" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "Exp" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))))) :+: ((C1 (MetaCons "BoolAnd" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "BoolOr" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "Eq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: (C1 (MetaCons "Lt" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "LtEq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "Gt" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))))) :+: (((C1 (MetaCons "GtEq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "NotEq" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "Multiply" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: (C1 (MetaCons "Divide" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "FloorDivide" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "Percent" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))))) :+: ((C1 (MetaCons "Plus" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: (C1 (MetaCons "BitOr" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "BitXor" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: ((C1 (MetaCons "BitAnd" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "ShiftLeft" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))) :+: (C1 (MetaCons "ShiftRight" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])) :+: C1 (MetaCons "At" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))))))

data Assoc Source #

The associativity of an operator. Each operator is either left-associative or right associative.

Left associative:

x + y + z = (x + y) + z

Right associative:

x + y + z = x + (y + z)

Constructors

L 
R 
Instances
Eq Assoc Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

(==) :: Assoc -> Assoc -> Bool #

(/=) :: Assoc -> Assoc -> Bool #

Show Assoc Source # 
Instance details

Defined in Language.Python.Syntax.Operator.Binary

Methods

showsPrec :: Int -> Assoc -> ShowS #

show :: Assoc -> String #

showList :: [Assoc] -> ShowS #

data OpEntry Source #

An operator along with its precedence and associativity.

Constructors

OpEntry 

Fields

operatorTable :: [OpEntry] Source #

operatorTable is a list of all operators in ascending order of precedence.

sameOperator :: BinOp a -> BinOp a' -> Bool Source #

Compare two BinOps to determine whether they represent the same operator, ignoring annotations and trailing whitespace.

isComparison :: BinOp a -> Bool Source #

Is a BinOp a comparison, such as <=

lookupOpEntry :: BinOp a -> [OpEntry] -> OpEntry Source #

Retrieve the information for a given operator from the operator table.