-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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