Copyright | (C) CSIRO 2017-2018 |
---|---|
License | BSD3 |
Maintainer | Isaac Elliott <isaace71295@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Synopsis
- data Newline
- data Whitespace
- data Blank a = Blank {
- _blankAnn :: a
- _blankWhitespaces :: [Whitespace]
- _blankComment :: Maybe (Comment a)
- class HasTrailingWhitespace s where
- trailingWhitespace :: Lens' s [Whitespace]
- class HasTrailingNewline (s :: [*] -> * -> *) where
- trailingNewline :: Traversal' (s v a) Newline
- setTrailingNewline :: s v a -> Newline -> s v a
- data IndentLevel
- getIndentLevel :: IndentLevel -> Int
- indentLevel :: Indent -> Int
- absoluteIndentLevel :: Int -> Indent -> Int
- newtype Indent = MkIndent {
- unIndent :: FingerTree IndentLevel Whitespace
- indentWhitespaces :: Iso' Indent [Whitespace]
- indentIt :: [Whitespace] -> Indents a -> Indents a
- dedentIt :: Indents a -> Indents a
- data Indents a = Indents {
- _indentsValue :: [Indent]
- _indentsAnn :: a
- indentsValue :: forall a. Lens' (Indents a) [Indent]
- indentsAnn :: forall a a. Lens (Indents a) (Indents a) a a
- subtractStart :: Indents a -> Indents a -> Maybe (Indents a)
Whitespace
A newline is either a carriage return, a line feed, or a carriage return followed by a line feed.
data Whitespace Source #
Whitespace is either a space, a tab, a newline that continues the
logical line (Continued
), a newline that ends the logical line (Newline
),
or a Whitespace
.
Despite not literally being whitespace, comments inside enclosed forms are treated as whitespace. See https://docs.python.org/3.5/reference/lexical_analysis.html#implicit-line-joining
Example and counterexample of comments as whitespace
( 1 + # here's a comment 2 + 3 # another comment )
x = 5 + 5 # this line is not considered whitespace y = x * 2
[ 1 , 2 # I'm whitespace , 3 # also whitespace ]
Instances
Eq Whitespace Source # | |
Defined in Language.Python.Syntax.Whitespace (==) :: Whitespace -> Whitespace -> Bool # (/=) :: Whitespace -> Whitespace -> Bool # | |
Ord Whitespace Source # | |
Defined in Language.Python.Syntax.Whitespace compare :: Whitespace -> Whitespace -> Ordering # (<) :: Whitespace -> Whitespace -> Bool # (<=) :: Whitespace -> Whitespace -> Bool # (>) :: Whitespace -> Whitespace -> Bool # (>=) :: Whitespace -> Whitespace -> Bool # max :: Whitespace -> Whitespace -> Whitespace # min :: Whitespace -> Whitespace -> Whitespace # | |
Show Whitespace Source # | |
Defined in Language.Python.Syntax.Whitespace showsPrec :: Int -> Whitespace -> ShowS # show :: Whitespace -> String # showList :: [Whitespace] -> ShowS # | |
HasNewlines Whitespace Source # | |
Defined in Language.Python.Optics.Newlines _Newlines :: Traversal' Whitespace Newline Source # | |
Measured IndentLevel Whitespace Source # | |
Defined in Language.Python.Syntax.Whitespace measure :: Whitespace -> IndentLevel |
Lines which are "blank", meaning that they contain, if anything, only whitespace and/or a comment.
Blank | |
|
Instances
Functor Blank Source # | |
Foldable Blank Source # | |
Defined in Language.Python.Syntax.Whitespace fold :: Monoid m => Blank m -> m # foldMap :: Monoid m => (a -> m) -> Blank a -> m # foldr :: (a -> b -> b) -> b -> Blank a -> b # foldr' :: (a -> b -> b) -> b -> Blank a -> b # foldl :: (b -> a -> b) -> b -> Blank a -> b # foldl' :: (b -> a -> b) -> b -> Blank a -> b # foldr1 :: (a -> a -> a) -> Blank a -> a # foldl1 :: (a -> a -> a) -> Blank a -> a # elem :: Eq a => a -> Blank a -> Bool # maximum :: Ord a => Blank a -> a # minimum :: Ord a => Blank a -> a # | |
Traversable Blank Source # | |
Eq a => Eq (Blank a) Source # | |
Show a => Show (Blank a) Source # | |
HasNewlines (Blank a) Source # | |
class HasTrailingWhitespace s where Source #
Every syntactic element contains the whitespace that immediately follows it.
This type class lets us access this trailing whitespace in many different types throughout hpython.
trailingWhitespace :: Lens' s [Whitespace] Source #
Instances
class HasTrailingNewline (s :: [*] -> * -> *) where Source #
A statement-containing thing may have a trailing newline
Some forms always have a trailing newline, which is why this class isn't just
trailingNewline ::
Lens'
(s v a) (Maybe
Newline
)
trailingNewline :: Traversal' (s v a) Newline Source #
setTrailingNewline :: s v a -> Newline -> s v a Source #
Instances
HasTrailingNewline CompoundStatement Source # | |
Defined in Language.Python.Syntax.Statement trailingNewline :: Traversal' (CompoundStatement v a) Newline Source # setTrailingNewline :: CompoundStatement v a -> Newline -> CompoundStatement v a Source # | |
HasTrailingNewline Suite Source # | |
Defined in Language.Python.Syntax.Statement | |
HasTrailingNewline Statement Source # | |
Defined in Language.Python.Syntax.Statement | |
HasTrailingNewline SmallStatement Source # | |
Defined in Language.Python.Syntax.Statement trailingNewline :: Traversal' (SmallStatement v a) Newline Source # setTrailingNewline :: SmallStatement v a -> Newline -> SmallStatement v a Source # | |
HasTrailingNewline Block Source # | |
Defined in Language.Python.Syntax.Statement |
Indentation
data IndentLevel Source #
Python has rules regarding the expansion of tabs into spaces and how to go about computing indentation after this is done.
See https://docs.python.org/3.5/reference/lexical_analysis.html#indentation
This data structure implements those rules as a monoid.
Instances
Semigroup IndentLevel Source # | |
Defined in Language.Python.Syntax.Whitespace (<>) :: IndentLevel -> IndentLevel -> IndentLevel # sconcat :: NonEmpty IndentLevel -> IndentLevel # stimes :: Integral b => b -> IndentLevel -> IndentLevel # | |
Monoid IndentLevel Source # | |
Defined in Language.Python.Syntax.Whitespace mempty :: IndentLevel # mappend :: IndentLevel -> IndentLevel -> IndentLevel # mconcat :: [IndentLevel] -> IndentLevel # | |
Measured IndentLevel Whitespace Source # | |
Defined in Language.Python.Syntax.Whitespace measure :: Whitespace -> IndentLevel |
getIndentLevel :: IndentLevel -> Int Source #
indentLevel :: Indent -> Int Source #
MkIndent | |
|
indentWhitespaces :: Iso' Indent [Whitespace] Source #
An Indent
is isomorphic to a list of Whitespace
A possibly annotated list of Indent
s.
Indents | |
|
Instances
Functor Indents Source # | |
Foldable Indents Source # | |
Defined in Language.Python.Syntax.Whitespace fold :: Monoid m => Indents m -> m # foldMap :: Monoid m => (a -> m) -> Indents a -> m # foldr :: (a -> b -> b) -> b -> Indents a -> b # foldr' :: (a -> b -> b) -> b -> Indents a -> b # foldl :: (b -> a -> b) -> b -> Indents a -> b # foldl' :: (b -> a -> b) -> b -> Indents a -> b # foldr1 :: (a -> a -> a) -> Indents a -> a # foldl1 :: (a -> a -> a) -> Indents a -> a # elem :: Eq a => a -> Indents a -> Bool # maximum :: Ord a => Indents a -> a # minimum :: Ord a => Indents a -> a # | |
Traversable Indents Source # | |
Eq1 Indents Source # | |
Ord1 Indents Source # | |
Defined in Language.Python.Syntax.Whitespace | |
Eq a => Eq (Indents a) Source # | |
Show a => Show (Indents a) Source # | |
Semigroup a => Semigroup (Indents a) Source # | |
HasNewlines (Indents a) Source # | |
indentsValue :: forall a. Lens' (Indents a) [Indent] Source #
indentsAnn :: forall a a. Lens (Indents a) (Indents a) a a Source #