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.Optics

Contents

Description

Optics for manipulating Python syntax trees

Synopsis

Documentation

Identifiers

Indentation

Newlines

Simple statements

Assignment

assignTargets :: Traversal (Expr v a) (Expr '[] a) (Ident v a) (Ident '[] a) #

Traversal targeting the variables that would modified as a result of an assignment

Here are some examples of assignment targets:

a = b
^
(a, b, c) = d
 ^  ^  ^
[a, b, *c] = d
 ^  ^   ^

These expressions have variables on the left hand side of the =, but those variables don't count as assignment targets:

a[b] = c
a(b) = c
{a: b} = c

Compound statements

class HasCompoundStatement s where #

Minimal complete definition

_CompoundStatement

Methods

_CompoundStatement :: Prism (s v a) (s '[] a) (CompoundStatement v a) (CompoundStatement '[] a) #

Instances
HasCompoundStatement CompoundStatement # 
Instance details

Defined in Language.Python.Optics

HasCompoundStatement Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_CompoundStatement :: (Choice p, Applicative f) => p (CompoundStatement v a) (f (CompoundStatement [] a)) -> p (Statement v a) (f (Statement [] a)) #

Function definitions

class HasFundef s where #

Minimal complete definition

_Fundef

Methods

_Fundef :: Prism (s v a) (s '[] a) (Fundef v a) (Fundef '[] a) #

