Skip to main content

Parser

Struct Parser 

struct Parser<'a> {
    arena: &'a Arena,
    declarations: Vec<(&'a Name, usize)>,
    depth: usize,
    doc: DocBlock<'a>,
    lexer: Lexer<'a>,
    line_breaks: usize,
    peeked: Option<Token<'a>>,
    references: Vec<(&'a Name, usize)>,
}
Available on crate feature parse only.
Expand description

Recursive descent parser for interface definitions.

Fields§

§arena: &'a Arena§declarations: Vec<(&'a Name, usize)>

Names of the declarations with their offsets, to locate errors.

§depth: usize

Nesting level of the type being parsed.

§doc: DocBlock<'a>§lexer: Lexer<'a>§line_breaks: usize

Line breaks since the last comment line or token.

§peeked: Option<Token<'a>>§references: Vec<(&'a Name, usize)>

References to types with their offsets, to locate errors.

Implementations§

§

impl<'a> Parser<'a>

fn bump(&mut self) -> Option<Token<'a>>

Consumes the next token.

fn composite(&mut self) -> Result<Composite<'a>, ParseError>

fn enum_rest( &mut self, first: &'a FieldName, first_doc: Option<&'a Doc>, ) -> Result<&'a [Variant<'a>], ParseError>

Parses the variants of an enum after the first one.

fn struct_rest( &mut self, first: &'a FieldName, first_doc: Option<&'a Doc>, ) -> Result<&'a [Field<'a>], ParseError>

Parses the fields of a struct after the type of the first one.

fn eat(&mut self, kind: Kind<'_>) -> bool

Consumes the next token if it is of the kind kind.

fn expect( &mut self, kind: Kind<'_>, expected: Expected, ) -> Result<(), ParseError>

fn field_name(&mut self) -> Result<&'a FieldName, ParseError>

fn fields(&mut self) -> Result<&'a [Field<'a>], ParseError>

Parses fields between parentheses, where an enum isn’t allowed.

fn interface(self) -> Result<Interface<'a>, ParseError>

fn list_continues(&mut self) -> Result<bool, ParseError>

Consumes a , and returns true, or consumes a ) and returns false.

fn locate(&self, error: ValidationError<'_>) -> ParseError

Turns a rule violation into an error at the name it refers to.

A duplicate declaration points at its second occurrence, an invalid reference at its first one.

fn member_name(&mut self) -> Result<&'a Name, ParseError>

Parses the name of a declaration and records where it is.

fn error_def( &mut self, doc: Option<&'a Doc>, ) -> Result<ErrorDef<'a>, ParseError>

fn method(&mut self, doc: Option<&'a Doc>) -> Result<Method<'a>, ParseError>

fn next_significant(&mut self) -> Option<Token<'a>>

Returns the next token that isn’t a comment or a line break.

Comments and line breaks on the way update the doc block.

fn kind(&mut self) -> Result<TypeKind<'a>, ParseError>

Parses the kind of a type.

fn offset(&mut self) -> usize

Returns the byte offset of the next token.

fn peek(&mut self) -> Option<Token<'a>>

fn take_doc(&mut self) -> Option<&'a Doc>

Returns the doc comment for the next token.

fn ty(&mut self) -> Result<Type<'a>, ParseError>

fn type_def(&mut self, doc: Option<&'a Doc>) -> Result<TypeDef<'a>, ParseError>

fn word(&mut self, expected: Expected) -> Result<(&'a str, usize), ParseError>

Consumes a word and returns it with its offset.

Trait Implementations§

§

impl<'a> Debug for Parser<'a>

§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Parser<'a>

§

impl<'a> !Send for Parser<'a>

§

impl<'a> !Sync for Parser<'a>

§

impl<'a> !UnwindSafe for Parser<'a>

§

impl<'a> Freeze for Parser<'a>

§

impl<'a> Unpin for Parser<'a>

§

impl<'a> UnsafeUnpin for Parser<'a>

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>,

Source§

type Error = !

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>,

Source§

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.