Skip to content

Commit

Permalink
Diagnostic dynamic argument
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed Apr 27, 2024
1 parent 515eb11 commit 30771ba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "as3_parser"
version = "0.5.25"
version = "0.5.26"
edition = "2021"
authors = ["hydroper <[email protected]>"]
repository = "https://github.com/hydroper/as3parser"
Expand Down
6 changes: 6 additions & 0 deletions crates/parser/diagnostics/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ impl Diagnostic {
match argument {
DiagnosticArgument::String(s) => s.clone(),
DiagnosticArgument::Token(t) => t.to_string(),
DiagnosticArgument::Dynamic(d) => d.to_string(),
}
}
}
Expand All @@ -174,4 +175,9 @@ pub macro diagnostic_arguments {
pub enum DiagnosticArgument {
String(String),
Token(Token),
Dynamic(Rc<dyn DynamicDiagnosticArgument>),
}

pub trait DynamicDiagnosticArgument {
fn to_string(&self) -> String;
}
4 changes: 1 addition & 3 deletions docs/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,4 @@ If you want, for simple debugging purposes, you may finish formatting your own m
diagnostic.format_with_message("My message", Some(custom_id_number))
```

For real use cases, calling `.format_with_message()` is not preferred if your application is not solely in English, since it will add categories such as `Warning`.

Moreover, argument variants in `as3_parser::ns::Diagnostic` may not be enough. For example, a compiler may want to store a symbol argument; in this case, an extra layer over `as3_parser::ns::Diagnostic` must be provided, supporting more variants.
For real use cases, calling `.format_with_message()` is not preferred if your application is not solely in English, since it will add categories such as `Warning`.

0 comments on commit 30771ba

Please sign in to comment.