Struct python_ast::Parser
[−]
[src]
pub struct Parser<'a> { state: ParserState<'a>, }
Create a Python AST from slice of Tokens created from the lexer::Lexer
.
Fields
state: ParserState<'a>
Methods
impl<'a> Parser<'a>
[src]
fn new() -> Self
Create a new instance of Parser
eager to consume TkSlice
instances.
fn parse_tokens<'b, 'c>(&mut self, tokens: &'b [Tk<'b>]) -> ParserResult
Public wrapper to the macro generated tkslice_to_ast which will take a slice of tokens, turn those into a TkSlice, and parse that into an AST.
fn inc_lineno(&mut self) -> usize
fn tkslice_to_ast<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Ast, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Ast, u32>)
fn module_start<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Module, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Module, u32>)
fn stmt_start<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_funcdef<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_block<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_return<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_assign<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_augassign<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_assert<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_assert_2arg<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_expr<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn sub_stmt_next_line<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Stmt, u32>)
fn start_expr<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_lambda<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_conditional<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_operator<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_boolop_logic_or<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_boolop_logic_and<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_or<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_xor<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_and<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_unaryop_logicnot<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_unaryop_neg<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_equality<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_inequality<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_is<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_in<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_not_in<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_lt<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_lte<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_gt<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_gte<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_lshift<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_rshift<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_add<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_sub<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_mul<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_matmul<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_truediv<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_floordiv<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_mod<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_binop_pow<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_call<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_getattr<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_list<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_dict<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_nameconstant<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_constant<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr, u32>)
fn sub_expr_func_args<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Vec<Expr>, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Vec<Expr>, u32>)
fn sub_expr_call_args<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Vec<Expr>, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Vec<Expr>, u32>)
fn sub_expr_dict_items<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Vec<(Expr, Expr)>, u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, Vec<(Expr, Expr)>, u32>)
fn sub_expr_dict_item<'b>(
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, (Expr, Expr), u32>)
self: Parser<'a>,
i: TkSlice<'b>
) -> (Parser<'a>, IResult<TkSlice<'b>, (Expr, Expr), u32>)
fn parse_sub_expr<'b>(
self,
slices: &'b [TkSlice<'b>]
) -> Result<Expr, ParserError>
self,
slices: &'b [TkSlice<'b>]
) -> Result<Expr, ParserError>
Helper for the recursive parsing of a subexpression as is common in
in cases where something has an infix-y semantic. For example:
x = 1 if y else 2
or q = [i for i in entries if i >= 3]
fn build_binop<'b>(
self,
i: TkSlice<'b>,
op: TkSlice<'b>,
lhs: Vec<TkSlice<'b>>,
rhs: Expr
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr>)
self,
i: TkSlice<'b>,
op: TkSlice<'b>,
lhs: Vec<TkSlice<'b>>,
rhs: Expr
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr>)
Offload the work to parse tokens in the LHS here instead of in the binop parsers
as a way to get around type inference hell. See build_conditional
.
fn build_conditional<'b>(
self,
i: TkSlice<'b>,
cons: Vec<TkSlice<'b>>,
cond: Vec<TkSlice<'b>>,
alt: Expr
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr>)
self,
i: TkSlice<'b>,
cons: Vec<TkSlice<'b>>,
cond: Vec<TkSlice<'b>>,
alt: Expr
) -> (Parser<'a>, IResult<TkSlice<'b>, Expr>)
Offloads the work to parse the conditional subexpressions found in sub_expr_conditional
.
This could probably be done in that function however, there were issues with
proper error type inference. In the future, a brave soul may wish to try to
add a map!(..., ...) onto the subexpression matchers for purity.
fn build_dict_item<'b>(
self,
i: TkSlice<'b>,
key: Vec<TkSlice<'b>>,
value: Expr
) -> (Parser<'a>, IResult<TkSlice<'b>, (Expr, Expr)>)
self,
i: TkSlice<'b>,
key: Vec<TkSlice<'b>>,
value: Expr
) -> (Parser<'a>, IResult<TkSlice<'b>, (Expr, Expr)>)
Trait Implementations
impl<'a> Debug for Parser<'a>
[src]
impl<'a> Copy for Parser<'a>
[src]
impl<'a> Clone for Parser<'a>
[src]
fn clone(&self) -> Parser<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more