Struct cl_parser::parser::Parser

source ·
pub struct Parser<'t> { /* private fields */ }
Expand description

Parses a sequence of Tokens into an AST

Implementations§

source§

impl<'t> Parser<'t>

Basic parser functionality

source

pub fn new(lexer: Lexer<'t>) -> Self

source

pub fn loc(&self) -> Loc

Gets the location of the last consumed Token

source

pub fn peek(&mut self, while_parsing: Parsing) -> PResult<&Token>

Looks ahead one token

Stores the token in an internal lookahead buffer

source

pub fn peek_kind(&mut self, while_parsing: Parsing) -> PResult<TokenKind>

Looks ahead at the next Token’s TokenKind

source

pub fn consume_peeked(&mut self) -> Option<Token>

Consumes a previously peeked Token, returning it. Returns None when there is no peeked token.

This avoids the overhead of constructing an Error

source

pub fn consume(&mut self, while_parsing: Parsing) -> PResult<Token>

Consumes one Token

source

pub fn match_type( &mut self, want: TokenKind, while_parsing: Parsing ) -> PResult<Token>

Consumes the next Token if it matches the pattern TokenKind

source

pub fn match_op( &mut self, want: Punct, while_parsing: Parsing ) -> PResult<Token>

source§

impl<'t> Parser<'t>

Top level parsing

source

pub fn file(&mut self) -> PResult<File>

Parses a [File]

source

pub fn item(&mut self) -> PResult<Item>

Parses an [Item]

See also: Parser::itemkind

source

pub fn ty(&mut self) -> PResult<Ty>

Parses a [Ty]

See also: Parser::tykind

source

pub fn path(&mut self) -> PResult<Path>

Parses a [Path]

See also: Parser::path_part, Parser::identifier

[Path] = :: RelativePath? | RelativePath
RelativePath = [PathPart] (:: [PathPart])*

source

pub fn stmt(&mut self) -> PResult<Stmt>

Parses a [Stmt]

See also: Parser::stmtkind

source

pub fn expr(&mut self) -> PResult<Expr>

Parses an [Expr]

See also: Parser::exprkind

source§

impl<'t> Parser<'t>

Attribute parsing

source

pub fn attributes(&mut self) -> PResult<Attrs>

Parses an attribute set

source

pub fn meta(&mut self) -> PResult<Meta>

Parses a single attribute

source

pub fn meta_kind(&mut self) -> PResult<MetaKind>

Parses data associated with a [Meta] attribute

source§

impl<'t> Parser<'t>

Item parsing

source

pub fn itemkind(&mut self) -> PResult<ItemKind>

Parses an [ItemKind]

See also: Parser::item

source

pub fn parse_alias(&mut self) -> PResult<Alias>

Parses a type alias

source

pub fn parse_const(&mut self) -> PResult<Const>

source

pub fn parse_static(&mut self) -> PResult<Static>

Parses a static item

source

pub fn parse_module(&mut self) -> PResult<Module>

Parses a [Module]

source

pub fn modulekind(&mut self) -> PResult<ModuleKind>

Parses the item list associated with a [Module], if present

source

pub fn parse_function(&mut self) -> PResult<Function>

Parses a [Function] definition

source

pub fn parse_params(&mut self) -> PResult<(Vec<Param>, Vec<TyKind>)>

Parses the parameters associated with a Function

source

pub fn parse_param(&mut self) -> PResult<(Param, TyKind)>

Parses a single function parameter

source

pub fn parse_struct(&mut self) -> PResult<Struct>

source

pub fn structkind_tuple(&mut self) -> PResult<StructKind>

Parses a tuple-struct’s members

source

pub fn structkind_struct(&mut self) -> PResult<StructKind>

Parses a structs members

source

pub fn struct_member(&mut self) -> PResult<StructMember>

Parses a single [StructMember]

source

pub fn parse_enum(&mut self) -> PResult<Enum>

Parses an enum definition

source

pub fn enum_variant(&mut self) -> PResult<Variant>

Parses an enum [Variant]

source

pub fn variantkind_clike(&mut self) -> PResult<VariantKind>

Parses a C-like enum [Variant]

source

pub fn variantkind_struct(&mut self) -> PResult<VariantKind>

Parses a struct-like enum [Variant]

source

pub fn variantkind_tuple(&mut self) -> PResult<VariantKind>

Parses a tuple-like enum [Variant]

source

pub fn parse_impl(&mut self) -> PResult<Impl>

source

pub fn parse_impl_kind(&mut self) -> PResult<ImplKind>

source

pub fn parse_use(&mut self) -> PResult<Use>

source

pub fn parse_use_tree(&mut self) -> PResult<UseTree>

source

pub fn visibility(&mut self) -> Visibility

[Visibility] = pub?

source

pub fn mutability(&mut self) -> Mutability

[Mutability] = mut?

source§

impl<'t> Parser<'t>

§Type parsing

source

pub fn tykind(&mut self) -> PResult<TyKind>

Parses a [TyKind]

See also: Parser::ty

source

pub fn tytuple(&mut self) -> PResult<TyTuple>

[TyTuple] = ( ([Ty] ,)* [Ty]? )

source

pub fn tyref(&mut self) -> PResult<TyRef>

[TyRef] = (&|&&)* [Path]

source

pub fn tyfn(&mut self) -> PResult<TyFn>

[TyFn] = fn [TyTuple] (-> [Ty])?

source

pub fn parse_rety(&mut self) -> PResult<Option<Ty>>

source

pub fn tyfn_args(&mut self) -> PResult<Vec<TyKind>>

source§

impl<'t> Parser<'t>

§Path parsing

source

pub fn path_part(&mut self) -> PResult<PathPart>

[PathPart] = super | self | Identifier

source

pub fn identifier(&mut self) -> PResult<Sym>

[Sym] = Identifier

source§

impl<'t> Parser<'t>

§Statement parsing

source

pub fn stmtkind(&mut self) -> PResult<StmtKind>

Parses a [StmtKind]

See also: Parser::stmt

source

pub fn parse_let(&mut self) -> PResult<Let>

source§

impl<'t> Parser<'t>

§Expression parsing

source

pub fn expr_from( &mut self, f: impl Fn(&mut Self) -> PResult<ExprKind> ) -> PResult<Expr>

Creates an [Expr] with the given [ExprKind]-parser

source

pub fn exprkind(&mut self, power: u8) -> PResult<ExprKind>

Parses an [ExprKind]

See also: Parser::expr

source

pub fn access(&mut self) -> PResult<MemberKind>

source

pub fn exprkind_pathlike(&mut self) -> PResult<ExprKind>

Parses an expression beginning with a [Path] (i.e. [Path] or [Structor])

source

pub fn structor_body(&mut self, to: Path) -> PResult<Structor>

[Structor]Body = { ([Fielder] ,)* [Fielder]? }

source

pub fn fielder(&mut self) -> PResult<Fielder>

[Fielder] = Identifier (: [Expr])?

source

pub fn exprkind_arraylike(&mut self) -> PResult<ExprKind>

[Array] = ‘[’ ([Expr] ‘,’)* [Expr]? ‘]’

Array and ArrayRef are ambiguous until the second token, so they can’t be independent subexpressions

source

pub fn exprkind_array_rep(&mut self) -> PResult<ExprKind>

[ArrayRep] = [ [Expr] ; [Expr] ]

source

pub fn exprkind_tuplelike(&mut self) -> PResult<ExprKind>

[Group] = ((Empty|[Expr]|[Tuple]))

[ExprKind::Empty] and [Group] are special cases of [Tuple]

source

pub fn exprkind_group(&mut self) -> PResult<ExprKind>

[Group] = ((Empty|[Expr]|[Tuple]))

source§

impl<'t> Parser<'t>

§Subexpressions
source

pub fn addrof(&mut self) -> PResult<AddrOf>

[AddrOf] = (&|&&)* [Expr]

source

pub fn literal(&mut self) -> PResult<Literal>

[Literal] = LITERAL | true | false

source

pub fn block(&mut self) -> PResult<Block>

[Block] = { [Stmt]* }

source§

impl<'t> Parser<'t>

§Control flow subexpressions
source

pub fn parse_break(&mut self) -> PResult<Break>

[Break] = break (unconsumed ; | [Expr])

source

pub fn parse_return(&mut self) -> PResult<Return>

[Return] = return (unconsumed ; | [Expr])

source

pub fn parse_while(&mut self) -> PResult<While>

[While] = while [Expr] [Block] [Else]?

source

pub fn parse_if(&mut self) -> PResult<If>

[If] = if [Expr] [Block] [Else]?

source

pub fn parse_for(&mut self) -> PResult<For>

[For]: for Pattern (TODO) in [Expr] [Block] [Else]?

source

pub fn parse_else(&mut self) -> PResult<Else>

[Else]: (else [Block])?

Trait Implementations§

source§

impl<'t> Debug for Parser<'t>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'t> Freeze for Parser<'t>

§

impl<'t> RefUnwindSafe for Parser<'t>

§

impl<'t> Send for Parser<'t>

§

impl<'t> Sync for Parser<'t>

§

impl<'t> Unpin for Parser<'t>

§

impl<'t> UnwindSafe for Parser<'t>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.