Skip to content

Commit fa049d9

Browse files
committed
add top-level tests for expressions
1 parent 640cc27 commit fa049d9

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

crates/parser/src/grammar.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ pub(crate) mod entry {
135135
}
136136
m.complete(p, ERROR);
137137
}
138+
139+
pub(crate) fn expr(p: &mut Parser) {
140+
let m = p.start();
141+
expressions::expr(p);
142+
if p.at(EOF) {
143+
m.abandon(p);
144+
return;
145+
}
146+
while !p.at(EOF) {
147+
p.bump_any();
148+
}
149+
m.complete(p, ERROR);
150+
}
138151
}
139152
}
140153

crates/parser/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ impl TopEntryPoint {
123123
TopEntryPoint::MacroItems => grammar::entry::top::macro_items,
124124
TopEntryPoint::Pattern => grammar::entry::top::pattern,
125125
TopEntryPoint::Type => grammar::entry::top::type_,
126+
TopEntryPoint::Expr => grammar::entry::top::expr,
126127
// FIXME
127-
TopEntryPoint::Expr => grammar::entry::prefix::expr,
128128
TopEntryPoint::MetaItem => grammar::entry::prefix::meta_item,
129129
};
130130
let mut p = parser::Parser::new(input);

crates/parser/src/tests/top_entries.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,46 @@ fn type_() {
224224
);
225225
}
226226

227+
#[test]
228+
fn expr() {
229+
check(
230+
TopEntryPoint::Expr,
231+
"2 + 2 == 5",
232+
expect![[r#"
233+
BIN_EXPR
234+
BIN_EXPR
235+
LITERAL
236+
INT_NUMBER "2"
237+
WHITESPACE " "
238+
PLUS "+"
239+
WHITESPACE " "
240+
LITERAL
241+
INT_NUMBER "2"
242+
WHITESPACE " "
243+
EQ2 "=="
244+
WHITESPACE " "
245+
LITERAL
246+
INT_NUMBER "5"
247+
"#]],
248+
);
249+
check(
250+
TopEntryPoint::Expr,
251+
"let _ = 0;",
252+
expect![[r#"
253+
ERROR
254+
LET_KW "let"
255+
WHITESPACE " "
256+
UNDERSCORE "_"
257+
WHITESPACE " "
258+
EQ "="
259+
WHITESPACE " "
260+
INT_NUMBER "0"
261+
SEMICOLON ";"
262+
error 0: expected expression
263+
"#]],
264+
);
265+
}
266+
227267
#[track_caller]
228268
fn check(entry: TopEntryPoint, input: &str, expect: expect_test::Expect) {
229269
let (parsed, _errors) = super::parse(entry, input);

0 commit comments

Comments
 (0)