Skip to content

Instantly share code, notes, and snippets.

@J-Cake
Last active February 7, 2023 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save J-Cake/af12057bfcd832dc919711378a53fa0a to your computer and use it in GitHub Desktop.
Save J-Cake/af12057bfcd832dc919711378a53fa0a to your computer and use it in GitHub Desktop.
This program demonstrates the setup I'm using to explain the weird behaviour I'm getting
fn parse_function_call(tokens: &[Token]) -> Result<ASTNode, SyntaxError> {
if /* Check if syntax is valid */ {
return Err(SyntaxError::InvalidToken);
}
// ...
}
fn parse_mathematical_expression(tokens: &[Token]) -> Result<ASTNode, SyntaxError> {
if /* Check if syntax is valid */ {
return Err(SyntaxError::InvalidSyntax);
}
// ...
}
pub fn parse(tokens: &[Token]) -> Result<Box<ASTNode>, SyntaxError> {
if let Ok(call) = parse_function_call(tokens) {
return Ok(Box::new(call));
}
if let Ok(expr) = parse_mathematical_expression(tokens) {
return Ok(Box::new(expr));
}
Err(SyntaxError::UnexpectedToken(tokens.get(0).unwrap()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment