Most of all the errors are gone
This commit is contained in:
@@ -143,7 +143,7 @@ impl<'a> Parser<'a> {
|
|||||||
/// Helper to run a parsing closure and wrap the result in a Spanned struct
|
/// Helper to run a parsing closure and wrap the result in a Spanned struct
|
||||||
fn spanned<F, T>(&mut self, parser: F) -> Result<Spanned<T>, Error<'a>>
|
fn spanned<F, T>(&mut self, parser: F) -> Result<Spanned<T>, Error<'a>>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut Self) -> Result<T, Error>,
|
F: FnOnce(&mut Self) -> Result<T, Error<'a>>,
|
||||||
{
|
{
|
||||||
let start_token = if self.current_token.is_some() {
|
let start_token = if self.current_token.is_some() {
|
||||||
self.current_token.clone()
|
self.current_token.clone()
|
||||||
@@ -269,12 +269,12 @@ impl<'a> Parser<'a> {
|
|||||||
Ok(expr)
|
Ok(expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign_next(&'a mut self) -> Result<(), Error<'a>> {
|
fn assign_next(&mut self) -> Result<(), Error<'a>> {
|
||||||
self.current_token = self.tokenizer.next_token()?;
|
self.current_token = self.tokenizer.next_token()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_next(&'a mut self) -> Result<Option<Token<'a>>, Error<'a>> {
|
fn get_next(&mut self) -> Result<Option<Token<'a>>, Error<'a>> {
|
||||||
self.assign_next()?;
|
self.assign_next()?;
|
||||||
Ok(self.current_token.clone())
|
Ok(self.current_token.clone())
|
||||||
}
|
}
|
||||||
@@ -317,7 +317,7 @@ impl<'a> Parser<'a> {
|
|||||||
self.assign_next()?; // consume Dot
|
self.assign_next()?; // consume Dot
|
||||||
|
|
||||||
let identifier_token = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
let identifier_token = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
||||||
let identifier_span = Self::token_to_span(identifier_token);
|
let identifier_span = Self::token_to_span(&identifier_token);
|
||||||
let identifier = match identifier_token.token_type {
|
let identifier = match identifier_token.token_type {
|
||||||
TokenType::Identifier(ref id) => id.clone(),
|
TokenType::Identifier(ref id) => id.clone(),
|
||||||
_ => {
|
_ => {
|
||||||
@@ -354,8 +354,8 @@ impl<'a> Parser<'a> {
|
|||||||
{
|
{
|
||||||
let next_token = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
let next_token = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
||||||
return Err(Error::UnexpectedToken(
|
return Err(Error::UnexpectedToken(
|
||||||
Self::token_to_span(next_token),
|
Self::token_to_span(&next_token),
|
||||||
next_token.clone(),
|
next_token,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,10 +495,7 @@ impl<'a> Parser<'a> {
|
|||||||
let span = self.current_span();
|
let span = self.current_span();
|
||||||
let next = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
let next = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
||||||
if !token_matches!(next, TokenType::Symbol(Symbol::Semicolon)) {
|
if !token_matches!(next, TokenType::Symbol(Symbol::Semicolon)) {
|
||||||
return Err(Error::UnexpectedToken(
|
return Err(Error::UnexpectedToken(Self::token_to_span(&next), next));
|
||||||
Self::token_to_span(next),
|
|
||||||
next.clone(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Some(Spanned {
|
Some(Spanned {
|
||||||
span,
|
span,
|
||||||
@@ -510,10 +507,7 @@ impl<'a> Parser<'a> {
|
|||||||
let span = self.current_span();
|
let span = self.current_span();
|
||||||
let next = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
let next = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
||||||
if !token_matches!(next, TokenType::Symbol(Symbol::Semicolon)) {
|
if !token_matches!(next, TokenType::Symbol(Symbol::Semicolon)) {
|
||||||
return Err(Error::UnexpectedToken(
|
return Err(Error::UnexpectedToken(Self::token_to_span(&next), next));
|
||||||
Self::token_to_span(next),
|
|
||||||
next.clone(),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
Some(Spanned {
|
Some(Spanned {
|
||||||
span,
|
span,
|
||||||
@@ -714,7 +708,7 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let identifier_token = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
let identifier_token = self.get_next()?.ok_or(Error::UnexpectedEOF)?;
|
||||||
let identifier_span = Self::token_to_span(identifier_token);
|
let identifier_span = Self::token_to_span(&identifier_token);
|
||||||
let identifier = match identifier_token.token_type {
|
let identifier = match identifier_token.token_type {
|
||||||
TokenType::Identifier(ref id) => id.clone(),
|
TokenType::Identifier(ref id) => id.clone(),
|
||||||
_ => {
|
_ => {
|
||||||
@@ -1524,8 +1518,8 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn syscall(&mut self) -> Result<SysCall<'a>, Error<'a>> {
|
fn syscall(&mut self) -> Result<SysCall<'a>, Error<'a>> {
|
||||||
fn check_length<'a>(
|
fn check_length<'a, 't: 'a>(
|
||||||
parser: &'a Parser,
|
parser: &'t Parser,
|
||||||
arguments: &[Spanned<Expression<'a>>],
|
arguments: &[Spanned<Expression<'a>>],
|
||||||
length: usize,
|
length: usize,
|
||||||
) -> Result<(), Error<'a>> {
|
) -> Result<(), Error<'a>> {
|
||||||
|
|||||||
Reference in New Issue
Block a user