From 1995f8a8f2cb5ea810afc173fe8dfa2f5355f684 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Wed, 12 Feb 2025 10:14:15 +1300 Subject: Separate syntactic and semantic token types by namespace This will allow type names to be shared by both types of token. --- src/main.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 0086496..32f4f5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,11 +129,13 @@ fn write_bytes_and_exit>(bytes: &[u8], path: Option<&P>) -> ! { } -fn report_syntactic_errors(syntactic_tokens: &[SyntacticToken], source_code: &str) { +fn report_syntactic_errors(syntactic_tokens: &[syntactic::Token], source_code: &str) { + use syntactic::*; + for token in syntactic_tokens { let context = Context { source_code: &source_code, source: &token.source }; match &token.variant { - SyntacticTokenVariant::ConstantExpression(expr) => for t in &expr.tokens { + TokenVariant::ConstantExpression(expr) => for t in &expr.tokens { let context = Context { source_code: &source_code, source: &t.source }; if let ConstantExpressionTokenVariant::Error(err) = &t.variant { let ConstantExpressionParseError::InvalidHexadecimalLiteral(hex) = err; @@ -141,7 +143,7 @@ fn report_syntactic_errors(syntactic_tokens: &[SyntacticToken], source_code: &st report_source_issue(LogLevel::Error, &context, &message); } } - SyntacticTokenVariant::PackedBinaryLiteral(pbl) => for e in &pbl.errors { + TokenVariant::PackedBinaryLiteral(pbl) => for e in &pbl.errors { let context = Context { source_code: &source_code, source: &e.source }; match e.variant { PackedBinaryLiteralParseErrorVariant::DuplicateFieldName(name) => { @@ -154,20 +156,20 @@ fn report_syntactic_errors(syntactic_tokens: &[SyntacticToken], source_code: &st } } } - SyntacticTokenVariant::Error(err) => match err { - SyntacticParseError::InvalidHexadecimalLiteral(hex) => { + TokenVariant::Error(err) => match err { + ParseError::InvalidHexadecimalLiteral(hex) => { let message = format!("Invalid hexadecimal literal {hex:?}"); report_source_issue(LogLevel::Error, &context, &message); } - SyntacticParseError::InvalidSymbolIdentifier(name) => { + ParseError::InvalidSymbolIdentifier(name) => { let message = format!("Invalid identifier {name:?}"); report_source_issue(LogLevel::Error, &context, &message); } - SyntacticParseError::UnterminatedComment => { + ParseError::UnterminatedComment => { let message = format!("Unterminated comment"); report_source_issue(LogLevel::Error, &context, &message); } - SyntacticParseError::UnterminatedConstantExpression => { + ParseError::UnterminatedConstantExpression => { let message = format!("Unterminated constant expression"); report_source_issue(LogLevel::Error, &context, &message); } -- cgit v1.2.3-70-g09d2