Skip to content

Commit d88816c

Browse files
committed
added parse_column_def support and propogated span and stmt with leading_comment
1 parent 2b53303 commit d88816c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/ast/helpers/stmt_create_table.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::ast::{
3232
};
3333

3434
use crate::parser::ParserError;
35+
use crate::tokenizer::Comment;
3536

3637
/// Builder for create table statement variant ([1]).
3738
///
@@ -115,6 +116,7 @@ pub struct CreateTableBuilder {
115116
pub refresh_mode: Option<RefreshModeKind>,
116117
pub initialize: Option<InitializeKind>,
117118
pub require_user: bool,
119+
pub leading_comment: Option<Comment>,
118120
}
119121

120122
impl CreateTableBuilder {
@@ -171,6 +173,7 @@ impl CreateTableBuilder {
171173
refresh_mode: None,
172174
initialize: None,
173175
require_user: false,
176+
leading_comment: None,
174177
}
175178
}
176179
pub fn or_replace(mut self, or_replace: bool) -> Self {
@@ -484,6 +487,7 @@ impl CreateTableBuilder {
484487
refresh_mode: self.refresh_mode,
485488
initialize: self.initialize,
486489
require_user: self.require_user,
490+
leading_comment: self.leading_comment,
487491
}
488492
.into()
489493
}
@@ -548,6 +552,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
548552
refresh_mode,
549553
initialize,
550554
require_user,
555+
leading_comment,
551556
}) => Ok(Self {
552557
or_replace,
553558
temporary,
@@ -600,6 +605,7 @@ impl TryFrom<Statement> for CreateTableBuilder {
600605
refresh_mode,
601606
initialize,
602607
require_user,
608+
leading_comment,
603609
}),
604610
_ => Err(ParserError::ParserError(format!(
605611
"Expected create table statement, but received: {stmt}"

src/ast/spans.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ impl Spanned for CreateTable {
553553
refresh_mode: _,
554554
initialize: _,
555555
require_user: _,
556+
leading_comment: _, // Option<Comment>
556557
} = self;
557558

558559
union_spans(
@@ -572,6 +573,7 @@ impl Spanned for ColumnDef {
572573
name,
573574
data_type: _, // enum
574575
options,
576+
leading_comment: _,
575577
} = self;
576578

577579
union_spans(core::iter::once(name.span).chain(options.iter().map(|i| i.span())))

src/parser/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7888,7 +7888,7 @@ impl<'a> Parser<'a> {
78887888
}
78897889

78907890
pub fn parse_columns(&mut self) -> Result<(Vec<ColumnDef>, Vec<TableConstraint>), ParserError> {
7891-
todo!("Add parsing for the Leading comment of the column, if any.");
7891+
//todo!("Add parsing for the Leading comment of the column, if any.");
78927892

78937893
let mut columns = vec![];
78947894
let mut constraints = vec![];
@@ -7952,13 +7952,21 @@ impl<'a> Parser<'a> {
79527952
}
79537953

79547954
pub fn parse_column_def(&mut self) -> Result<ColumnDef, ParserError> {
7955+
let leading_comment = match self.peek_token().token {
7956+
Token::LeadingComment(_) => {
7957+
let Token::LeadingComment(c) = self.next_token().token else { unreachable!() };
7958+
Some(c)
7959+
}
7960+
_ => None,
7961+
};
79557962
let col_name = self.parse_identifier()?;
79567963
let data_type = if self.is_column_type_sqlite_unspecified() {
79577964
DataType::Unspecified
79587965
} else {
79597966
self.parse_data_type()?
79607967
};
79617968
let mut options = vec![];
7969+
79627970
loop {
79637971
if self.parse_keyword(Keyword::CONSTRAINT) {
79647972
let name = Some(self.parse_identifier()?);
@@ -7980,6 +7988,7 @@ impl<'a> Parser<'a> {
79807988
name: col_name,
79817989
data_type,
79827990
options,
7991+
leading_comment,
79837992
})
79847993
}
79857994

0 commit comments

Comments
 (0)