Copyright | (C) CSIRO 2017-2018 |
---|---|
License | BSD3 |
Maintainer | Isaac Elliott <isaace71295@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
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
- data BinOp a
- = Is a [Whitespace]
- | IsNot a [Whitespace] [Whitespace]
- | In a [Whitespace]
- | NotIn a [Whitespace] [Whitespace]
- | Minus a [Whitespace]
- | Exp a [Whitespace]
- | BoolAnd a [Whitespace]
- | BoolOr a [Whitespace]
- | Eq a [Whitespace]
- | Lt a [Whitespace]
- | LtEq a [Whitespace]
- | Gt a [Whitespace]
- | GtEq a [Whitespace]
- | NotEq a [Whitespace]
- | Multiply a [Whitespace]
- | Divide a [Whitespace]
- | FloorDivide a [Whitespace]
- | Percent a [Whitespace]
- | Plus a [Whitespace]
- | BitOr a [Whitespace]
- | BitXor a [Whitespace]
- | BitAnd a [Whitespace]
- | ShiftLeft a [Whitespace]
- | ShiftRight a [Whitespace]
- | At a [Whitespace]
- data Assoc
- data OpEntry = OpEntry {}
- opPrec :: Lens' OpEntry Int
- opOperator :: Lens' OpEntry (BinOp ())
- opAssoc :: Lens' OpEntry Assoc
- operatorTable :: [OpEntry]
- sameOperator :: BinOp a -> BinOp a' -> Bool
- isComparison :: BinOp a -> Bool
- lookupOpEntry :: BinOp a -> [OpEntry] -> OpEntry
Documentation
A Python binary operator, such as +
, along with its trailing Whitespace
The type variable allows annotations, but it can simply be made ()
for an unannotated BinOp
.
Is a [Whitespace] | a is b |
IsNot a [Whitespace] [Whitespace] | a is not b |
In a [Whitespace] | a in b |
NotIn a [Whitespace] [Whitespace] | a not in b |
Minus a [Whitespace] | a - b |
Exp a [Whitespace] | a ** b |
BoolAnd a [Whitespace] | a and b |
BoolOr a [Whitespace] | a or b |
Eq a [Whitespace] | a == b |
Lt a [Whitespace] | a < b |
LtEq a [Whitespace] | a <= b |
Gt a [Whitespace] | a > b |
GtEq a [Whitespace] | a >= b |
NotEq a [Whitespace] | a != b |
Multiply a [Whitespace] | a * b |
Divide a [Whitespace] | a / b |
FloorDivide a [Whitespace] | a // b |
Percent a [Whitespace] | a % b |
Plus a [Whitespace] | a + b |
BitOr a [Whitespace] | a | b |
BitXor a [Whitespace] | a ^ b |
BitAnd a [Whitespace] | a & b |
ShiftLeft a [Whitespace] | a << b |
ShiftRight a [Whitespace] | a >> b |
At a [Whitespace] |
|
Instances
Functor BinOp Source # | |
Foldable BinOp Source # | |
Defined in Language.Python.Syntax.Operator.Binary 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 # elem :: Eq a => a -> BinOp a -> Bool # maximum :: Ord a => BinOp a -> a # minimum :: Ord a => BinOp a -> a # | |
Traversable BinOp Source # | |
Eq a => Eq (BinOp a) Source # | |
Show a => Show (BinOp a) Source # | |
HasTrailingWhitespace (BinOp a) Source # | |
Defined in Language.Python.Syntax.Operator.Binary trailingWhitespace :: Lens' (BinOp a) [Whitespace] Source # | |
HasNewlines (BinOp a) 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)
An operator along with its precedence and associativity.
opOperator :: Lens' OpEntry (BinOp ()) Source #
operatorTable :: [OpEntry] Source #
operatorTable
is a list of all operators in ascending order of precedence.