aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-27 22:42:13 +0100
committerAleksey Kladov <[email protected]>2018-08-27 22:42:13 +0100
commit13110f48e948d7554500aefc336e72f96041386b (patch)
tree60796fe2a4de16e37ff844c3360726e526c9b506 /crates/libsyntax2/src
parent8f5330cb0796670a93089107c8b15cdef3fa7c94 (diff)
Log errors
Diffstat (limited to 'crates/libsyntax2/src')
-rw-r--r--crates/libsyntax2/src/parser_impl/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/parser_impl/mod.rs b/crates/libsyntax2/src/parser_impl/mod.rs
index f60ef80f0..b343b404f 100644
--- a/crates/libsyntax2/src/parser_impl/mod.rs
+++ b/crates/libsyntax2/src/parser_impl/mod.rs
@@ -1,6 +1,8 @@
1mod event; 1mod event;
2mod input; 2mod input;
3 3
4use std::cell::Cell;
5
4use { 6use {
5 lexer::Token, 7 lexer::Token,
6 parser_api::Parser, 8 parser_api::Parser,
@@ -51,6 +53,7 @@ pub(crate) struct ParserImpl<'t> {
51 53
52 pos: InputPosition, 54 pos: InputPosition,
53 events: Vec<Event>, 55 events: Vec<Event>,
56 steps: Cell<u32>,
54} 57}
55 58
56impl<'t> ParserImpl<'t> { 59impl<'t> ParserImpl<'t> {
@@ -60,6 +63,7 @@ impl<'t> ParserImpl<'t> {
60 63
61 pos: InputPosition::new(), 64 pos: InputPosition::new(),
62 events: Vec::new(), 65 events: Vec::new(),
66 steps: Cell::new(0),
63 } 67 }
64 } 68 }
65 69
@@ -91,6 +95,12 @@ impl<'t> ParserImpl<'t> {
91 } 95 }
92 96
93 pub(super) fn nth(&self, n: u32) -> SyntaxKind { 97 pub(super) fn nth(&self, n: u32) -> SyntaxKind {
98 let steps = self.steps.get();
99 if steps > 10_000_000 {
100 panic!("the parser seems stuck");
101 }
102 self.steps.set(steps + 1);
103
94 self.inp.kind(self.pos + n) 104 self.inp.kind(self.pos + n)
95 } 105 }
96 106