Skip to content

Commit

Permalink
Fix XML closing tag
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed May 2, 2024
1 parent bb72e6c commit 2deb0f6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 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 = "1.0.7"
version = "1.0.8"
edition = "2021"
authors = ["hydroper <[email protected]>"]
repository = "https://github.com/hydroper/as3parser"
Expand Down
1 change: 1 addition & 0 deletions crates/parser/diagnostics/diagnostic_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum DiagnosticKind {
ExpectingDirective = 1087,
ExpectingStatement = 1088,
Unexpected = 1089,
XmlClosingTagNameMustBeEquals = 1090,
}

impl DiagnosticKind {
Expand Down
7 changes: 4 additions & 3 deletions crates/parser/diagnostics/diagnostics_english_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}
18 changes: 15 additions & 3 deletions crates/parser/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions crates/parser/tree/mxml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ impl MxmlName {
let p2 = other.resolve_prefix(namespace)?;
Ok(&p1 == &p2)
}

pub fn to_string(&self, namespace: &Rc<MxmlNamespace>) -> String {
self.resolve_name(namespace).map(|(uri, localname)| format!("{uri}:{localname}")).unwrap_or("[error]".into())
}
}

#[derive(Clone)]
Expand Down

0 comments on commit 2deb0f6

Please sign in to comment.