From 06a6fb34c187dc02a7916290d074cd4bf11a412a Mon Sep 17 00:00:00 2001 From: Ethiraric Date: Sun, 19 Nov 2023 16:36:04 +0100 Subject: [PATCH] Handle "!!" tag overriding. --- saphyr/src/parser.rs | 20 +++++++++++++------- saphyr/tests/yaml-test-suite.rs | 4 ---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/saphyr/src/parser.rs b/saphyr/src/parser.rs index 433de60..62ffd6f 100644 --- a/saphyr/src/parser.rs +++ b/saphyr/src/parser.rs @@ -948,14 +948,20 @@ impl> Parser { /// Resolve a tag from the handle and the suffix. fn resolve_tag(&self, mark: Marker, handle: &str, suffix: String) -> Result { if handle == "!!" { - // "!!" is a shorthand for "tag:yaml.org,2002:". - Ok(Tag { - handle: "tag:yaml.org,2002:".to_string(), - suffix, - }) + // "!!" is a shorthand for "tag:yaml.org,2002:". However, that default can be + // overridden. + match self.tags.get("!!") { + Some(prefix) => Ok(Tag { + handle: prefix.to_string(), + suffix, + }), + None => Ok(Tag { + handle: "tag:yaml.org,2002:".to_string(), + suffix, + }), + } } else if handle.is_empty() && suffix == "!" { - // "!" is a shorthand for "whatever would be the default". However, that - // default can be overridden. + // "!" introduces a local tag. Local tags may have their prefix overridden. match self.tags.get("") { Some(prefix) => Ok(Tag { handle: prefix.to_string(), diff --git a/saphyr/tests/yaml-test-suite.rs b/saphyr/tests/yaml-test-suite.rs index bd57d15..204cdb6 100644 --- a/saphyr/tests/yaml-test-suite.rs +++ b/saphyr/tests/yaml-test-suite.rs @@ -297,10 +297,6 @@ fn expected_events(expected_tree: &str) -> Vec { #[rustfmt::skip] static EXPECTED_FAILURES: &[&str] = &[ - // These seem to be API limited (not enough information on the event stream level) - // Cannot resolve tag namespaces - "P76L", // overriding the `!!` namespace! - // These seem to be plain bugs // Leading TAB in literal scalars "96NN-00",