Skip to content

Commit

Permalink
Merge pull request #121 from lucalewin/node_file_structure
Browse files Browse the repository at this point in the history
Node file structure
  • Loading branch information
jaytaph authored Oct 10, 2023
2 parents 4feaabc + eac7f31 commit 7f61c56
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/html5_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ pub mod element_class;
pub mod error_logger;
pub mod input_stream;
pub mod node;
mod node_arena;
pub mod node_data;
pub mod parser;
pub mod tokenizer;
11 changes: 7 additions & 4 deletions src/html5_parser/node.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::html5_parser::element_class::ElementClass;
use crate::html5_parser::node_data::comment_data::CommentData;
use crate::html5_parser::node_data::document_data::DocumentData;
use crate::html5_parser::node_data::element_data::ElementData;
use crate::html5_parser::node_data::text_data::TextData;
use crate::html5_parser::node::data::comment::CommentData;
use crate::html5_parser::node::data::document::DocumentData;
use crate::html5_parser::node::data::element::ElementData;
use crate::html5_parser::node::data::text::TextData;
use derive_more::Display;
use std::collections::HashMap;

Expand All @@ -13,6 +13,9 @@ pub const XLINK_NAMESPACE: &str = "http://www.w3.org/1999/xlink";
pub const XML_NAMESPACE: &str = "http://www.w3.org/XML/1998/namespace";
pub const XMLNS_NAMESPACE: &str = "http://www.w3.org/2000/xmlns/";

pub mod arena;
pub mod data;

/// Different types of nodes
#[derive(Debug, PartialEq)]
pub enum NodeType {
Expand Down
8 changes: 7 additions & 1 deletion src/html5_parser/node_arena.rs → src/html5_parser/node/arena.rs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::html5_parser::node::Node;
use std::collections::HashMap;

use super::node::NodeId;
use super::NodeId;

pub struct NodeArena {
nodes: HashMap<NodeId, Node>, // Current nodes
Expand Down Expand Up @@ -85,6 +85,12 @@ impl NodeArena {
}
}

impl Default for NodeArena {
fn default() -> Self {
Self::new()
}
}

fn has_child_recursive(arena: &mut NodeArena, parent_id: NodeId, child_id: NodeId) -> bool {
let node = arena.get_node_mut(parent_id).cloned();
if node.is_none() {
Expand Down
4 changes: 4 additions & 0 deletions src/html5_parser/node/data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod comment;
pub mod document;
pub mod element;
pub mod text;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions src/html5_parser/node_data.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/html5_parser/nodes.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/html5_parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use super::node::NodeId;
use crate::html5_parser::element_class::ElementClass;
use crate::html5_parser::error_logger::{ErrorLogger, ParseError, ParserError};
use crate::html5_parser::input_stream::InputStream;
use crate::html5_parser::node::data::text::TextData;
use crate::html5_parser::node::{Node, NodeData, HTML_NAMESPACE, MATHML_NAMESPACE, SVG_NAMESPACE};
use crate::html5_parser::node_data::text_data::TextData;
use crate::html5_parser::parser::adoption_agency::AdoptionResult;
use crate::html5_parser::parser::attr_replacements::{
MATHML_ADJUSTMENTS, SVG_ADJUSTMENTS, XML_ADJUSTMENTS,
Expand Down
2 changes: 1 addition & 1 deletion src/html5_parser/parser/adoption_agency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::html5_parser::node::data::element::ElementData;
use crate::html5_parser::node::{Node, NodeData, NodeId, HTML_NAMESPACE};
use crate::html5_parser::node_data::element_data::ElementData;
use crate::html5_parser::parser::{ActiveElement, Html5Parser, Scope};
use crate::html5_parser::tokenizer::token::Token;
use std::collections::HashMap;
Expand Down
6 changes: 2 additions & 4 deletions src/html5_parser/parser/document.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::html5_parser::node::arena::NodeArena;
use crate::html5_parser::node::data::{comment::CommentData, element::ElementData, text::TextData};
use crate::html5_parser::node::NodeTrait;
use crate::html5_parser::node::NodeType;
use crate::html5_parser::node::{Node, NodeData, NodeId};
use crate::html5_parser::node_arena::NodeArena;
use crate::html5_parser::node_data::{
comment_data::CommentData, element_data::ElementData, text_data::TextData,
};
use crate::html5_parser::parser::quirks::QuirksMode;
use crate::html5_parser::parser::HashMap;
use std::fmt;
Expand Down

0 comments on commit 7f61c56

Please sign in to comment.