Skip to content

Commit 03621ad

Browse files
committed
Do not eat token when expecting another token
1 parent d9c5962 commit 03621ad

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

vhdl_lang/src/syntax/subprogram.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,14 @@ function foo(foo : natural) return lib.foo.natural;
407407
pub fn parses_function_signature_many_return_error() {
408408
let code = Code::new("[return bar.type_mark return");
409409
assert_eq!(
410-
code.with_stream_err(parse_signature),
411-
Diagnostic::error(code.s("return", 2), "Expected ']'")
410+
code.with_partial_stream(parse_signature),
411+
Err(Diagnostic::error(code.s("return", 2), "Expected ']'"))
412412
);
413413

414414
let code = Code::new("[foo return bar.type_mark return");
415415
assert_eq!(
416-
code.with_stream_err(parse_signature),
417-
Diagnostic::error(code.s("return", 2), "Expected ']'")
416+
code.with_partial_stream(parse_signature),
417+
Err(Diagnostic::error(code.s("return", 2), "Expected ']'"))
418418
);
419419
}
420420

vhdl_lang/src/syntax/tokens/tokenstream.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ impl<'a> TokenStream<'a> {
5050
}
5151

5252
pub fn expect_kind(&mut self, kind: Kind) -> DiagnosticResult<Token> {
53-
if let Some(token) = self.pop()? {
54-
token.expect_kind(kind)
53+
if let Some(token) = self.peek()? {
54+
if token.kind == kind {
55+
self.move_after(&token);
56+
Ok(token)
57+
} else {
58+
Err(token.kinds_error_before(&[kind]))
59+
}
5560
} else {
5661
Err(self
5762
.tokenizer

0 commit comments

Comments
 (0)