-
Notifications
You must be signed in to change notification settings - Fork 19
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
Implement lambda expressions #219
Merged
makenowjust
merged 6 commits into
cloudspannerecosystem:main
from
apstndb:feature/lambda
Dec 2, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a241c2
Implement LambdaArg
apstndb 5b10fc7
Update testdata
apstndb 25b3f33
Fix to use token.InvalidPos
apstndb abdf190
Replace useless use of parseCommaSeparatedList
apstndb e5e6033
Add comment to LambdaArg.Args
apstndb d021e57
Update LambdaArg comments
apstndb 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
1 change: 1 addition & 0 deletions
1
testdata/input/expr/array_functions_array_filter_parenless_lambda.sql
This file contains 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 @@ | ||
ARRAY_FILTER([1 ,2, 3], e -> e > 1) |
1 change: 1 addition & 0 deletions
1
testdata/input/expr/array_functions_array_filter_two_args_lambda.sql
This file contains 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 @@ | ||
ARRAY_FILTER([0, 2, 3], (e, i) -> e > i) |
72 changes: 72 additions & 0 deletions
72
testdata/result/expr/array_functions_array_filter_parenless_lambda.sql.txt
This file contains 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,72 @@ | ||
--- array_functions_array_filter_parenless_lambda.sql | ||
ARRAY_FILTER([1 ,2, 3], e -> e > 1) | ||
--- AST | ||
&ast.CallExpr{ | ||
Rparen: 34, | ||
Func: &ast.Ident{ | ||
NamePos: 0, | ||
NameEnd: 12, | ||
Name: "ARRAY_FILTER", | ||
}, | ||
Distinct: false, | ||
Args: []ast.Arg{ | ||
&ast.ExprArg{ | ||
Expr: &ast.ArrayLiteral{ | ||
Array: -1, | ||
Lbrack: 13, | ||
Rbrack: 21, | ||
Type: nil, | ||
Values: []ast.Expr{ | ||
&ast.IntLiteral{ | ||
ValuePos: 14, | ||
ValueEnd: 15, | ||
Base: 10, | ||
Value: "1", | ||
}, | ||
&ast.IntLiteral{ | ||
ValuePos: 17, | ||
ValueEnd: 18, | ||
Base: 10, | ||
Value: "2", | ||
}, | ||
&ast.IntLiteral{ | ||
ValuePos: 20, | ||
ValueEnd: 21, | ||
Base: 10, | ||
Value: "3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
&ast.LambdaArg{ | ||
Lparen: -1, | ||
Args: []*ast.Ident{ | ||
&ast.Ident{ | ||
NamePos: 24, | ||
NameEnd: 25, | ||
Name: "e", | ||
}, | ||
}, | ||
Expr: &ast.BinaryExpr{ | ||
Op: ">", | ||
Left: &ast.Ident{ | ||
NamePos: 29, | ||
NameEnd: 30, | ||
Name: "e", | ||
}, | ||
Right: &ast.IntLiteral{ | ||
ValuePos: 33, | ||
ValueEnd: 34, | ||
Base: 10, | ||
Value: "1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
NamedArgs: []*ast.NamedArg(nil), | ||
NullHandling: nil, | ||
Having: nil, | ||
} | ||
|
||
--- SQL | ||
ARRAY_FILTER([1, 2, 3], e -> e > 1) |
76 changes: 76 additions & 0 deletions
76
testdata/result/expr/array_functions_array_filter_two_args_lambda.sql.txt
This file contains 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,76 @@ | ||
--- array_functions_array_filter_two_args_lambda.sql | ||
ARRAY_FILTER([0, 2, 3], (e, i) -> e > i) | ||
--- AST | ||
&ast.CallExpr{ | ||
Rparen: 39, | ||
Func: &ast.Ident{ | ||
NamePos: 0, | ||
NameEnd: 12, | ||
Name: "ARRAY_FILTER", | ||
}, | ||
Distinct: false, | ||
Args: []ast.Arg{ | ||
&ast.ExprArg{ | ||
Expr: &ast.ArrayLiteral{ | ||
Array: -1, | ||
Lbrack: 13, | ||
Rbrack: 21, | ||
Type: nil, | ||
Values: []ast.Expr{ | ||
&ast.IntLiteral{ | ||
ValuePos: 14, | ||
ValueEnd: 15, | ||
Base: 10, | ||
Value: "0", | ||
}, | ||
&ast.IntLiteral{ | ||
ValuePos: 17, | ||
ValueEnd: 18, | ||
Base: 10, | ||
Value: "2", | ||
}, | ||
&ast.IntLiteral{ | ||
ValuePos: 20, | ||
ValueEnd: 21, | ||
Base: 10, | ||
Value: "3", | ||
}, | ||
}, | ||
}, | ||
}, | ||
&ast.LambdaArg{ | ||
Lparen: 24, | ||
Args: []*ast.Ident{ | ||
&ast.Ident{ | ||
NamePos: 25, | ||
NameEnd: 26, | ||
Name: "e", | ||
}, | ||
&ast.Ident{ | ||
NamePos: 28, | ||
NameEnd: 29, | ||
Name: "i", | ||
}, | ||
}, | ||
Expr: &ast.BinaryExpr{ | ||
Op: ">", | ||
Left: &ast.Ident{ | ||
NamePos: 34, | ||
NameEnd: 35, | ||
Name: "e", | ||
}, | ||
Right: &ast.Ident{ | ||
NamePos: 38, | ||
NameEnd: 39, | ||
Name: "i", | ||
}, | ||
}, | ||
}, | ||
}, | ||
NamedArgs: []*ast.NamedArg(nil), | ||
NullHandling: nil, | ||
Having: nil, | ||
} | ||
|
||
--- SQL | ||
ARRAY_FILTER([0, 2, 3], (e, i) -> e > i) |
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.
It may be useful to mention
len(Args) == 1
ifLparen.Invalid()
here and the above template doc. What do you think?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.
Updated e5e6033, d021e57