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) }