diff --git a/Cargo.lock b/Cargo.lock index 3eb1f11..c044080 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,7 +67,7 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "as3_parser" -version = "0.5.20" +version = "0.5.22" dependencies = [ "bitflags", "by_address", diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 6d362a5..100afb6 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "as3_parser" -version = "0.5.20" +version = "0.5.22" edition = "2021" authors = ["hydroper "] repository = "https://github.com/hydroper/as3parser" diff --git a/crates/parser/diagnostics/diagnostics.rs b/crates/parser/diagnostics/diagnostics.rs index 2ba1cbd..ccbb8c7 100644 --- a/crates/parser/diagnostics/diagnostics.rs +++ b/crates/parser/diagnostics/diagnostics.rs @@ -1,3 +1,5 @@ +use std::any::Any; + use maplit::hashmap; use crate::ns::*; @@ -14,7 +16,7 @@ pub struct Diagnostic { pub(crate) is_warning: bool, pub(crate) is_verify_error: bool, pub(crate) arguments: Vec, - pub(crate) custom_id: RefCell>, + pub(crate) custom_kind: RefCell>>, } impl Eq for Diagnostic {} @@ -46,7 +48,7 @@ impl Diagnostic { is_verify_error: false, is_warning: false, arguments, - custom_id: RefCell::new(None), + custom_kind: RefCell::new(None), } } @@ -57,7 +59,7 @@ impl Diagnostic { is_verify_error: true, is_warning: false, arguments, - custom_id: RefCell::new(None), + custom_kind: RefCell::new(None), } } @@ -68,7 +70,7 @@ impl Diagnostic { is_verify_error: false, is_warning: true, arguments, - custom_id: RefCell::new(None), + custom_kind: RefCell::new(None), } } @@ -104,12 +106,12 @@ impl Diagnostic { self.kind.id() } - pub fn custom_id(&self) -> Option { - self.custom_id.borrow().clone() + pub fn custom_kind(&self) -> Option> { + self.custom_kind.borrow().clone() } - pub fn set_custom_id(&self, id: Option<&str>) { - self.custom_id.replace(id.map(|id| id.to_owned())); + pub fn set_custom_kind(&self, id: Option>) { + self.custom_kind.replace(id); } /// Formats the diagnostic by overriding the message text. diff --git a/docs/diagnostics.md b/docs/diagnostics.md index 35c54e8..bb508f6 100644 --- a/docs/diagnostics.md +++ b/docs/diagnostics.md @@ -47,16 +47,22 @@ The `diagnostic_arguments![]` literal takes elements in one of the forms: * `Token(token)` * `String(string)` -## Custom IDs +## Custom kinds -If you need to support your own messages, set the `custom_id` field: +If you need to support your own messages, set the `custom_kind` field: ```rust -diagnostic.set_custom_id(Some("myMessage")); +diagnostic.set_custom_kind(Some(Rc::new(kind))); ``` -Finish formatting your own message by attaching additional information with: +Where `kind` is an enumeration's variant. You may then later cast the custom kind from `Rc` to your enumeration through `.downcast::()`. -``` +If you want, for simple debugging purposes, you may finish formatting your own message with location information by using: + +```rust diagnostic.format_with_message("My message", Some(custom_id_number)) -``` \ No newline at end of file +``` + +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. \ No newline at end of file