Skip to content

✨ feat(mq-lang): replace XML parser with native quick-xml builtin#1464

Merged
harehare merged 5 commits intomainfrom
feat/native-xml-parse-builtin
Mar 17, 2026
Merged

✨ feat(mq-lang): replace XML parser with native quick-xml builtin#1464
harehare merged 5 commits intomainfrom
feat/native-xml-parse-builtin

Conversation

@harehare
Copy link
Copy Markdown
Owner

No description provided.

Replace the mq-lang XML parser implementation with a native `_xml_parse`
builtin backed by the `quick-xml` crate, consistent with the JSON and
toon-format native builtin migrations.
Copilot AI review requested due to automatic review settings March 17, 2026 13:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a native Rust-backed XML parser in mq-lang using quick-xml, replacing the previous mq-script implementation and wiring it into the existing xml::xml_parse module API.

Changes:

  • Added _xml_parse builtin implemented via quick-xml that returns the existing {tag, attributes, children, text} structure.
  • Updated modules/xml.mq to delegate XML parsing to the new builtin.
  • Added quick-xml dependency, registered builtin dispatch/docs, and added Rust unit tests for the new builtin.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 7 comments.

File Description
crates/mq-lang/src/eval/builtin.rs Adds _xml_parse builtin + dispatch/doc entries + unit tests.
crates/mq-lang/modules/xml.mq Replaces mq-script XML parsing implementation with a thin wrapper calling _xml_parse.
crates/mq-lang/Cargo.toml Adds quick-xml dependency needed by the new builtin.
Cargo.lock Records the new quick-xml dependency resolution.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings March 17, 2026 13:50
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a native XML parsing builtin to mq-lang using quick-xml, replacing the previous pure-mq implementation in the xml module.

Changes:

  • Introduces a new internal builtin function _xml_parse implemented in Rust via quick-xml.
  • Updates xml::xml_parse to delegate to _xml_parse instead of the old mq-based XML parser.
  • Adds quick-xml as a dependency and includes unit tests + builtin documentation for _xml_parse.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

File Description
crates/mq-lang/src/eval/builtin.rs Adds _xml_parse builtin implementation, dispatch wiring, docs entry, and Rust unit tests.
crates/mq-lang/modules/xml.mq Replaces mq-based XML parsing with a call to the new _xml_parse builtin.
crates/mq-lang/Cargo.toml Adds quick-xml dependency for the new builtin.
Cargo.lock Locks quick-xml and its transitive dependencies.

Comment on lines +2415 to +2429
return Err(Error::Runtime(format!(
"XML parse error at position {}: {}",
reader.buffer_position(),
e
)));
}
_ => (),
}
buf.clear();
}

Ok(root.unwrap_or(RuntimeValue::NONE))
}
[a] => Err(Error::InvalidTypes(ident.to_string(), vec![std::mem::take(a)])),
_ => unreachable!(),
Comment on lines +2353 to +2359
let mut dict = BTreeMap::new();
dict.insert(Ident::new("tag"), RuntimeValue::String(tag));
dict.insert(Ident::new("attributes"), RuntimeValue::Dict(attrs));
dict.insert(Ident::new("children"), RuntimeValue::Array(children));
dict.insert(
Ident::new("text"),
text.map(RuntimeValue::String).unwrap_or(RuntimeValue::NONE),
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 17, 2026

Merging this PR will not alter performance

✅ 29 untouched benchmarks


Comparing feat/native-xml-parse-builtin (7400751) with main (2bc9bec)

Open in CodSpeed

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings March 17, 2026 14:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a native Rust XML parsing builtin in mq-lang using quick-xml, and rewires the xml module to use it instead of the previous pure-mq XML parser implementation.

Changes:

  • Add _xml_parse builtin implemented with quick-xml and register it in the builtin lookup + internal docs.
  • Simplify modules/xml.mq so xml_parse(...) delegates to the new _xml_parse(...).
  • Add quick-xml as a dependency (and update Cargo.lock accordingly), plus unit tests for basic XML parsing scenarios.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
crates/mq-lang/src/eval/builtin.rs Implements and registers _xml_parse, documents it, and adds tests.
crates/mq-lang/modules/xml.mq Replaces the old mq-based XML parser with a thin wrapper around _xml_parse.
crates/mq-lang/Cargo.toml Adds quick-xml dependency required by the new builtin.
Cargo.lock Locks quick-xml and its transitive dependencies.

Comment on lines +2316 to +2321
let key = String::from_utf8_lossy(attr.key.as_ref()).to_string();
let value = attr
.decode_and_unescape_value(reader.decoder())
.map_err(|e| Error::Runtime(format!("XML attribute value error: {}", e)))?
.to_string();
attrs.insert(Ident::new(&key), RuntimeValue::String(value));
Comment on lines +2352 to +2359
let mut dict = BTreeMap::new();
dict.insert(Ident::new("tag"), RuntimeValue::String(tag));
dict.insert(Ident::new("attributes"), RuntimeValue::Dict(attrs));
dict.insert(Ident::new("children"), RuntimeValue::Array(children));
dict.insert(
Ident::new("text"),
text.map(RuntimeValue::String).unwrap_or(RuntimeValue::NONE),
);
Comment on lines +2386 to +2415
Ok(quick_xml::events::Event::Text(e)) => {
if let Some(parent) = stack.last_mut() {
let text = reader
.decoder()
.decode(e.as_ref())
.map_err(|e| Error::Runtime(format!("XML text error: {}", e)))?
.to_string();

if !text.is_empty() {
match &mut parent.3 {
Some(t) => t.push_str(&text),
None => parent.3 = Some(text),
}
}
}
}
Ok(quick_xml::events::Event::CData(e)) => {
if let Some(parent) = stack.last_mut() {
let text = reader
.decoder()
.decode(e.as_ref())
.map_err(|e| Error::Runtime(format!("XML CDATA error: {}", e)))?
.to_string();
match &mut parent.3 {
Some(t) => t.push_str(&text),
None => parent.3 = Some(text),
}
}
}
Ok(quick_xml::events::Event::Eof) => break,
thiserror = {workspace = true}
url = {workspace = true}
toon-format = { version = "0.4", default-features = false }
quick-xml = "0.39.2"
@harehare harehare merged commit 41d0cae into main Mar 17, 2026
10 checks passed
@harehare harehare deleted the feat/native-xml-parse-builtin branch March 17, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants