From 5fcb3b4f3b9ba9d0d0a228ebe43bc01d013a30de Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 22 Feb 2020 20:21:15 -0800 Subject: [PATCH] combine stuff - doesn't work --- schala-lang/language/src/parser.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/schala-lang/language/src/parser.rs b/schala-lang/language/src/parser.rs index 50a65c7..0c3aa8b 100644 --- a/schala-lang/language/src/parser.rs +++ b/schala-lang/language/src/parser.rs @@ -219,12 +219,29 @@ mod thing { use crate::builtin::Builtin; 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::*; + fn number_literal(input: &str) -> impl Parser + where I: Stream, I::Error: ParseError { + + use combine::parser::char::digit; + + many1(digit()) + .flat_map(|digits: Vec| { + //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 { - let identifier = take_while1(|c: char| c.is_alphabetic()); - let mut parser = sep_by(identifier, range(", ")); + use combine::parser::char::char; + //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); format!("{:?}", result) }