Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
tanzaku committed May 5, 2024
1 parent aaf18ba commit da4bce9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions crates/lexer-generator/resources/lex_template.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::all)]
#![allow(unreachable_code)]

use std::collections::HashMap;
Expand Down
3 changes: 2 additions & 1 deletion crates/postgresql-lst-parser/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub struct Rule {
pub kind: RuleKind,
}

#[allow(clippy::all)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum TokenKind {
RAW(String),
Expand Down Expand Up @@ -177,5 +178,5 @@ pub fn lex(input: &str) -> Vec<Token> {
}

// dbg!(&tokens);
return tokens;
tokens
}
1 change: 1 addition & 0 deletions crates/postgresql-lst-parser/src/lexer/generated.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::all)]
#![allow(unreachable_code)]

use std::collections::HashMap;
Expand Down
8 changes: 4 additions & 4 deletions crates/postgresql-lst-parser/src/lexer/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn yyerror(msg: &str) {
}

pub fn get_char_by_byte_pos(s: &str, byte_pos: usize) -> char {
s.bytes().nth(byte_pos).unwrap() as char
s.as_bytes()[byte_pos] as char
}

impl Lexer {
Expand Down Expand Up @@ -112,19 +112,19 @@ impl Lexer {
let mut neg = false;

match yytext.bytes().next() {
Some(b) if b == '-' as u8 => {
Some(b'-') => {
neg = true;
yytext = &yytext[1..];
}
Some(b) if b == '+' as u8 => {
Some(b'+') => {
yytext = &yytext[1..];
}
_ => (),
}

let res_parse_as_i32 = match radix {
8 => i32::from_str_radix(&yytext[2..], 8),
10 => i32::from_str_radix(yytext, 10),
10 => yytext.parse::<i32>(),
16 => i32::from_str_radix(&yytext[2..], 16),
_ => unreachable!(),
};
Expand Down
14 changes: 6 additions & 8 deletions crates/postgresql-lst-parser/src/lst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ impl Parser {

/// The logic for converting tokens in PostgreSQL's parser.c
/// ref: https://github.com/postgres/postgres/blob/REL_16_STABLE/src/backend/parser/parser.c#L195
fn init_tokens(tokens: &mut Vec<Token>) {
fn next_token_index(tokens: &Vec<Token>, i: usize) -> Option<usize> {
for j in i + 1..tokens.len() {
match tokens[j].kind {
fn init_tokens(tokens: &mut [Token]) {
fn next_token_index(tokens: &[Token], i: usize) -> Option<usize> {
for (j, token) in tokens.iter().enumerate().skip(i + 1) {
match token.kind {
TokenKind::C_COMMENT | TokenKind::SQL_COMMENT => continue,
_ => return Some(j),
}
Expand Down Expand Up @@ -234,7 +234,6 @@ pub fn parse(input: &str) -> Result<ResolvedNode, ParseError> {
token.start_byte_pos,
&input[last_pos..token.start_byte_pos],
));
token.start_byte_pos;
}

last_pos = token.end_byte_pos;
Expand All @@ -252,7 +251,7 @@ pub fn parse(input: &str) -> Result<ResolvedNode, ParseError> {
}

let action = match action_table[(state * num_terminal_symbol() + cid) as usize] {
v if v == 0x7FFF => Action::Error,
0x7FFF => Action::Error,
v if v > 0 => Action::Shift((v - 1) as usize),
v if v < 0 => Action::Reduce((-v - 1) as usize),
_ => Action::Accept,
Expand Down Expand Up @@ -290,7 +289,7 @@ pub fn parse(input: &str) -> Result<ResolvedNode, ParseError> {
}
children.reverse();

let reduced_component_id = rule_name_to_component_id(&rule.name);
let reduced_component_id = rule_name_to_component_id(rule.name);

let start_byte_pos =
children
Expand Down Expand Up @@ -359,7 +358,6 @@ pub fn parse(input: &str) -> Result<ResolvedNode, ParseError> {
token.start_byte_pos,
&input[last_pos..token.start_byte_pos],
));
token.start_byte_pos;
}

last_pos = token.end_byte_pos;
Expand Down

0 comments on commit da4bce9

Please sign in to comment.