From 365f5d60a2961be9bdb82995525ad86df3f4eab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 27 Jul 2023 23:52:09 +0200 Subject: [PATCH] interpreter: feed in default namespaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- src/interpreter.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/interpreter.rs b/src/interpreter.rs index a2af08c..ac852c0 100644 --- a/src/interpreter.rs +++ b/src/interpreter.rs @@ -13,12 +13,13 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use crate::element::ScanElement; +use crate::element::{ScanElement, DEFAULT_NS, SCANSION_NS}; use crate::parsers::{parse_spec, Token}; use crate::types::{Action, Context, Entity, Spec}; use jid::Jid; use minidom::{Element, Error as MinidomError}; use rand::{thread_rng, Rng}; +use std::collections::BTreeMap; #[cfg_attr(test, derive(PartialEq))] #[derive(Debug)] @@ -82,16 +83,30 @@ pub fn read_actions(spec: Spec, context: &Context) -> Result()?; - inout.receives(ScanElement::new(elem).with_context(Some(&context))); + let prefixes: BTreeMap, String> = { + let mut tmp = BTreeMap::new(); + tmp.insert(None, String::from(DEFAULT_NS)); + tmp.insert(Some(String::from("scansion")), String::from(SCANSION_NS)); + tmp + }; + + let elem = Element::from_reader_with_prefixes(s.as_ref(), prefixes)?; + inout.receives(ScanElement::new(elem).apply_context(&context)); } Action::Send(name, s) => { let _ = context .get(&name) .expect(format!("Name '{}' not found in clients", name).as_str()); - let elem = s.parse::()?; - inout.sends(ScanElement::new(elem).with_context(Some(&context))); + let prefixes: BTreeMap, String> = { + let mut tmp = BTreeMap::new(); + tmp.insert(None, String::from(DEFAULT_NS)); + tmp.insert(Some(String::from("scansion")), String::from(SCANSION_NS)); + tmp + }; + + let elem = Element::from_reader_with_prefixes(s.as_ref(), prefixes)?; + inout.sends(ScanElement::new(elem).apply_context(&context)); } _ => (), }