Skip to content

Commit 46b2b61

Browse files
committed
Improve code comments
1 parent 2f54dcb commit 46b2b61

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/parser.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ impl Parser {
157157
self.parse_subexpr(0)
158158
}
159159

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).
161163
pub fn parse_subexpr(&mut self, precedence: u8) -> Result<Expr, ParserError> {
162164
debug!("parsing expr");
163165
let mut expr = self.parse_prefix()?;
@@ -169,6 +171,18 @@ impl Parser {
169171
break;
170172
}
171173

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+
//
172186
expr = self.parse_infix(expr, next_precedence)?;
173187
}
174188
Ok(expr)
@@ -684,7 +698,8 @@ impl Parser {
684698
const BETWEEN_PREC: u8 = 20;
685699
const PLUS_MINUS_PREC: u8 = 30;
686700

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`)
688703
pub fn get_next_precedence(&self) -> Result<u8, ParserError> {
689704
if let Some(token) = self.peek_token() {
690705
debug!("get_next_precedence() {:?}", token);
@@ -1261,7 +1276,7 @@ impl Parser {
12611276
})
12621277
}
12631278

1264-
/// Parse a copy statement
1279+
/// Parse a PostgreSQL `COPY` statement
12651280
pub fn parse_copy(&mut self) -> Result<Statement, ParserError> {
12661281
let table_name = self.parse_object_name()?;
12671282
let columns = self.parse_parenthesized_column_list(Optional)?;
@@ -1275,14 +1290,8 @@ impl Parser {
12751290
})
12761291
}
12771292

1278-
/// Parse a tab separated values in
1279-
/// COPY payload
1293+
/// Parse a tab separated values in PostgreSQL `COPY` payload
12801294
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> {
12861295
let mut values = vec![];
12871296
let mut content = String::from("");
12881297
while let Some(t) = self.next_token_no_skip() {

0 commit comments

Comments
 (0)