10000 [refactoring] Better structure for the 'parser' module · UnBCIC-TP2/r-python@e3c460c · GitHub
[go: up one dir, main page]

Skip to content

Commit e3c460c

Browse files
committed
[refactoring] Better structure for the 'parser' module
1 parent 3f6409a commit e3c460c

File tree

3 files changed

+36
-613
lines changed

3 files changed

+36
-613
lines changed

src/parser.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/parser/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
pub mod keywords;
2+
pub mod parser_common;
3+
pub mod parser_expr;
4+
pub mod parser_stmt;
5+
pub mod parser_type;
6+
use nom::{
7+
branch::alt,
8+
bytes::complete::{tag},
9+
character::complete::{char, multispace0},
10+
combinator::{map, opt},
11+
error::Error,
12+
multi::separated_list0,
13+
sequence::tuple,
14+
IResult,
15+
};
16+
17+
use crate::ir::ast::Statement;
18+
19+
pub use parser_expr::parse_expression;
20+
pub use parser_stmt::parse_statement;
21+
pub use parser_type::parse_type;
22+
23+
pub fn parse(input: &str) -> IResult<&str, Vec<Statement>> {
24+
map(
25+
tuple((
26+
multispace0,
27+
separated_list0(
28+
tuple((multispace0, char(';'), multispace0)),
29+
parse_statement
30+
),
31+
opt(tuple((multispace0, char(';')))), // optional trailing semicolon
32+
multispace0
33+
)),
34+
|(_, statements, _, _)| statements
35+
)(input)
36+
}

0 commit comments

Comments
 (0)
0