summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2025-02-12 10:14:15 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2025-02-12 10:14:15 +1300
commit1995f8a8f2cb5ea810afc173fe8dfa2f5355f684 (patch)
treef3aaa305f82fb7d424b59527e713ac781e5fa723 /src/main.rs
parentce47e3b24ea37748b809cb5c53b217b6474e0fd3 (diff)
downloadtorque-asm-1995f8a8f2cb5ea810afc173fe8dfa2f5355f684.zip
Separate syntactic and semantic token types by namespace
This will allow type names to be shared by both types of token.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs18
1 files changed, 10 insertions, 8 deletions
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<P: AsRef<Path>>(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);
}