parses the most basic example

looking-at-specs
mitchellhansen 4 years ago
parent d00f3b06b2
commit 32ae95b3d0

@ -51,18 +51,34 @@ pub fn hex_color(input: &str) -> IResult<&str, Color> {
Ok((input, Color { red, green, blue }))
}
pub fn elem_tag(input: &str) -> IResult<&str, &str> {
pub fn scope<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str> {
let (input, _) = delimited(opt(sp), delimited(char('{'), is_not("}"), char('}')), opt(sp))(input)?;
//let (input, _) = delimited(char('{'), is_not("}"), char('}'))(input)?;
let (input, _) = delimited(opt(sp), tag("elem"), sp)(input)?;
Ok((input, input))
}
pub fn elem<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str> {
let (input, _) = delimited(opt(sp), tag("elem"), sp)(input)?;
let (input, elem_name) = parse_str(input)?;
let (input, _) = scope::<'a, E>(input)?;
println!("elem , name : {:?} || scope : {:?}", elem_name, input);
Ok((input, elem_name))
}
fn parse_str<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &'a str, E> {
let chars = "\n";
escaped(alphanumeric, '\\', one_of(""))(i)
}
// Parse from a # to a newline character
pub fn comment<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
let v = preceded(char('#'),
@ -72,14 +88,12 @@ pub fn comment<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, &
)),
)(input)?;
println!("{:?}", v);
println!("comment : # {:?}", v.1);
Ok((v.0, v.0))
}
fn curlies(input: &str) -> IResult<&str, &str> {
delimited(char('{'), is_not("}"), char('}'))(input)
}
/// parser combinators are constructed from the bottom up:
/// first we write parsers for the smallest elements (here a space character),
@ -93,27 +107,26 @@ fn sp<'a>(i: &'a str) -> IResult<&'a str, &'a str> {
}
pub fn parse_script<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, ScriptMeta, E> {
let x = delimited(
sp,
alt((map(comment, |s| ScriptMeta::Comment(String::from(s))),
map(elem_tag, |s| ScriptMeta::Element(String::from(s)))
)),
opt(sp),
)(input);
let x = x.unwrap().0;
println!("{:?}", x);
let x = delimited(
sp,
alt((map(comment, |s| ScriptMeta::Comment(String::from(s))),
map(elem_tag, |s| ScriptMeta::Element(String::from(s)))
)),
opt(sp),
)(x);
let x = x.unwrap().0;
println!("{:?}", x);
println!("Full input string : {:?}\n", input);
let mut remaining_str = input;
while remaining_str.len() > 0 {
println!("Remaining Length : {:?}", remaining_str.len());
println!("Remaining String: {:?}", remaining_str);
let x = delimited(
sp,
alt((map(comment, |s| ScriptMeta::Comment(String::from(s))),
map(elem::<'a, E>, |s| ScriptMeta::Element(String::from(s)))
)),
opt(sp),
)(remaining_str);
remaining_str = x.unwrap().0;
}
//println!("{:?}", x);
// if let Ok(v) = elem_tag(input) {
// println!("Found elem tag");
// if let Ok(v) = sp(v.0) {
@ -129,7 +142,7 @@ pub fn parse_script<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a s
// }
return Ok((x, ScriptMeta::Comment(String::default())));
return Ok((remaining_str, ScriptMeta::Comment(String::default())));
}

Loading…
Cancel
Save