Skip to content

Commit

Permalink
Directive injection and XML utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed May 8, 2024
1 parent 1af9162 commit 462f55e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 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.15"
version = "1.0.16"
edition = "2021"
authors = ["hydroper <[email protected]>"]
repository = "https://github.com/hydroper/as3parser"
Expand Down
2 changes: 2 additions & 0 deletions crates/parser/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ mod normal_configuration_directive;
pub use normal_configuration_directive::*;
mod package_concat_directive;
pub use package_concat_directive::*;
mod directive_injection_node;
pub use directive_injection_node::*;

// Miscellaneous
mod attributes;
Expand Down
2 changes: 2 additions & 0 deletions crates/parser/tree/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum Directive {
IncludeDirective(IncludeDirective),
NormalConfigurationDirective(NormalConfigurationDirective),
PackageConcatDirective(PackageConcatDirective),
DirectiveInjection(DirectiveInjectionNode),
VariableDefinition(VariableDefinition),
FunctionDefinition(FunctionDefinition),
ClassDefinition(ClassDefinition),
Expand Down Expand Up @@ -68,6 +69,7 @@ impl Directive {
Self::IncludeDirective(d) => d.location.clone(),
Self::NormalConfigurationDirective(d) => d.location.clone(),
Self::PackageConcatDirective(d) => d.location.clone(),
Self::DirectiveInjection(d) => d.location.clone(),
Self::VariableDefinition(d) => d.location.clone(),
Self::FunctionDefinition(d) => d.location.clone(),
Self::ClassDefinition(d) => d.location.clone(),
Expand Down
9 changes: 9 additions & 0 deletions crates/parser/tree/directive_injection_node.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::ns::*;
use serde::{Serialize, Deserialize};

/// Node that allows modification to the directive sequence.
#[derive(Clone, Serialize, Deserialize)]
pub struct DirectiveInjectionNode {
pub location: Location,
pub directives: RefCell<Vec<Rc<Directive>>>,
}
22 changes: 22 additions & 0 deletions crates/parser/tree/mxml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ pub struct MxmlElement {
pub closing_name: Option<MxmlName>,
}

impl MxmlElement {
pub fn inner_text(&self) -> String {
let mut j = String::new();
if let Some(c) = self.content.as_ref() {
for c1 in c.iter() {
j.push_str(&c1.inner_text());
}
}
j
}
}

#[derive(Clone, Serialize, Deserialize)]
pub struct MxmlAttribute {
pub location: Location,
Expand Down Expand Up @@ -120,6 +132,16 @@ impl MxmlContent {
Self::Element(e) => e.location.clone(),
}
}

pub fn inner_text(&self) -> String {
match self {
Self::Characters((data, _)) => data.clone(),
Self::CData((data, _)) => data["<![CDATA[".len()..(data.len() - 3)].to_owned(),
Self::Comment(_) => String::new(),
Self::ProcessingInstruction { .. } => String::new(),
Self::Element(e) => e.inner_text(),
}
}
}

/// Mapping of namespace prefixes.
Expand Down

0 comments on commit 462f55e

Please sign in to comment.