Copyright | (C) CSIRO 2017-2019 |
---|---|
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 :: Ann 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 {}
- indentWhitespaces :: Iso' Indent [Whitespace]
- indentIt :: [Whitespace] -> Indents a -> Indents a
- dedentIt :: Indents a -> Indents a
- data Indents a = Indents {
- _indentsValue :: [Indent]
- _indentsAnn :: Ann a
- indentsValue :: forall a. Lens' (Indents a) [Indent]
- indentsAnn :: forall a a. Lens (Indents a) (Indents a) (Ann a) (Ann 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 | |
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
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
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 #
indentWhitespaces :: Iso' Indent [Whitespace] Source #
An Indent
is isomorphic to a list of Whitespace
A possibly annotated list of Indent
s.
Indents | |
|