pub struct ImpParser<'i> {
pub file: Name,
pub input: &'i str,
pub index: usize,
pub builtin: bool,
}
Fields§
§file: Name
§input: &'i str
§index: usize
§builtin: bool
Implementations§
Source§impl<'a> ImpParser<'a>
impl<'a> ImpParser<'a>
pub fn new(file: Name, input: &'a str, builtin: bool) -> Self
pub fn parse_function_def( &mut self, indent: Indent, ) -> ParseResult<(Definition, Indent)>
pub fn parse_type_def(&mut self, indent: Indent) -> ParseResult<(Adt, Indent)>
pub fn parse_object(&mut self, indent: Indent) -> ParseResult<(Adt, Indent)>
pub fn parse_hvm(&mut self) -> ParseResult<(HvmDefinition, Indent)>
Trait Implementations§
Source§impl<'a> Parser<'a> for ImpParser<'a>
impl<'a> Parser<'a> for ImpParser<'a>
Source§fn expected<T>(&mut self, exp: &str) -> ParseResult<T>
fn expected<T>(&mut self, exp: &str) -> ParseResult<T>
Generates an error message for parsing failures, including the highlighted context.
Override to have our own error message.
Source§fn consume(&mut self, text: &str) -> ParseResult<()>
fn consume(&mut self, text: &str) -> ParseResult<()>
Consumes an instance of the given string, erroring if it is not found.
Override to have our own error message.
fn input(&mut self) -> &'a str
fn index(&mut self) -> &mut usize
Source§fn skip_trivia(&mut self)
fn skip_trivia(&mut self)
Skips whitespace & comments in the text.
Source§fn expected_and<T>(&mut self, exp: &str, msg: &str) -> Result<T, ParseError>
fn expected_and<T>(&mut self, exp: &str, msg: &str) -> Result<T, ParseError>
Generates an error message with an additional custom message.
Source§fn peek_one(&mut self) -> Option<char>
fn peek_one(&mut self) -> Option<char>
Inspects the next character in the text without consuming it.
Source§fn peek_many(&mut self, count: usize) -> Option<&'i str>
fn peek_many(&mut self, count: usize) -> Option<&'i str>
Inspects the next
count
characters in the text without consuming them.Source§fn advance_one(&mut self) -> Option<char>
fn advance_one(&mut self) -> Option<char>
Consumes the next character in the text.
Source§fn advance_many(&mut self, count: usize) -> Option<&'i str>
fn advance_many(&mut self, count: usize) -> Option<&'i str>
Advances the parser by
count
characters, consuming them.Source§fn skip_spaces(&mut self)
fn skip_spaces(&mut self)
Skips spaces in the text.
Source§fn starts_with(&mut self, text: &str) -> bool
fn starts_with(&mut self, text: &str) -> bool
Checks if the next characters in the input start with the given string.
Source§fn take_while(&mut self, f: impl FnMut(char) -> bool) -> &'i str
fn take_while(&mut self, f: impl FnMut(char) -> bool) -> &'i str
Consumes all contiguous characters matching a given predicate.
Source§fn parse_name(&mut self) -> Result<String, ParseError>
fn parse_name(&mut self) -> Result<String, ParseError>
Parses a name from the input, supporting alphanumeric characters, underscores, periods, and hyphens.
Source§fn parse_u64(&mut self) -> Result<u64, ParseError>
fn parse_u64(&mut self) -> Result<u64, ParseError>
Parses a u64 from the input, supporting dec, hex (0xNUM), and bin (0bNUM).
Source§fn parse_char(&mut self) -> Result<char, ParseError>
fn parse_char(&mut self) -> Result<char, ParseError>
Parses a single unicode character, supporting scape sequences.
Source§fn parse_quoted_char(&mut self) -> Result<char, ParseError>
fn parse_quoted_char(&mut self) -> Result<char, ParseError>
Parses a quoted character, like ‘x’.
Source§fn parse_quoted_string(&mut self) -> Result<String, ParseError>
fn parse_quoted_string(&mut self) -> Result<String, ParseError>
Parses a quoted string, like “foobar”.
Source§impl<'a> ParserCommons<'a> for ImpParser<'a>
impl<'a> ParserCommons<'a> for ImpParser<'a>
fn labelled<T>( &mut self, parser: impl Fn(&mut Self) -> ParseResult<T>, label: &str, ) -> ParseResult<T>
fn parse_restricted_name(&mut self, kind: &str) -> ParseResult<Name>
fn parse_top_level_name(&mut self) -> ParseResult<Name>
fn parse_var_name(&mut self) -> ParseResult<Name>
fn parse_name_maybe_alias( &mut self, label: &str, ) -> ParseResult<(Name, Option<Name>)>
fn parse_import_name( &mut self, label: &str, ) -> ParseResult<(Name, Option<Name>, bool)>
Source§fn consume_exactly(&mut self, text: &str) -> ParseResult<()>
fn consume_exactly(&mut self, text: &str) -> ParseResult<()>
Consumes exactly the text without skipping.
fn consume_new_line(&mut self) -> ParseResult<()>
Source§fn advance_newlines(&mut self) -> ParseResult<Indent>
fn advance_newlines(&mut self) -> ParseResult<Indent>
Skips trivia, returns the number of trivia characters skipped in the last line.
Source§fn advance_trivia_inline(&mut self) -> ParseResult<isize>
fn advance_trivia_inline(&mut self) -> ParseResult<isize>
Advances the parser to the next non-trivia character in the same line.
Returns how many characters were advanced.
Source§fn skip_trivia_inline(&mut self) -> ParseResult<()>
fn skip_trivia_inline(&mut self) -> ParseResult<()>
Skips until the next non-trivia character in the same line.
fn expected_spanned<T>( &mut self, exp: &str, span: Range<usize>, ) -> ParseResult<T>
Source§fn expected_spanned_and<T>(
&mut self,
exp: &str,
msg: &str,
span: Range<usize>,
) -> ParseResult<T>
fn expected_spanned_and<T>( &mut self, exp: &str, msg: &str, span: Range<usize>, ) -> ParseResult<T>
Same as
expected_spanned
but adds an information message before the expected message.Source§fn err_msg_spanned<T>(
&mut self,
msg: &str,
span: Range<usize>,
) -> ParseResult<T>
fn err_msg_spanned<T>( &mut self, msg: &str, span: Range<usize>, ) -> ParseResult<T>
If the parser result is an error, adds code location information to the error message.
Source§fn with_ctx<T>(
&mut self,
res: Result<T, impl Display>,
span: Range<usize>,
) -> ParseResult<T>
fn with_ctx<T>( &mut self, res: Result<T, impl Display>, span: Range<usize>, ) -> ParseResult<T>
If the parser result is an error, adds highlighted code context to the message.
Source§fn try_consume(&mut self, text: &str) -> bool
fn try_consume(&mut self, text: &str) -> bool
Consumes text if the input starts with it or trivia. Otherwise, do nothing.
Source§fn try_consume_exactly(&mut self, text: &str) -> bool
fn try_consume_exactly(&mut self, text: &str) -> bool
Consumes text if the input starts exactly with it. Otherwise, do nothing.
fn try_parse_keyword(&mut self, keyword: &str) -> bool
fn parse_keyword(&mut self, keyword: &str) -> ParseResult<()>
fn starts_with_keyword(&mut self, keyword: &str) -> bool
Source§fn list_like<T>(
&mut self,
parser: impl FnMut(&mut Self) -> ParseResult<T>,
start: &str,
end: &str,
sep: &str,
hard_sep: bool,
min_els: usize,
) -> ParseResult<Vec<T>>
fn list_like<T>( &mut self, parser: impl FnMut(&mut Self) -> ParseResult<T>, start: &str, end: &str, sep: &str, hard_sep: bool, min_els: usize, ) -> ParseResult<Vec<T>>
Parses a list-like structure like “[x1, x2, x3,]”.
Since a list is always well terminated, we consume newlines. Read more
fn try_parse_oper(&mut self) -> Option<Op>
fn peek_oper(&mut self) -> Option<Op>
fn parse_u32(&mut self) -> ParseResult<u32>
fn u32_with_radix(&mut self, radix: Radix) -> ParseResult<u32>
fn parse_number(&mut self) -> ParseResult<Num>
fn num_range_err<T>(&mut self, ini_idx: usize, typ: &str) -> ParseResult<T>
Source§fn parse_quoted_symbol(&mut self) -> ParseResult<u32>
fn parse_quoted_symbol(&mut self) -> ParseResult<u32>
Parses up to 4 base64 characters surrounded by “`”.
Joins the characters into a u24 and returns it.
fn check_repeated_ctr_fields( &mut self, fields: &[CtrField], ctr_name: &Name, span: Range<usize>, ) -> ParseResult<()>
fn redefinition_of_function_msg(builtin: bool, function_name: &str) -> String
fn redefinition_of_hvm_msg(builtin: bool, function_name: &str) -> String
fn redefinition_of_constructor_msg(constructor_name: &str) -> String
fn redefinition_of_type_msg(type_name: &str) -> String
Auto Trait Implementations§
impl<'i> Freeze for ImpParser<'i>
impl<'i> RefUnwindSafe for ImpParser<'i>
impl<'i> Send for ImpParser<'i>
impl<'i> Sync for ImpParser<'i>
impl<'i> Unpin for ImpParser<'i>
impl<'i> UnwindSafe for ImpParser<'i>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more