@@ -157,7 +157,9 @@ impl Parser {
157
157
self . parse_subexpr ( 0 )
158
158
}
159
159
160
- /// Parse tokens until the precedence changes
160
+ /// Parse an expression, that either follows an operator with the
161
+ /// specified `precedence` or starts at the beginning, in which case
162
+ /// the `precedence` is 0 (representing the lowest binding power).
161
163
pub fn parse_subexpr ( & mut self , precedence : u8 ) -> Result < Expr , ParserError > {
162
164
debug ! ( "parsing expr" ) ;
163
165
let mut expr = self . parse_prefix ( ) ?;
@@ -169,6 +171,18 @@ impl Parser {
169
171
break ;
170
172
}
171
173
174
+ // Here next_precedence > precedence... i.e. the following operator
175
+ // has higher binding power than the operator to the left of `expr`
176
+ // In the following illustration, we're at the second (and the
177
+ // last) iteration of this loop.
178
+ //
179
+ // expr
180
+ // _______
181
+ // a + b * c * d + e
182
+ // ^ ^
183
+ // | |< current token (returned by `peek_token()`;
184
+ // `precedence` has `next_precedence`)
185
+ //
172
186
expr = self . parse_infix ( expr, next_precedence) ?;
173
187
}
174
188
Ok ( expr)
@@ -684,7 +698,8 @@ impl Parser {
684
698
const BETWEEN_PREC : u8 = 20 ;
685
699
const PLUS_MINUS_PREC : u8 = 30 ;
686
700
687
- /// Get the precedence of the next token
701
+ /// Get the precedence of the next unprocessed token (or multiple
702
+ /// tokens, in cases like `NOT IN`)
688
703
pub fn get_next_precedence ( & self ) -> Result < u8 , ParserError > {
689
704
if let Some ( token) = self . peek_token ( ) {
690
705
debug ! ( "get_next_precedence() {:?}" , token) ;
@@ -1261,7 +1276,7 @@ impl Parser {
1261
1276
} )
1262
1277
}
1263
1278
1264
- /// Parse a copy statement
1279
+ /// Parse a PostgreSQL `COPY` statement
1265
1280
pub fn parse_copy ( & mut self ) -> Result < Statement , ParserError > {
1266
1281
let table_name = self . parse_object_name ( ) ?;
1267
1282
let columns = self . parse_parenthesized_column_list ( Optional ) ?;
@@ -1275,14 +1290,8 @@ impl Parser {
1275
1290
} )
1276
1291
}
1277
1292
1278
- /// Parse a tab separated values in
1279
- /// COPY payload
1293
+ /// Parse a tab separated values in PostgreSQL `COPY` payload
1280
1294
fn parse_tsv ( & mut self ) -> Result < Vec < Option < String > > , ParserError > {
1281
- let values = self . parse_tab_value ( ) ?;
1282
- Ok ( values)
1283
- }
1284
-
1285
- fn parse_tab_value ( & mut self ) -> Result < Vec < Option < String > > , ParserError > {
1286
1295
let mut values = vec ! [ ] ;
1287
1296
let mut content = String :: from ( "" ) ;
1288
1297
while let Some ( t) = self . next_token_no_skip ( ) {
0 commit comments