From 2deb0f622a58f434a3f98cb6ec7bb63527a6b22e Mon Sep 17 00:00:00 2001 From: hydroper Date: Thu, 2 May 2024 16:54:37 -0300 Subject: [PATCH] Fix XML closing tag --- Cargo.lock | 2 +- crates/parser/Cargo.toml | 2 +- crates/parser/diagnostics/diagnostic_kind.rs | 1 + .../diagnostics_english_resources.rs | 7 ++++--- crates/parser/parser/parser.rs | 18 +++++++++++++++--- crates/parser/tree/mxml.rs | 4 ++++ 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ad4372..54ec816 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,7 +67,7 @@ checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "as3_parser" -version = "1.0.7" +version = "1.0.8" dependencies = [ "bitflags", "by_address", diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index f8fb3aa..a1f551d 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "as3_parser" -version = "1.0.7" +version = "1.0.8" edition = "2021" authors = ["hydroper "] repository = "https://github.com/hydroper/as3parser" diff --git a/crates/parser/diagnostics/diagnostic_kind.rs b/crates/parser/diagnostics/diagnostic_kind.rs index baac4cb..e03cb70 100644 --- a/crates/parser/diagnostics/diagnostic_kind.rs +++ b/crates/parser/diagnostics/diagnostic_kind.rs @@ -67,6 +67,7 @@ pub enum DiagnosticKind { ExpectingDirective = 1087, ExpectingStatement = 1088, Unexpected = 1089, + XmlClosingTagNameMustBeEquals = 1090, } impl DiagnosticKind { diff --git a/crates/parser/diagnostics/diagnostics_english_resources.rs b/crates/parser/diagnostics/diagnostics_english_resources.rs index b7eccc2..192a7e7 100644 --- a/crates/parser/diagnostics/diagnostics_english_resources.rs +++ b/crates/parser/diagnostics/diagnostics_english_resources.rs @@ -67,9 +67,10 @@ lazy_static! { DiagnosticKind::InputEndedBeforeReachingClosingQuoteForAttributeValue.id() => "Input ended before reaching the closing quotation mark for an attribute value.".into(), DiagnosticKind::ExpectingEitherSemicolonOrNewLineHere.id() => "Expecting either a semicolon or a new line here.".into(), DiagnosticKind::CssInvalidHexEscape.id() => "Invalid hexadecimal escape: '\\{1}'.".into(), - DiagnosticKind::ExpectingDirective.id() => "Expecting directive before {1}".into(), - DiagnosticKind::ExpectingStatement.id() => "Expecting statement before {1}".into(), - DiagnosticKind::Unexpected.id() => "Unexpected {1}".into(), + DiagnosticKind::ExpectingDirective.id() => "Expecting directive before {1}.".into(), + DiagnosticKind::ExpectingStatement.id() => "Expecting statement before {1}.".into(), + DiagnosticKind::Unexpected.id() => "Unexpected {1}.".into(), + DiagnosticKind::XmlClosingTagNameMustBeEquals.id() => "Closing tag name must be equals '{1}'.".into(), // DiagnosticKind::K.id() => ".".into(), }; } \ No newline at end of file diff --git a/crates/parser/parser/parser.rs b/crates/parser/parser/parser.rs index 664a137..d424750 100644 --- a/crates/parser/parser/parser.rs +++ b/crates/parser/parser/parser.rs @@ -4885,8 +4885,14 @@ impl<'input> Parser<'input> { self.expect_and_ie_xml_content(Token::Gt); content = Some(self.parse_mxml_content(false, &namespace, encoding)); self.non_greedy_expect_and_ie_xml_tag(Token::XmlLtSlash); - let name = self.parse_xml_name(); - closing_name = Some(self.process_mxml_tag_name(name, &namespace)); + let name_1 = self.parse_xml_name(); + let closing_name_1 = self.process_mxml_tag_name(name_1, &namespace); + if let Ok(equal) = name.equals_name(&closing_name_1, &namespace) { + if !equal { + self.add_syntax_error(&closing_name_1.location, DiagnosticKind::XmlClosingTagNameMustBeEquals, diagarg![name.to_string(&namespace)]); + } + } + closing_name = Some(closing_name_1); self.consume_and_ie_xml_tag(Token::XmlWhitespace); self.non_greedy_expect_and_ie_xml_content(Token::Gt); } @@ -5094,10 +5100,16 @@ impl<'input> Parser<'input> { let element = self.parse_mxml_element(start, namespace, encoding); content.push(Rc::new(MxmlContent::Element(Rc::new(element)))); } else if !until_eof { - self.expect_and_ie_xml_content(Token::XmlLtSlash); + self.non_greedy_expect_and_ie_xml_content(Token::XmlLtSlash); if !self.tokenizer.characters().has_remaining() { break; } + } else if self.peek(Token::XmlLtSlash) { + self.add_syntax_error(&self.token_location(), DiagnosticKind::Expecting, diagarg![Token::Eof, self.token.0.clone()]); + self.next_ie_xml_tag(); + let _ = self.parse_xml_name(); + self.consume_and_ie_xml_tag(Token::XmlWhitespace); + self.non_greedy_expect_and_ie_xml_content(Token::Gt); } } content diff --git a/crates/parser/tree/mxml.rs b/crates/parser/tree/mxml.rs index 0316898..5ffacf1 100644 --- a/crates/parser/tree/mxml.rs +++ b/crates/parser/tree/mxml.rs @@ -77,6 +77,10 @@ impl MxmlName { let p2 = other.resolve_prefix(namespace)?; Ok(&p1 == &p2) } + + pub fn to_string(&self, namespace: &Rc) -> String { + self.resolve_name(namespace).map(|(uri, localname)| format!("{uri}:{localname}")).unwrap_or("[error]".into()) + } } #[derive(Clone)]