hpython-0.2: Python language tools

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

Language.Python.Internal.Lexer

Contents

Description

 
Synopsis

Documentation

tokenizeWithTabs Source #

Arguments

:: (AsLexicalError s Char, AsTabError s SrcInfo, AsIncorrectDedent s SrcInfo) 
=> FilePath

File name

-> Text

Input to tokenize

-> Either s [PyToken SrcInfo] 

Tokenize an input file, inserting indent/level/dedent tokens in appropriate positions according to the block structure.

Source Information

withSrcInfo :: MonadParsec e s m => m (SrcInfo -> a) -> m a Source #

Errors

unsafeFromLexicalError :: (HasCallStack, AsLexicalError s t) => ParseError t Void -> s Source #

Convert a concrete ParseError to a value that has an instance of AsLexicalError

This function is partial, because our parser will never use FancyError

class AsTabError s a | s -> a where Source #

Methods

_TabError :: Prism' s a Source #

class AsIncorrectDedent s a | s -> a where Source #

Instances
AsIncorrectDedent (ParseError a) a Source # 
Instance details

Defined in Language.Python.Parse.Error

fromTabError :: (AsTabError s a, AsIncorrectDedent s a) => TabError a -> s Source #

Convert a concrete TabError to a value that has an instance of AsTabError

data TabError a Source #

Constructors

TabError a

Tabs and spaces were used inconsistently

IncorrectDedent a

The dedent at the end of a block doesn't match and preceding indents

e.g.

def a():
    if b:
        pass
    else:
        pass
  pass

The final line will cause an IncorrectDedent error

Instances
Eq a => Eq (TabError a) Source # 
Instance details

Defined in Language.Python.Internal.Lexer

Methods

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

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

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

Defined in Language.Python.Internal.Lexer

Methods

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

show :: TabError a -> String #

showList :: [TabError a] -> ShowS #

Miscellaneous

tokenize Source #

Arguments

:: AsLexicalError e Char 
=> FilePath

File name

-> Text

Input to tokenize

-> Either e [PyToken SrcInfo] 

Convert some input to a sequence of tokens. Indent and dedent tokens are not added (see insertTabs)

insertTabs Source #

Arguments

:: (Semigroup a, AsTabError s a, AsIncorrectDedent s a) 
=> a

Initial source annotation

-> [PyToken a]

Token stream

-> Either s [PyToken a] 

Megaparsec re-exports

data ParseError t e #

ParseError t e represents a parse error parametrized over the token type t and the custom data e.

Note that the stack of source positions contains current position as its head, and the rest of positions allows to track full sequence of include files with topmost source file at the end of the list.

Semigroup and Monoid instances of the data type allow to merge parse errors from different branches of parsing. When merging two ParseErrors, the longest match is preferred; if positions are the same, custom data sets and collections of message items are combined. Note that fancy errors take precedence over trivial errors in merging.

Since: megaparsec-6.0.0

Constructors

TrivialError (NonEmpty SourcePos) (Maybe (ErrorItem t)) (Set (ErrorItem t))

Trivial errors, generated by Megaparsec's machinery. The data constructor includes the stack of source positions, unexpected token (if any), and expected tokens.

FancyError (NonEmpty SourcePos) (Set (ErrorFancy e))

Fancy, custom errors.

Instances
(Eq t, Eq e) => Eq (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Methods

(==) :: ParseError t e -> ParseError t e -> Bool #

(/=) :: ParseError t e -> ParseError t e -> Bool #

(Data t, Data e, Ord t, Ord e) => Data (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ParseError t e -> c (ParseError t e) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ParseError t e) #

toConstr :: ParseError t e -> Constr #

dataTypeOf :: ParseError t e -> DataType #

dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (ParseError t e)) #

dataCast2 :: Typeable t0 => (forall d e0. (Data d, Data e0) => c (t0 d e0)) -> Maybe (c (ParseError t e)) #

gmapT :: (forall b. Data b => b -> b) -> ParseError t e -> ParseError t e #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ParseError t e -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ParseError t e -> r #

gmapQ :: (forall d. Data d => d -> u) -> ParseError t e -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ParseError t e -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ParseError t e -> m (ParseError t e) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ParseError t e -> m (ParseError t e) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ParseError t e -> m (ParseError t e) #

(Read t, Read e, Ord t, Ord e) => Read (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

(Show t, Show e) => Show (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Methods

showsPrec :: Int -> ParseError t e -> ShowS #

show :: ParseError t e -> String #

showList :: [ParseError t e] -> ShowS #

Generic (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Associated Types

type Rep (ParseError t e) :: Type -> Type #

Methods

from :: ParseError t e -> Rep (ParseError t e) x #

to :: Rep (ParseError t e) x -> ParseError t e #

(Ord t, Ord e) => Semigroup (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Methods

(<>) :: ParseError t e -> ParseError t e -> ParseError t e #

sconcat :: NonEmpty (ParseError t e) -> ParseError t e #

stimes :: Integral b => b -> ParseError t e -> ParseError t e #

(Ord t, Ord e) => Monoid (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Methods

mempty :: ParseError t e #

mappend :: ParseError t e -> ParseError t e -> ParseError t e #

mconcat :: [ParseError t e] -> ParseError t e #

(Show t, Ord t, ShowToken t, Typeable t, Show e, ShowErrorComponent e, Typeable e) => Exception (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

(NFData t, NFData e) => NFData (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error

Methods

rnf :: ParseError t e -> () #

type Rep (ParseError t e) 
Instance details

Defined in Text.Megaparsec.Error