hpython-0.1.0.1: Python language tools

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

Language.Python.Syntax.Strings

Contents

Description

Synopsis

Datatypes

Characters

data PyChar #

A character in a string literal. This is a large sum type, with a catch-all of a Haskell Char.

Instances
Eq PyChar # 
Instance details

Defined in Language.Python.Syntax.Strings

Methods

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

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

Ord PyChar # 
Instance details

Defined in Language.Python.Syntax.Strings

Show PyChar # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic PyChar # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep PyChar :: * -> * #

Methods

from :: PyChar -> Rep PyChar x #

to :: Rep PyChar x -> PyChar #

type Rep PyChar # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep PyChar = D1 (MetaData "PyChar" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) ((((C1 (MetaCons "Char_newline" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Char_octal1" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 OctDigit))) :+: (C1 (MetaCons "Char_octal2" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 OctDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 OctDigit)) :+: C1 (MetaCons "Char_octal3" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 OctDigit) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 OctDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 OctDigit))))) :+: ((C1 (MetaCons "Char_hex" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit)) :+: C1 (MetaCons "Char_uni16" PrefixI False) ((S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit)))) :+: (C1 (MetaCons "Char_uni32" PrefixI False) (((S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit))) :*: ((S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit)) :*: (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 HeXDigit)))) :+: (C1 (MetaCons "Char_esc_bslash" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Char_esc_singlequote" PrefixI False) (U1 :: * -> *))))) :+: (((C1 (MetaCons "Char_esc_doublequote" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Char_esc_a" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Char_esc_b" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Char_esc_f" PrefixI False) (U1 :: * -> *))) :+: ((C1 (MetaCons "Char_esc_n" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Char_esc_r" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Char_esc_t" PrefixI False) (U1 :: * -> *) :+: (C1 (MetaCons "Char_esc_v" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Char_lit" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Char)))))))

fromHaskellString :: String -> [PyChar] #

Convert a Haskell string to a list of PyChar. This is useful when writing Python in Haskell.

String information

data QuoteType #

Double or single quotation marks?

"Double quotes"
"""Double quotes"""
'Single quotes'
'''Single quotes'''

Constructors

SingleQuote 
DoubleQuote 
Instances
Eq QuoteType # 
Instance details

Defined in Language.Python.Syntax.Strings

Ord QuoteType # 
Instance details

Defined in Language.Python.Syntax.Strings

Show QuoteType # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic QuoteType # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep QuoteType :: * -> * #

type Rep QuoteType # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep QuoteType = D1 (MetaData "QuoteType" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) (C1 (MetaCons "SingleQuote" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "DoubleQuote" PrefixI False) (U1 :: * -> *))

data StringType #

Three pairs of quotations or one?

"""Long string"""
'''Also long string'''
"Short string"
'Also short string'

Constructors

ShortString 
LongString 
Instances
Eq StringType # 
Instance details

Defined in Language.Python.Syntax.Strings

Ord StringType # 
Instance details

Defined in Language.Python.Syntax.Strings

Show StringType # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic StringType # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep StringType :: * -> * #

type Rep StringType # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep StringType = D1 (MetaData "StringType" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) (C1 (MetaCons "ShortString" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "LongString" PrefixI False) (U1 :: * -> *))

String prefixes

data StringPrefix #

In Python 3.5, a prefix of u or U is allowed, but doesn't have any meaning. They exist for backwards compatibility with Python 2.

See https://www.python.org/dev/peps/pep-0414/

Constructors

Prefix_u 
Prefix_U 
Instances
Eq StringPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Ord StringPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Show StringPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic StringPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep StringPrefix :: * -> * #

