Skip to content

Commit

Permalink
Split tag parsing into methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chinedufn committed Mar 5, 2019
1 parent 6adf0c6 commit 877ab50
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
9 changes: 4 additions & 5 deletions crates/html-macro/src/parser/braced.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::parser::{is_self_closing, HtmlParser};
use crate::tag::{Attr, Tag};
use proc_macro2::{Ident, Span};
use quote::{quote, quote_spanned};
use crate::parser::HtmlParser;
use proc_macro2::Ident;
use quote::quote;
use syn::spanned::Spanned;
use syn::{Block, Expr};
use syn::Block;

impl HtmlParser {
/// Parse an incoming Tag::Braced text node
Expand Down
7 changes: 1 addition & 6 deletions crates/html-macro/src/parser/close_tag.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
use crate::parser::{is_self_closing, HtmlParser};
use crate::tag::{Attr, Tag};
use proc_macro2::Ident;
use quote::{quote, quote_spanned};
use syn::Expr;
use quote::quote_spanned;

impl HtmlParser {
/// Parse an incoming Tag::Close
pub(crate) fn parse_close_tag(&mut self, name: Ident) {
let idx = &mut self.current_idx;
let parent_to_children = &mut self.parent_to_children;
let parent_stack = &mut self.parent_stack;
let tokens = &mut self.tokens;
let node_order = &mut self.node_order;

let close_span = name.span();
let close_tag = name.to_string();
Expand Down
44 changes: 22 additions & 22 deletions crates/html-macro/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use proc_macro2::LineColumn;
use quote::{quote, quote_spanned};
use std::collections::HashMap;
use syn::export::Span;
use syn::group::parse_braces;
use syn::spanned::Spanned;
use syn::{Expr, Ident};
use syn::Ident;

mod braced;
mod close_tag;
Expand Down Expand Up @@ -56,12 +54,6 @@ impl HtmlParser {
/// Generate the tokens for the incoming Tag and update our parser's heuristics that keep
/// track of information about what we've parsed.
pub fn push_tag(&mut self, tag: Tag) {
let idx = &mut self.current_idx;
let parent_stack = &mut self.parent_stack;
let node_order = &mut self.node_order;
let parent_to_children = &mut self.parent_to_children;
let tokens = &mut self.tokens;

match tag {
Tag::Open { name, attrs } => {
self.parse_open_tag(name, attrs);
Expand Down Expand Up @@ -129,22 +121,14 @@ impl HtmlParser {
};
node
}
}

// TODO: Cache this as a HashSet inside of our parser
fn is_self_closing(tag: &str) -> bool {
let whitelist = [
"area", "base", "br", "col", "hr", "img", "input", "link", "meta", "param", "command",
"keygen", "source",
];

for whitelisted in whitelist.iter() {
if &tag == whitelisted {
return true;
}
/// Set the location of the most recent start tag's ending LineColumn
fn set_most_recent_start_tag_end (&mut self, span: Span) {
}

return false;
/// Set the location of the most recent start tag's ending LineColumn
fn set_most_recent_block_start (&mut self, span: Span) {
}
}

/// Keep track of the locations of different kinds of tokens that we encounter.
Expand All @@ -161,3 +145,19 @@ struct RecentSpanLocations {
most_recent_start_tag_end: Option<LineColumn>,
most_recent_block_start: Option<LineColumn>,
}

// TODO: Cache this as a HashSet inside of our parser
fn is_self_closing(tag: &str) -> bool {
let whitelist = [
"area", "base", "br", "col", "hr", "img", "input", "link", "meta", "param", "command",
"keygen", "source",
];

for whitelisted in whitelist.iter() {
if &tag == whitelisted {
return true;
}
}

return false;
}
2 changes: 1 addition & 1 deletion crates/html-macro/src/parser/open_tag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::parser::{is_self_closing, HtmlParser};
use crate::tag::{Attr, Tag};
use crate::tag::Attr;
use proc_macro2::Ident;
use quote::quote;
use syn::Expr;
Expand Down
6 changes: 2 additions & 4 deletions crates/html-macro/src/parser/text.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::parser::{is_self_closing, HtmlParser};
use crate::tag::{Attr, Tag};
use crate::parser::HtmlParser;
use proc_macro2::{Ident, Span};
use quote::{quote, quote_spanned};
use syn::Expr;
use quote::quote;

impl HtmlParser {
/// Parse an incoming Tag::Text text node
Expand Down
2 changes: 1 addition & 1 deletion crates/html-macro/src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn parse_block(input: &mut ParseStream) -> Result<Tag> {

fn parse_text_node(input: &mut ParseStream) -> Result<Tag> {
// Continue parsing tokens until we see a closing tag <
let text_tokens = TokenStream::new();
let _text_tokens = TokenStream::new();

let mut text = "".to_string();

Expand Down

0 comments on commit 877ab50

Please sign in to comment.