Instances
HasFundef CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_Fundef :: (Choice p, Applicative f) => p (Fundef v a) (f (Fundef [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasFundef Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_Fundef :: (Choice p, Applicative f) => p (Fundef v a) (f (Fundef [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasFundef Fundef # 
Instance details

Defined in Language.Python.Optics

Methods

_Fundef :: (Choice p, Applicative f) => p (Fundef v a) (f (Fundef [] a)) -> p (Fundef v a) (f (Fundef [] a)) #

Class defintions

class HasClassDef s where #

Minimal complete definition

_ClassDef

Methods

_ClassDef :: Prism (s v a) (s '[] a) (ClassDef v a) (ClassDef '[] a) #

Instances
HasClassDef CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_ClassDef :: (Choice p, Applicative f) => p (ClassDef v a) (f (ClassDef [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasClassDef Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_ClassDef :: (Choice p, Applicative f) => p (ClassDef v a) (f (ClassDef [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasClassDef ClassDef # 
Instance details

Defined in Language.Python.Optics

Methods

_ClassDef :: (Choice p, Applicative f) => p (ClassDef v a) (f (ClassDef [] a)) -> p (ClassDef v a) (f (ClassDef [] a)) #

while statements

class HasWhile s where #

Minimal complete definition

_While

Methods

_While :: Prism (s v a) (s '[] a) (While v a) (While '[] a) #

Instances
HasWhile CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_While :: (Choice p, Applicative f) => p (While v a) (f (While [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasWhile Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_While :: (Choice p, Applicative f) => p (While v a) (f (While [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasWhile While # 
Instance details

Defined in Language.Python.Optics

Methods

_While :: (Choice p, Applicative f) => p (While v a) (f (While [] a)) -> p (While v a) (f (While [] a)) #

for statements

class HasFor s where #

Minimal complete definition

_For

Methods

_For :: Prism (s v a) (s '[] a) (For v a) (For '[] a) #

Instances
HasFor CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_For :: (Choice p, Applicative f) => p (For v a) (f (For [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasFor Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_For :: (Choice p, Applicative f) => p (For v a) (f (For [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasFor For # 
Instance details

Defined in Language.Python.Optics

Methods

_For :: (Choice p, Applicative f) => p (For v a) (f (For [] a)) -> p (For v a) (f (For [] a)) #

with statements

class HasWith s where #

Minimal complete definition

_With

Methods

_With :: Prism (s v a) (s '[] a) (With v a) (With '[] a) #

Instances
HasWith CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_With :: (Choice p, Applicative f) => p (With v a) (f (With [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasWith Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_With :: (Choice p, Applicative f) => p (With v a) (f (With [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasWith With # 
Instance details

Defined in Language.Python.Optics

Methods

_With :: (Choice p, Applicative f) => p (With v a) (f (With [] a)) -> p (With v a) (f (With [] a)) #

if statements

class HasIf s where #

Minimal complete definition

_If

Methods

_If :: Prism (s v a) (s '[] a) (If v a) (If '[] a) #

Instances
HasIf CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_If :: (Choice p, Applicative f) => p (If v a) (f (If [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasIf Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_If :: (Choice p, Applicative f) => p (If v a) (f (If [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasIf If # 
Instance details

Defined in Language.Python.Optics

Methods

_If :: (Choice p, Applicative f) => p (If v a) (f (If [] a)) -> p (If v a) (f (If [] a)) #

_Elif :: Iso' (Elif v a) (Indents a, [Whitespace], Expr v a, Suite v a) #

try statements

class HasTryExcept s where #

Minimal complete definition

_TryExcept

Methods

_TryExcept :: Prism (s v a) (s '[] a) (TryExcept v a) (TryExcept '[] a) #

Instances
HasTryExcept CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_TryExcept :: (Choice p, Applicative f) => p (TryExcept v a) (f (TryExcept [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasTryExcept Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_TryExcept :: (Choice p, Applicative f) => p (TryExcept v a) (f (TryExcept [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasTryExcept TryExcept # 
Instance details

Defined in Language.Python.Optics

Methods

_TryExcept :: (Choice p, Applicative f) => p (TryExcept v a) (f (TryExcept [] a)) -> p (TryExcept v a) (f (TryExcept [] a)) #

class HasTryFinally s where #

Minimal complete definition

_TryFinally

Methods

_TryFinally :: Prism (s v a) (s '[] a) (TryFinally v a) (TryFinally '[] a) #

Instances
HasTryFinally CompoundStatement # 
Instance details

Defined in Language.Python.Optics

Methods

_TryFinally :: (Choice p, Applicative f) => p (TryFinally v a) (f (TryFinally [] a)) -> p (CompoundStatement v a) (f (CompoundStatement [] a)) #

HasTryFinally Statement # 
Instance details

Defined in Language.Python.Optics

Methods

_TryFinally :: (Choice p, Applicative f) => p (TryFinally v a) (f (TryFinally [] a)) -> p (Statement v a) (f (Statement [] a)) #

HasTryFinally TryFinally # 
Instance details

Defined in Language.Python.Optics

Methods

_TryFinally :: (Choice p, Applicative f) => p (TryFinally v a) (f (TryFinally [] a)) -> p (TryFinally v a) (f (TryFinally [] a)) #

_Except :: Iso' (Except v a) (Indents a, [Whitespace], Maybe (ExceptAs v a), Suite v a) #

else

_Else :: Iso' (Else v a) (Indents a, [Whitespace], Suite v a) #

Parameters

_KeywordParam :: Prism (Param v a) (Param '[] a) (KeywordParam v a) (KeywordParam '[] a) #

_StarParam :: Prism (Param v a) (Param '[] a) (StarParam v a) (StarParam '[] a) #

Expressions

Identifiers

_Ident :: (Choice p, Applicative f) => p (Ident v a) (f (Ident '[] a)) -> p (Expr v a) (f (Expr '[] a)) #

A faux-Prism for matching on the Ident constructor of an Expr.

It's not a Prism because:

When previewing, it discards the 'Expr'\'s annotation, and when reviewing, it re-constructs an annotation from the supplied Ident

_Ident :: Prism (Expr v a) (Expr '[] a) (Ident v a) (Ident '[] a)

None

_None :: Prism (Expr v a) (Expr '[] a) (None v a) (None '[] a) #

Function calls

_Call :: Prism (Expr v a) (Expr '[] a) (Call v a) (Call '[] a) #

Tuples

_Tuple :: Prism (Expr v a) (Expr '[] a) (Tuple v a) (Tuple '[] a) #

tupleItems :: Traversal (Tuple v a) (Tuple '[] a) (TupleItem v a) (TupleItem '[] a) #

Lists

_List :: Prism (Expr v a) (Expr '[] a) (List v a) (List '[] a) #

_ListUnpack :: Prism (ListItem v a) (ListItem '[] a) (ListUnpack v a) (ListUnpack '[] a) #

listItems :: Traversal (List v a) (List '[] a) (ListItem v a) (ListItem '[] a) #