1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
pub mod declaration;
pub mod statement;
pub mod expression;
pub mod operator;
pub mod atomic;
use nom::{
IResult,
branch::alt,
bytes::complete::{tag, take_until},
combinator::map,
multi::many0,
sequence::{preceded, terminated},
};
use crate::ast::Declaration;
use self::declaration::declaration;
pub fn comment(s: &str) -> IResult<&str, &str> {
preceded(tag("#"), take_until("\n"))(s)
}
pub fn whitespace(s: &str) -> IResult<&str, &str> {
map(many0(alt((tag(" "), tag("\t"), tag("\n"), comment))), |_| "")(s)
}
pub fn parse_file(s: &str) -> IResult<&str, Vec<Declaration>> {
terminated(many0(declaration), whitespace)(s)
}