add some block parsing and a test (incomplete)

This commit is contained in:
Kasey White 2022-10-01 19:34:42 -04:00 committed by Lucas
parent 4acb849f09
commit 118a5ac54e
2 changed files with 24 additions and 2 deletions

View File

@ -312,7 +312,7 @@ pub fn expr_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError
.ignore_then(pattern_parser()) .ignore_then(pattern_parser())
.then(just(Token::Colon).ignore_then(type_parser()).or_not()) .then(just(Token::Colon).ignore_then(type_parser()).or_not())
.then_ignore(just(Token::Equal)) .then_ignore(just(Token::Equal))
.then(r) .then(r.clone())
.map_with_span( .map_with_span(
|((pattern, annotation), value), span| expr::UntypedExpr::Assignment { |((pattern, annotation), value), span| expr::UntypedExpr::Assignment {
location: span, location: span,
@ -323,6 +323,19 @@ pub fn expr_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError
}, },
); );
let expr_block_parser = just(Token::LeftBrace)
.ignore_then(r.clone().then(r.repeated()))
.then_ignore(just(Token::RightBrace))
.map_with_span(|(a, b), span| {
let mut expressions = vec![a];
expressions.extend(b);
expr::UntypedExpr::Sequence {
location: span,
expressions,
}
});
let expr_unit_parser = choice(( let expr_unit_parser = choice((
string_parser, string_parser,
int_parser, int_parser,
@ -330,6 +343,7 @@ pub fn expr_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError
todo_parser, todo_parser,
list_parser, list_parser,
assignment_parser, assignment_parser,
expr_block_parser,
)) ))
.boxed(); .boxed();
@ -368,7 +382,7 @@ pub fn expr_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError
}) })
.boxed(); .boxed();
// Logical // Comparison
let op = choice(( let op = choice((
just(Token::EqualEqual).to(BinOp::Eq), just(Token::EqualEqual).to(BinOp::Eq),
just(Token::NotEqual).to(BinOp::NotEq), just(Token::NotEqual).to(BinOp::NotEq),
@ -389,6 +403,7 @@ pub fn expr_parser() -> impl Parser<Token, expr::UntypedExpr, Error = ParseError
}) })
.boxed(); .boxed();
// Logical
let op = choice(( let op = choice((
just(Token::AmperAmper).to(BinOp::And), just(Token::AmperAmper).to(BinOp::And),
just(Token::VbarVbar).to(BinOp::Or), just(Token::VbarVbar).to(BinOp::Or),

View File

@ -50,6 +50,13 @@ fn module() {
y y
} }
pub fn wow2(a: Int){
let x = 1 + {
2 + 7 * 8
} / 2
x
}
"#; "#;
let len = code.chars().count(); let len = code.chars().count();