diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-07-27 17:33:43 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-07-27 17:33:43 +0300 |
commit | 3060e17c7a24f6b67cb1ef33922c38f67d872bc6 (patch) | |
tree | 4b5960bb7cf04cb67c9dad20d11580ada35642a6 /src/parse | |
parent | 1bd9d5bbd304926f464cf23870b17a46385b9f7a (diff) | |
download | myslip-3060e17c7a24f6b67cb1ef33922c38f67d872bc6.tar.gz myslip-3060e17c7a24f6b67cb1ef33922c38f67d872bc6.zip |
Implemented parse_token
Diffstat (limited to 'src/parse')
-rw-r--r-- | src/parse/parsetree.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/parse/parsetree.rs b/src/parse/parsetree.rs index 8887200..e243d56 100644 --- a/src/parse/parsetree.rs +++ b/src/parse/parsetree.rs @@ -2,6 +2,9 @@ use nom::{ IResult, Parser, + branch::alt, + bytes::complete::{tag, take_while}, + character::complete::multispace1, }; @@ -14,14 +17,22 @@ pub enum Token { Whitespace(String), } +use Token::*; +use crate::parse::util::*; + fn parse_token(s: &str) -> IResult<&str, Token> { - todo!() + alt(( + tag("(").map(|_| ParOpen), + tag(")").map(|_| ParClose), + multispace1.map(whitespace), + nom::character::complete::i32.map(Num), + take_while(|c| !(" \n\t()".contains(c))).map(sym), + )).parse(s) } #[cfg(test)] mod private_parsing_tests { - use super::{*, Token::*}; - use crate::parse::util::*; + use super::{*, parse_token}; #[test] fn test_parse_token() { |