-
Notifications
You must be signed in to change notification settings - Fork 669
Leading comment support added for AlterTable, CreateTable, and ColumnDef
#2069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
AlterTable, CreateTable and ColumnDef`
AlterTable, CreateTable and ColumnDef` AlterTable, CreateTable and ColumnDef
AlterTable, CreateTable and ColumnDef AlterTable, CreateTable, and ColumnDef
…r leading_comment value
Viicos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @RPG-Alex,
Coming from #2077 (comment), I'm wondering if it is necessary to distinguish between the two types of comments. In theory, by analyzing the token coming right after the comment one?
Maybe this makes sense as a user convenience, but it feels weird to have two separate tokens for this, I'm wondering if we could have a concept of flags, where this information would be stored.
That way, users that don't care about which type of comment it is can simply match against a single Comment token kind. But this would require a larger refactor, and is not only relevant for comments (e.g. for strings, if you don't care about the quote style and number).
This PR refactors the internal representation of comments in the tokenizer and parser and adds leading comment support for
AlterTable,CreateTable, andColumnDef.The
SingleLineandMultiLinecomment variants previously defined in theWhitespaceenum are now represented by a new, dedicatedCommentenum. TheCommentis used for both whitespace comments (interstitial comments) and leading comments. Leading comment support propagated forAlterTable,CreateTable, andColumnDef, to parse leading comments alongside the associatied struct (see below for example).Rationale
This change improves the semantic clarity of comment handling in the SQL tokenizer and parser.
As discussed in #2065, comments preceding a table or column definition may serve as inline documentation, and should be distinguishable from interstitial (whitespace) comments.
For example:
Term Definitions
Intersitial Comment: a comment preceded by something (if nothing then defined as leading comment) that is not a comma or semicolon:
Leading Comment: a comment that is preceded by either nothing, a comma, or a semicolon.
currently the variants covered include single line comments:
and multi-line comments:
By separating comment handling from generic whitespace, the parser can now support more context-aware interpretations and contribute to a lossless syntax tree, addressing #175 and complementing PR #189.
Summary of Changes
Commentenum encapsulatingSingleLineandMultiLinecomment variants.Whitespaceto includeInterstitialComment(Comment)variant.Tokenizer.rsto emitCommentvalues instead ofWhitespace::SingleLineComment/Whitespace::MultiLineComment.parser/mod.rsimplementedLeadingCommentforCreateTable,ColumnDef,AlterTableparsing.leading_comment: Option<Comment>to theCreateTable,ColumnDef,AlterTable:InterstitialCommentandLeadingComment.