Skip to content

Commit 2059e07

Browse files
committedSep 12, 2023
chore: cleanup
1 parent 228b039 commit 2059e07

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed
 

‎crates/codegen/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ pg_query_proto_parser.workspace = true
1212

1313
[lib]
1414
proc-macro = true
15+
doctest = false
16+

‎crates/codegen/src/syntax_kind.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use std::collections::HashSet;
2+
use std::env::current_dir;
23

34
use pg_query_proto_parser::{Node, ProtoParser, Token};
45
use proc_macro2::{Ident, Literal};
56
use quote::{format_ident, quote};
67

78
pub fn syntax_kind_mod(_item: proc_macro2::TokenStream) -> proc_macro2::TokenStream {
8-
let parser = ProtoParser::new("./libpg_query/protobuf/pg_query.proto");
9+
let parser = ProtoParser::new("libpg_query/protobuf/pg_query.proto");
910
let proto_file = parser.parse();
1011

1112
let custom_node_names = custom_node_names();

‎crates/parser/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ pg_query_proto_parser.workspace = true
2020

2121
[dev-dependencies]
2222
insta = "1.31.0"
23+
24+
[lib]
25+
doctest = false

‎crates/parser/src/statement.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ use crate::{parser::Parser, syntax_kind_codegen::SyntaxKind};
55

66
/// A super simple lexer for sql statements.
77
///
8-
/// One weakness of pg_query.rs is that it does not parse whitespace or newlines. To circumvent
9-
/// this, we use a very simple lexer that just knows what kind of characters are being used. It
10-
/// does not know anything about postgres syntax or keywords. For example, all words such as `select` and `from` are put into the `Word` type.
8+
/// One weakness of pg_query.rs is that it does not parse whitespace or newlines. We use a very
9+
/// simple lexer to fill the gaps.
1110
#[derive(Logos, Debug, PartialEq)]
1211
pub enum StatementToken {
1312
// comments and whitespaces
@@ -38,18 +37,17 @@ impl Parser {
3837
/// The main entry point for parsing a statement `text`. `at_offset` is the offset of the statement in the source file.
3938
///
4039
/// On a high level, the algorithm works as follows:
41-
/// 1. Parse the statement with pg_query.rs and order nodes by their position. If the
42-
/// statement contains syntax errors, the parser will report the error and continue to work without information
40+
/// 1. Parse the statement with pg_query.rs. If the statement contains syntax errors, the parser will report the error and continue to work without information
4341
/// about the nodes. The result will be a flat list of tokens under the generic `Stmt` node.
4442
/// If successful, the first node in the ordered list will be the main node of the statement,
4543
/// and serves as a root node.
4644
/// 2. Scan the statements for tokens with pg_query.rs. This will never fail, even if the statement contains syntax errors.
47-
/// 3. Parse the statement with the `StatementToken` lexer. The lexer will be the main vehicle
48-
/// while walking the statement.
49-
/// 4. Walk the statement with the `StatementToken` lexer.
50-
/// - at every token, consume all nodes that are within the token's range.
51-
/// - if there is a pg_query token within the token's range, consume it. if not, fallback to
52-
/// the StatementToken. This is the case for e.g. whitespace.
45+
/// 3. Parse the statement with the `StatementToken` lexer. The lexer only contains the tokens
46+
/// that are not parsed by pg_query.rs, such as whitespace.
47+
/// 4. Define a pointer that starts at 0 and move it along the statement.
48+
/// - first, check if the current pointer is within a pg_query token. If so, consume the
49+
/// token.
50+
/// - if not, consume the next token from the `StatementToken` lexer.
5351
/// 5. Close all open nodes for that statement.
5452
pub fn parse_statement(&mut self, text: &str, at_offset: Option<u32>) {
5553
let offset = at_offset.unwrap_or(0);

‎crates/pg_query_proto_parser/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ edition = "2021"
99
protobuf-parse = "3.2.0"
1010
protobuf = "3.2.0"
1111
convert_case = "0.6.0"
12+
13+
[lib]
14+
doctest = false

0 commit comments

Comments
 (0)
Please sign in to comment.