Skip to content
Open

St05 #2491

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion crates/lib-core/src/parser/segments/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ impl FromExpressionElementSegment {

let alias_expression = self
.0
.child(const { &SyntaxSet::new(&[SyntaxKind::AliasExpression]) });
.child(const { &SyntaxSet::new(&[SyntaxKind::AliasExpression]) })
.or_else(|| {
self.0
.child(const { &SyntaxSet::new(&[SyntaxKind::Bracketed]) })
.and_then(|bracketed| {
bracketed.child(const { &SyntaxSet::new(&[SyntaxKind::AliasExpression]) })
})
});
if let Some(alias_expression) = alias_expression {
let segment = alias_expression.child(
const {
Expand Down
64 changes: 41 additions & 23 deletions crates/lib-dialects/src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4707,34 +4707,52 @@ pub fn raw_dialect() -> Dialect {
(
"FromExpressionElementSegment".into(),
NodeMatcher::new(SyntaxKind::FromExpressionElement, |_| {
Sequence::new(vec![
Ref::new("PreTableFunctionKeywordsGrammar")
.optional()
let base_from_expression_element = || {
Sequence::new(vec![
Ref::new("PreTableFunctionKeywordsGrammar")
.optional()
.to_matchable(),
optionally_bracketed(vec![
Ref::new("TableExpressionSegment").to_matchable(),
])
.to_matchable(),
optionally_bracketed(vec![Ref::new("TableExpressionSegment").to_matchable()])
Ref::new("AliasExpressionSegment")
.exclude(one_of(vec![
Ref::new("FromClauseTerminatorGrammar").to_matchable(),
Ref::new("SamplingExpressionSegment").to_matchable(),
Ref::new("JoinLikeClauseGrammar").to_matchable(),
LookaheadExclude::new("WITH", "(").to_matchable(),
]))
.optional()
.to_matchable(),
Sequence::new(vec![
Ref::keyword("WITH").to_matchable(),
Ref::keyword("OFFSET").to_matchable(),
Ref::new("AliasExpressionSegment").to_matchable(),
])
.config(|this| this.optional())
.to_matchable(),
Ref::new("AliasExpressionSegment")
.exclude(one_of(vec![
Ref::new("FromClauseTerminatorGrammar").to_matchable(),
Ref::new("SamplingExpressionSegment").to_matchable(),
Ref::new("JoinLikeClauseGrammar").to_matchable(),
LookaheadExclude::new("WITH", "(").to_matchable(),
]))
.optional()
Ref::new("SamplingExpressionSegment")
.optional()
.to_matchable(),
Ref::new("PostTableExpressionGrammar")
.optional()
.to_matchable(),
])
.to_matchable()
};

one_of(vec![
base_from_expression_element(),
Bracketed::new(vec![
Sequence::new(vec![
base_from_expression_element(),
AnyNumberOf::new(vec![Ref::new("JoinClauseSegment").to_matchable()])
.to_matchable(),
])
.to_matchable(),
Sequence::new(vec![
Ref::keyword("WITH").to_matchable(),
Ref::keyword("OFFSET").to_matchable(),
Ref::new("AliasExpressionSegment").to_matchable(),
])
.config(|this| this.optional())
.to_matchable(),
Ref::new("SamplingExpressionSegment")
.optional()
.to_matchable(),
Ref::new("PostTableExpressionGrammar")
.optional()
.to_matchable(),
])
.to_matchable()
})
Expand Down
Loading
Loading