You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crates/pgt_statement_splitter/src/parser.rs
+123-112
Original file line number
Diff line number
Diff line change
@@ -13,24 +13,24 @@ use crate::diagnostics::SplitDiagnostic;
13
13
/// Main parser that exposes the `cstree` api, and collects errors and statements
14
14
/// It is modelled after a Pratt Parser. For a gentle introduction to Pratt Parsing, see https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html
15
15
pubstructParser{
16
-
/// The ranges of the statements
17
-
ranges:Vec<(usize,usize)>,
16
+
/// The statement ranges are defined by the indices of the start/end tokens
17
+
stmt_ranges:Vec<(usize,usize)>,
18
+
18
19
/// The syntax errors accumulated during parsing
19
20
errors:Vec<SplitDiagnostic>,
20
-
/// The start of the current statement, if any
21
+
21
22
current_stmt_start:Option<usize>,
22
-
/// The tokens to parse
23
-
pubtokens:Vec<Token>,
23
+
24
+
tokens:Vec<Token>,
24
25
25
26
eof_token:Token,
26
27
27
-
next_pos:usize,
28
+
current_pos:usize,
28
29
}
29
30
30
-
/// Result of Building
31
31
#[derive(Debug)]
32
-
pubstructParse{
33
-
/// The ranges of the errors
32
+
pubstructParserResult{
33
+
/// The ranges of the parsed statements
34
34
pubranges:Vec<TextRange>,
35
35
/// The syntax errors accumulated during parsing
36
36
puberrors:Vec<SplitDiagnostic>,
@@ -41,40 +41,34 @@ impl Parser {
41
41
let eof_token = Token::eof(usize::from(
42
42
tokens
43
43
.last()
44
-
.map(|t| t.span.start())
44
+
.map(|t| t.span.end())
45
45
.unwrap_or(TextSize::from(0)),
46
46
));
47
47
48
-
// next_pos should be the initialised with the first valid token already
49
-
letmut next_pos = 0;
50
-
loop{
51
-
let token = tokens.get(next_pos).unwrap_or(&eof_token);
52
-
53
-
ifis_irrelevant_token(token){
54
-
next_pos += 1;
55
-
}else{
56
-
break;
57
-
}
48
+
// Place `current_pos` on the first relevant token
0 commit comments