type Rep StringPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep StringPrefix = D1 (MetaData "StringPrefix" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) (C1 (MetaCons "Prefix_u" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Prefix_U" PrefixI False) (U1 :: * -> *))

data RawStringPrefix #

Raw strings are prefixed with either r or R.

Constructors

Prefix_r 
Prefix_R 

data BytesPrefix #

This prefix indicates it's a bytes literal rather than a string literal.

Constructors

Prefix_b 
Prefix_B 
Instances
Eq BytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Ord BytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Show BytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic BytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep BytesPrefix :: * -> * #

type Rep BytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep BytesPrefix = D1 (MetaData "BytesPrefix" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) (C1 (MetaCons "Prefix_b" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Prefix_B" PrefixI False) (U1 :: * -> *))

data RawBytesPrefix #

A string of raw bytes can be indicated by a number of prefixes

Instances
Eq RawBytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Ord RawBytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Show RawBytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic RawBytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep RawBytesPrefix :: * -> * #

type Rep RawBytesPrefix # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep RawBytesPrefix = D1 (MetaData "RawBytesPrefix" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) (((C1 (MetaCons "Prefix_br" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Prefix_Br" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Prefix_bR" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Prefix_BR" PrefixI False) (U1 :: * -> *))) :+: ((C1 (MetaCons "Prefix_rb" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Prefix_rB" PrefixI False) (U1 :: * -> *)) :+: (C1 (MetaCons "Prefix_Rb" PrefixI False) (U1 :: * -> *) :+: C1 (MetaCons "Prefix_RB" PrefixI False) (U1 :: * -> *))))

hasPrefix :: StringLiteral a -> Bool #

Most types of StringLiteral have prefixes. Plain old strings may have an optional prefix, but it is meaningless.

String literals

data StringLiteral a #

A StringLiteral, complete with a prefix, information about quote type and number, and a list of PyChars.

Like many other data types in hpython, it has an annotation and trailing whitespace.

Instances
Functor StringLiteral # 
Instance details

Defined in Language.Python.Syntax.Strings

Methods

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

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

Foldable StringLiteral # 
Instance details

Defined in Language.Python.Syntax.Strings

Methods

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

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

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

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

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

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

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

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

toList :: StringLiteral a -> [a] #

null :: StringLiteral a -> Bool #

length :: StringLiteral a -> Int #

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

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

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

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

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

Traversable StringLiteral # 
Instance details

Defined in Language.Python.Syntax.Strings

Methods

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

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

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

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

HasAnn StringLiteral # 
Instance details

Defined in Language.Python.Syntax.Strings

Methods

annot :: Functor f => (Ann a -> f (Ann a)) -> StringLiteral a -> f (StringLiteral a) #

Eq a => Eq (StringLiteral a) # 
Instance details

Defined in Language.Python.Syntax.Strings

Ord a => Ord (StringLiteral a) # 
Instance details

Defined in Language.Python.Syntax.Strings

Show a => Show (StringLiteral a) # 
Instance details

Defined in Language.Python.Syntax.Strings

Generic (StringLiteral a) # 
Instance details

Defined in Language.Python.Syntax.Strings

Associated Types

type Rep (StringLiteral a) :: * -> * #

HasTrailingWhitespace (StringLiteral a) # 
Instance details

Defined in Language.Python.Syntax.Strings

HasNewlines (StringLiteral a) # 
Instance details

Defined in Language.Python.Optics.Newlines

type Rep (StringLiteral a) # 
Instance details

Defined in Language.Python.Syntax.Strings

type Rep (StringLiteral a) = D1 (MetaData "StringLiteral" "Language.Python.Syntax.Strings" "hpython-0.1.0.1-inplace" False) ((C1 (MetaCons "RawStringLiteral" PrefixI True) ((S1 (MetaSel (Just "_stringLiteralAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: (S1 (MetaSel (Just "_unsafeRawStringLiteralPrefix") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 RawStringPrefix) :*: S1 (MetaSel (Just "_stringLiteralStringType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 StringType))) :*: (S1 (MetaSel (Just "_stringLiteralQuoteType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 QuoteType) :*: (S1 (MetaSel (Just "_stringLiteralValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [PyChar]) :*: S1 (MetaSel (Just "_stringLiteralWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: C1 (MetaCons "StringLiteral" PrefixI True) ((S1 (MetaSel (Just "_stringLiteralAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: (S1 (MetaSel (Just "_unsafeStringLiteralPrefix") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Maybe StringPrefix)) :*: S1 (MetaSel (Just "_stringLiteralStringType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 StringType))) :*: (S1 (MetaSel (Just "_stringLiteralQuoteType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 QuoteType) :*: (S1 (MetaSel (Just "_stringLiteralValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [PyChar]) :*: S1 (MetaSel (Just "_stringLiteralWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))))) :+: (C1 (MetaCons "RawBytesLiteral" PrefixI True) ((S1 (MetaSel (Just "_stringLiteralAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: (S1 (MetaSel (Just "_unsafeRawBytesLiteralPrefix") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 RawBytesPrefix) :*: S1 (MetaSel (Just "_stringLiteralStringType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 StringType))) :*: (S1 (MetaSel (Just "_stringLiteralQuoteType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 QuoteType) :*: (S1 (MetaSel (Just "_stringLiteralValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [PyChar]) :*: S1 (MetaSel (Just "_stringLiteralWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace])))) :+: C1 (MetaCons "BytesLiteral" PrefixI True) ((S1 (MetaSel (Just "_stringLiteralAnn") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (Ann a)) :*: (S1 (MetaSel (Just "_unsafeBytesLiteralPrefix") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 BytesPrefix) :*: S1 (MetaSel (Just "_stringLiteralStringType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 StringType))) :*: (S1 (MetaSel (Just "_stringLiteralQuoteType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 QuoteType) :*: (S1 (MetaSel (Just "_stringLiteralValue") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [PyChar]) :*: S1 (MetaSel (Just "_stringLiteralWhitespace") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 [Whitespace]))))))

Lenses

Rendering

Extra functions

isEscape :: PyChar -> Bool #

Determine whether a PyChar is an escape character or not.