Conversation
This commit improves the syntax for user operators to better align
with built-in operators and distinguish their syntax from user
functions.
The new syntax for op declarations is:
op name arg, arg, ... : ( ... )
and invoking an operator is now:
call name arg, arg, ...
with a short-cut where you can drop the "call" as a shortcut:
name arg, arg, ...
(as long as the shortcut is not a single operator with no arguments
inside of a subquery)
Updated documentation is coming in a subsequent PR from the book branch.
nwt
approved these changes
Sep 3, 2025
compiler/parser/parser.peg
Outdated
Comment on lines
+90
to
+94
| / !CallIDGuard id:Identifier _ !CallExprGuard args:Exprs { | ||
| return &ast.CallOp{Kind:"CallOp", Name: id.(*ast.ID), Args:sliceOf[ast.Expr](args), Loc:loc(c)}, nil | ||
| } | ||
| / !CallIDGuard id:Identifier &EndOfOp { | ||
| return &ast.CallOp{Kind:"CallOp", Name: id.(*ast.ID), Loc:loc(c)}, nil |
Member
There was a problem hiding this comment.
Nit: We usually name these for the field they initialize rather than their rule.
Suggested change
| / !CallIDGuard id:Identifier _ !CallExprGuard args:Exprs { | |
| return &ast.CallOp{Kind:"CallOp", Name: id.(*ast.ID), Args:sliceOf[ast.Expr](args), Loc:loc(c)}, nil | |
| } | |
| / !CallIDGuard id:Identifier &EndOfOp { | |
| return &ast.CallOp{Kind:"CallOp", Name: id.(*ast.ID), Loc:loc(c)}, nil | |
| / !CallIDGuard name:Identifier _ !CallExprGuard args:Exprs { | |
| return &ast.CallOp{Kind: "CallOp", Name: name.(*ast.ID), Args: sliceOf[ast.Expr](args), Loc: loc(c)}, nil | |
| } | |
| / !CallIDGuard name:Identifier &EndOfOp { | |
| return &ast.CallOp{Kind: "CallOp", Name: name.(*ast.ID), Loc: loc(c)}, nil |
compiler/parser/parser.peg
Outdated
Comment on lines
+423
to
+428
| = CALL _ id:Identifier args:((_ args:Exprs) { return args, nil })? { | ||
| op := &ast.CallOp{Kind:"CallOp", Name: id.(*ast.ID), Loc:loc(c)} | ||
| if args != nil { | ||
| op.Args = sliceOf[ast.Expr](args) | ||
| } | ||
| return op, nil |
Member
There was a problem hiding this comment.
Nits: Name the Identifier label for the field it initializes. And passing nil to sliceOf is safe.
Suggested change
| = CALL _ id:Identifier args:((_ args:Exprs) { return args, nil })? { | |
| op := &ast.CallOp{Kind:"CallOp", Name: id.(*ast.ID), Loc:loc(c)} | |
| if args != nil { | |
| op.Args = sliceOf[ast.Expr](args) | |
| } | |
| return op, nil | |
| = CALL _ name:Identifier args:((_ args:Exprs) { return args, nil })? { | |
| return &ast.CallOp{ | |
| Kind: "CallOp", | |
| Name: name.(*ast.ID), | |
| Args: sliceOf[ast.Expr](args), | |
| Loc: loc(c) | |
| }, nil | |
| } |
compiler/parser/parser.peg
Outdated
| // or an expression that is either an implied "values" (non-boolean) or an implied | ||
| // "where" (boolean). | ||
| // one of four shortcuts: a shortcut assignment for "put", a shortcut "aggregate", | ||
| // a shortcut "call" operator, or an expression that is either an implied "values" |
Member
There was a problem hiding this comment.
Nit: For consistency with the other items in this list.
Suggested change
| // a shortcut "call" operator, or an expression that is either an implied "values" | |
| // a shortcut "call", or an expression that is either an implied "values" |
Member
|
I think this new syntax looks really good! |
Co-authored-by: Noah Treuhaft <noah.treuhaft@gmail.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit improves the syntax for user operators to better align with built-in operators and distinguish their syntax from user functions.
The new syntax for op declarations is:
and invoking an operator is now:
with a short-cut where you can drop the "call" as a shortcut:
(as long as the shortcut is not a single operator with no arguments inside of a subquery)
Updated documentation is coming in a subsequent PR from the book branch.