diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-03-23 11:39:00 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-03-23 11:39:00 +1300 |
commit | 38765b156cdb7a6018d40f4c8f0de4f7ad4fb208 (patch) | |
tree | fcb8478879205c453c851c88434cb761f42e32b6 | |
parent | 315d23bf2148e831b0c14a118841133aacc1fb96 (diff) | |
download | torque-asm-octal-literals.zip |
Implement octal literalsoctal-literals
Octal literals are prefixed by '0o'.
-rw-r--r-- | src/stages/syntactic.rs | 6 | ||||
-rw-r--r-- | src/stages/syntactic_tokens.rs | 3 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/stages/syntactic.rs b/src/stages/syntactic.rs index 14f8815..d23f8cb 100644 --- a/src/stages/syntactic.rs +++ b/src/stages/syntactic.rs @@ -180,6 +180,12 @@ fn parse_syntactic_from_tokeniser(mut t: Tokeniser) -> Result<Vec<Tracked<Syntac Ok(value) => SyntacticToken::IntegerLiteral(value), Err(_) => err!(SyntacticError::InvalidBinaryLiteral(binary_string)), } + } else if let Some(octal_string) = token.strip_prefix("0o") { + let octal_string = octal_string.to_string(); + match parse_integer_literal(&octal_string, 8) { + Ok(value) => SyntacticToken::IntegerLiteral(value), + Err(_) => err!(SyntacticError::InvalidOctalLiteral(octal_string)), + } } else { match parse_integer_literal(&token, 10) { Ok(value) => SyntacticToken::IntegerLiteral(value), diff --git a/src/stages/syntactic_tokens.rs b/src/stages/syntactic_tokens.rs index 041c568..5bfa0be 100644 --- a/src/stages/syntactic_tokens.rs +++ b/src/stages/syntactic_tokens.rs @@ -70,6 +70,7 @@ pub enum SyntacticError { InvalidDecimalLiteral(String), InvalidHexadecimalLiteral(String), InvalidBinaryLiteral(String), + InvalidOctalLiteral(String), } @@ -118,6 +119,8 @@ fn report_syntactic_error(error: &Tracked<SyntacticError>, source_code: &str) { &format!("The string '{string}' is not a valid hexadecimal literal"), SyntacticError::InvalidBinaryLiteral(string) => &format!("The string '{string}' is not a valid binary literal"), + SyntacticError::InvalidOctalLiteral(string) => + &format!("The string '{string}' is not a valid octal literal"), }; report_source_issue(LogLevel::Error, &context, message); |