combine stuff - doesn't work

This commit is contained in:
greg 2020-02-22 20:21:15 -08:00
parent 1f4ea71cf9
commit 5fcb3b4f3b

View File

@ -219,12 +219,29 @@ mod thing {
use crate::builtin::Builtin; use crate::builtin::Builtin;
use combine::parser::range::{range, take_while1}; use combine::parser::range::{range, take_while1};
use combine::parser::repeat::sep_by; use combine::parser::repeat::{many1, sep_by};
use combine::Stream;
use combine::*; use combine::*;
fn number_literal<I>(input: &str) -> impl Parser<I, Output=u64>
where I: Stream<Token = char>, I::Error: ParseError<I::Token, I::Range, I::Position> {
use combine::parser::char::digit;
many1(digit())
.flat_map(|digits: Vec<char>| {
//let num_str: String = digits.into_iter().filter_map(|x| x).collect();
let num_str: String = digits.into_iter().collect();
u64::from_str_radix(&num_str, 10)
})
}
pub fn perform_parsing(input: &str) -> String { pub fn perform_parsing(input: &str) -> String {
let identifier = take_while1(|c: char| c.is_alphabetic()); use combine::parser::char::char;
let mut parser = sep_by(identifier, range(", ")); //let identifier = take_while1(|c: char| c.is_alphabetic());
//let mut parser = sep_by(identifier, range(", "));
let parser = sep_by(char(','), number_literal);
let result: Result<(Vec<&str>, &str), _> = parser.easy_parse(input); let result: Result<(Vec<&str>, &str), _> = parser.easy_parse(input);
format!("{:?}", result) format!("{:?}", result)
} }