-
Notifications
You must be signed in to change notification settings - Fork 602
Move Statement
and Expr
so they hold identifiable structs
#345
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
Closed
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
db5c9c2
moving Statement so it holds structs
tvallotton 72d01f3
-
tvallotton 29e00e0
-
tvallotton 09428fd
updating parser and tests
tvallotton 8b5949e
fixing tests
tvallotton b461ff5
boxing CreateTable to use less space
tvallotton bf66af3
Moving Expr so it holds structs
tvallotton b84e24b
Update README.md
tvallotton 46a7636
Adding Drop constraint to parser
tvallotton a165767
Adding drop constraint to parser
tvallotton 9b0f83e
Fixing error
tvallotton 39e0dce
Moving table constraint so it holds structs
tvallotton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"RA_LOG=lsp_server": "debug", | ||
"RA_LOG_FILE": "/Users/tomas/Documents/sqlparser-rs/output" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Fork | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is probably not accurate |
||
This is a fork of [`sqlparser`](https://github.com/sqlparser-rs/sqlparser-rs). The major difference between `sqlparse` and this fork is that here `Statement` and `Expr` hold structs instead of variables. | ||
|
||
# Extensible SQL Lexer and Parser for Rust | ||
|
||
[](https://opensource.org/licenses/Apache-2.0) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
use super::*; | ||
|
||
impl fmt::Display for Expr { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self { | ||
Expr::Identifier(s) => write!(f, "{}", s), | ||
Expr::MapAccess(x) => write!(f, "{}", x), | ||
Expr::Wildcard => f.write_str("*"), | ||
Expr::QualifiedWildcard(q) => write!(f, "{}.*", display_separated(q, ".")), | ||
Expr::CompoundIdentifier(s) => write!(f, "{}", display_separated(s, ".")), | ||
Expr::IsNull(ast) => write!(f, "{} IS NULL", ast), | ||
Expr::IsNotNull(ast) => write!(f, "{} IS NOT NULL", ast), | ||
Expr::InList(x) => write!(f, "{}", x), | ||
Expr::InSubquery(x) => write!(f, "{}", x), | ||
Expr::Between(x) => write!(f, "{}", x), | ||
Expr::BinaryOp(x) => write!(f, "{}", x), | ||
Expr::UnaryOp(x) => write!(f, "{}", x), | ||
Expr::Cast(x) => write!(f, "{}", x), | ||
Expr::TryCast(x) => write!(f, "{}", x), | ||
Expr::Extract(x) => write!(f, "{}", x), | ||
Expr::Collate(x) => write!(f, "{}", x), | ||
Expr::Nested(ast) => write!(f, "({})", ast), | ||
Expr::Value(v) => write!(f, "{}", v), | ||
Expr::TypedString(x) => write!(f, "{}", x), | ||
Expr::Function(fun) => write!(f, "{}", fun), | ||
Expr::Case(x) => write!(f, "{}", x), | ||
Expr::Exists(s) => write!(f, "EXISTS ({})", s), | ||
Expr::Subquery(s) => write!(f, "({})", s), | ||
Expr::ListAgg(listagg) => write!(f, "{}", listagg), | ||
Expr::Substring(x) => write!(f, "{}", x), | ||
Expr::Trim(x) => write!(f, "{}", x), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Trim { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "TRIM(")?; | ||
if let Some((ref ident, ref trim_char)) = self.trim_where { | ||
write!(f, "{} {} FROM {}", ident, trim_char, self.expr)?; | ||
} else { | ||
write!(f, "{}", self.expr)?; | ||
} | ||
write!(f, ")") | ||
} | ||
} | ||
|
||
impl fmt::Display for Substring { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "SUBSTRING({}", self.expr)?; | ||
if let Some(ref from_part) = self.substring_from { | ||
write!(f, " FROM {}", from_part)?; | ||
} | ||
if let Some(ref from_part) = self.substring_for { | ||
write!(f, " FOR {}", from_part)?; | ||
} | ||
|
||
write!(f, ")") | ||
} | ||
} | ||
|
||
impl fmt::Display for Case { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "CASE")?; | ||
if let Some(ref operand) = self.operand { | ||
write!(f, " {}", operand)?; | ||
} | ||
for (c, r) in self.conditions.iter().zip(&self.results) { | ||
write!(f, " WHEN {} THEN {}", c, r)?; | ||
} | ||
|
||
if let Some(ref else_result) = self.else_result { | ||
write!(f, " ELSE {}", else_result)?; | ||
} | ||
write!(f, " END") | ||
} | ||
} | ||
|
||
impl fmt::Display for TypedString { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", self.data_type)?; | ||
write!(f, " '{}'", &value::escape_single_quote_string(&self.value)) | ||
} | ||
} | ||
|
||
impl fmt::Display for Collate { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{} COLLATE {}", self.expr, self.collation) | ||
} | ||
} | ||
impl fmt::Display for UnaryOp { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
if self.op == UnaryOperator::PGPostfixFactorial { | ||
write!(f, "{}{}", self.expr, self.op) | ||
} else { | ||
write!(f, "{} {}", self.op, self.expr) | ||
} | ||
} | ||
} | ||
impl fmt::Display for InSubquery { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{} {}IN ({})", | ||
self.expr, | ||
if self.negated { "NOT " } else { "" }, | ||
self.subquery | ||
) | ||
} | ||
} | ||
impl fmt::Display for Between { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{} {}BETWEEN {} AND {}", | ||
self.expr, | ||
if self.negated { "NOT " } else { "" }, | ||
self.low, | ||
self.high | ||
) | ||
} | ||
} | ||
impl fmt::Display for InList { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{} {}IN ({})", | ||
self.expr, | ||
if self.negated { "NOT " } else { "" }, | ||
display_comma_separated(&self.list) | ||
) | ||
} | ||
} | ||
impl fmt::Display for BinaryOp { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{} {} {}", self.left, self.op, self.right) | ||
} | ||
} | ||
impl fmt::Display for MapAccess { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}[\"{}\"]", self.column, self.key) | ||
} | ||
} | ||
|
||
impl fmt::Display for Cast { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "CAST({} AS {})", self.expr, self.data_type) | ||
} | ||
} | ||
|
||
impl fmt::Display for TryCast { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "TRY_CAST({} AS {})", self.expr, self.data_type) | ||
} | ||
} | ||
|
||
impl fmt::Display for Extract { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "EXTRACT({} FROM {})", self.field, self.expr) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this file looks pretty specific to your own environment -- did you mean to propose including it into this PR?
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.
Oh yeah I think I was a little careless as I initially didn't think I was going to submit a pull request. I also noticed I made the changes on the master branch, would you prefer I did another submission on a separate branch?
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.
I don't think it matters what branch you work on in your fork (
tvallotton:main
is fine)