add: improve syntax
This commit is contained in:
parent
55130db04a
commit
149025f9e4
7 changed files with 52 additions and 34 deletions
|
@ -37,12 +37,6 @@ pub fn string_parser(buf: impl Iterator<Item = char>, buffer: &mut String) {
|
|||
///
|
||||
/// # Returns
|
||||
/// `(key, value)`
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// attr_parser("(attr \"a\" \"b\")");
|
||||
/// ```
|
||||
pub fn attr_parser(buf: &str) -> (String, String) {
|
||||
let mut key: String = String::new();
|
||||
let mut value: String = String::new();
|
||||
|
@ -134,8 +128,15 @@ pub fn expr_parser(buf: &str) -> Element {
|
|||
}
|
||||
|
||||
return element;
|
||||
} else if (element.tag == "attr") | (element.tag == ":") {
|
||||
let (k, v) = attr_parser(&buf[i..buf.len()]);
|
||||
} else if (element.tag == "attr") | (element.tag == ":") | (element.tag.is_empty()) {
|
||||
let mut chars = (&buf[i..buf.len()]).to_string();
|
||||
|
||||
if element.tag.is_empty() {
|
||||
chars.insert_str(0, "\"");
|
||||
}
|
||||
|
||||
// parse
|
||||
let (k, v) = attr_parser(&chars);
|
||||
element.attrs.insert(k, v);
|
||||
element.tag = "attr".to_string();
|
||||
return element;
|
||||
|
@ -143,7 +144,7 @@ pub fn expr_parser(buf: &str) -> Element {
|
|||
let mut buffer: String = String::new();
|
||||
|
||||
string_parser((&buf[i..buf.len()]).chars(), &mut buffer);
|
||||
if (element.tag != "text") && (element.tag != "'") {
|
||||
if element.tag != "text" {
|
||||
// allows us to write `(h1' "Hello, world!")` instead of `(h1 [(text "Hello, world!")])`
|
||||
element.tag = element.tag.replace("'", "");
|
||||
|
||||
|
@ -154,10 +155,6 @@ pub fn expr_parser(buf: &str) -> Element {
|
|||
element.children.push(text_element);
|
||||
} else {
|
||||
// just add attr
|
||||
if element.tag == "'" {
|
||||
element.tag = "text".to_string();
|
||||
}
|
||||
|
||||
element.attrs.insert("content".to_string(), buffer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue