Skip to content

Commit be7c5c9

Browse files
committed
add parse_2way_with_transformers
1 parent 3d43763 commit be7c5c9

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

crates/postgresql-cst-parser/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub use cst::SyntaxToken;
2424

2525
use transform::ComplementMissingFromTableTransformer;
2626
use transform::ComplementMissingSampleValueTransformer;
27+
use transform::ParseTransformer;
2728
use transform::SkipExtraComma;
2829
use transform::SkipExtraOperator;
2930
pub use tree_sitter::parse as ts_parse;
@@ -48,3 +49,10 @@ pub fn parse_2way(input: &str) -> Result<ResolvedNode, ParseError> {
4849
],
4950
)
5051
}
52+
53+
pub fn parse_2way_with_transformers(
54+
input: &str,
55+
transformers: &[&dyn ParseTransformer],
56+
) -> Result<ResolvedNode, ParseError> {
57+
parse_with_transformer(input, transformers)
58+
}

crates/postgresql-cst-parser/src/transform.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ pub(crate) mod missing_sample_value;
33
pub(crate) mod skip_extra_comma;
44
pub(crate) mod skip_extra_operator;
55

6-
pub(crate) use missing_from_table::*;
7-
pub(crate) use missing_sample_value::*;
8-
pub(crate) use skip_extra_comma::*;
9-
pub(crate) use skip_extra_operator::*;
6+
pub use missing_from_table::*;
7+
pub use missing_sample_value::*;
8+
pub use skip_extra_comma::*;
9+
pub use skip_extra_operator::*;
1010

1111
use crate::{cst::LRParseState, lexer::TokenKind, parser::num_terminal_symbol};
1212

crates/postgresql-cst-parser/src/transform/missing_from_table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{lexer::TokenKind, syntax_kind::SyntaxKind};
55
use super::{num_terminal_symbol, LRParseState, ParseTransform, ParseTransformer};
66

77
/// Complete missing replacement string sample values ​​(FROM clause only)
8-
pub(crate) struct ComplementMissingFromTableTransformer;
8+
pub struct ComplementMissingFromTableTransformer;
99

1010
fn is_replacement_string_comment(comment: &str) -> bool {
1111
comment.starts_with("/*#") && comment.ends_with("*/")

crates/postgresql-cst-parser/src/transform/missing_sample_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{cst::Extra, lexer::TokenKind, syntax_kind::SyntaxKind};
33
use super::{num_terminal_symbol, LRParseState, ParseTransform, ParseTransformer};
44

55
/// Complete missing bind variable sample values
6-
pub(crate) struct ComplementMissingSampleValueTransformer;
6+
pub struct ComplementMissingSampleValueTransformer;
77

88
impl ComplementMissingSampleValueTransformer {
99
fn is_bind_variable_comment(s: impl AsRef<str>) -> bool {

crates/postgresql-cst-parser/src/transform/skip_extra_comma.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{lexer::TokenKind, syntax_kind::SyntaxKind};
33
use super::{LRParseState, ParseTransform, ParseTransformer};
44

55
/// Skip extra commas at the beginning of SELECT, FROM, and ORDER BY clauses
6-
pub(crate) struct SkipExtraComma;
6+
pub struct SkipExtraComma;
77

88
impl SkipExtraComma {
99
fn allow_extra_comma<'a>(lr_parse_state: &LRParseState<'a>) -> bool {

crates/postgresql-cst-parser/src/transform/skip_extra_operator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{lexer::TokenKind, syntax_kind::SyntaxKind};
33
use super::{LRParseState, ParseTransform, ParseTransformer};
44

55
/// Skip extra AND/OR at the beginning of the WHERE clause
6-
pub(crate) struct SkipExtraOperator;
6+
pub struct SkipExtraOperator;
77

88
impl SkipExtraOperator {
99
fn allow_extra_operator<'a>(lr_parse_state: &LRParseState<'a>) -> bool {

0 commit comments

Comments
 (0)