1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use quote::{quote_spanned, ToTokens};
use proc_macro2::{Span};
use syn::parse::{Parse, ParseStream, Result};
pub use crate::bracketed_expr::BracketedExpr;
pub use crate::xtext_display_expr::XtextDisplayExpr;
pub use crate::xtext_expr::XtextExpr;
pub use crate::xtext_class_attr::XtextClassAttr;
pub use crate::xtext_attr::XtextAttr;
pub use crate::xtext_class_child::XtextClassChild;
pub use crate::xtext_class::XtextClass;
pub use crate::xtext_tag::XtextTag;
pub use crate::xtext_crumb::XtextCrumb;
pub struct Xtext {
pub crumbs: Vec<XtextCrumb>
}
impl Xtext {
pub fn span(&self) -> Span {
if self.crumbs.len() > 0 {
let mut span = self.crumbs[0].span();
for c in self.crumbs[1..].iter() {
span = span.join(c.span()).unwrap_or(c.span());
}
span
} else {
Span::call_site()
}
}
}
impl ToTokens for Xtext {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let mut prev: Option<Span> = None;
for c in self.crumbs.iter() {
c.to_tokens(tokens);
}
}
}
impl Parse for Xtext {
fn parse(input: ParseStream) -> Result<Self> {
let crumbs: Vec<XtextCrumb> = input.call(XtextCrumb::parse_outer)?;
Ok(Xtext {
crumbs: crumbs
})
}
}