-
Couldn't load subscription status.
- Fork 39
Add more (infix) operators #1091
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: master
Are you sure you want to change the base?
Conversation
| case _ => | ||
| val lhs = variable() | ||
| peek.kind match { | ||
| case `+=` | `-=` | `*=` | `/=` => |
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.
what about <<= and >>=?
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.
We decided to make some changes in the Effekt meeting. Thanks!
| case `<|` | ||
| case `|>` |
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.
We decided to delete these.
| case `||` => "infixOr" | ||
| case `&&` => "infixAnd" | ||
| case `===` => "infixEq" | ||
| case `!==` => "infixNeq" | ||
| case `<` => "infixLt" | ||
| case `>` => "infixGt" | ||
| case `<` => "infixLt" | ||
| case `>` => "infixGt" | ||
| case `<=` => "infixLte" | ||
| case `>=` => "infixGte" | ||
| case `+` => "infixAdd" | ||
| case `-` => "infixSub" | ||
| case `*` => "infixMul" | ||
| case `/` => "infixDiv" | ||
| case `+` => "infixAdd" | ||
| case `+=` => "infixAdd" | ||
| case `-` => "infixSub" | ||
| case `-=` => "infixSub" | ||
| case `*` => "infixMul" | ||
| case `*=` => "infixMul" | ||
| case `/` => "infixDiv" | ||
| case `/=` => "infixDiv" | ||
| case `++` => "infixConcat" | ||
| case `>>` => "infixShr" | ||
| case `<<` => "infixShl" | ||
| case `--` => "infixRemove" | ||
|
|
||
| case TokenKind.`~` => "infixTilde" | ||
| case TokenKind.`~>` => "infixTildeRight" | ||
| case TokenKind.`<~` => "infixTildeLeft" | ||
| case TokenKind.`|` => "infixPipe" | ||
| case TokenKind.`&` => "infixAmp" | ||
|
|
||
| case `<|` => "infixPipeLeft" | ||
| case `|>` => "infixPipeRight" | ||
| case `..` => "infixDotDot" | ||
| case `...` => "infixDotDotDot" | ||
| case `^^` => "infixHatHat" | ||
| case `^` => "infixHat" |
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.
Use syntactic not semantic names since they can be overloaded anyway.
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.
Claude suggested these names:
case `+` => "infixPlus"
case `+=` => "infixPlusEq"
case `-` => "infixMinus"
case `-=` => "infixMinusEq"
case `*` => "infixStar"
case `*=` => "infixStarEq"
case `/` => "infixSlash"
case `/=` => "infixSlashEq"
case `++` => "infixPlusPlus"
case `>>` => "infixGreaterGreater"
case `<<` => "infixLessLess"
case `--` => "infixMinusMinus"
case TokenKind.`~` => "infixTilde"
case TokenKind.`~>` => "infixTildeGreater"
case TokenKind.`<~` => "infixLessTilde"
case TokenKind.`|` => "infixBar"
case TokenKind.`&` => "infixAmp"
case `<|` => "infixLessBar"
case `|>` => "infixBarGreater"
case `..` => "infixDotDot"
case `...` => "infixDotDotDot"
case `^^` => "infixCaretCaret"
case `^` => "infixCaret"
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.
Of course, please also change the other operator names
| // <EXPR>.[<EXPR>, ...] | ||
| case `[` => | ||
| val bracket = peek | ||
| val arguments = some(expr, `[`, `,`, `]`) | ||
| e = MethodCall(e, | ||
| IdRef(Nil, "postfixAccess", Span(source, dot.start, bracket.end, Synthesized)), | ||
| Nil, arguments.unspan.map(a => ValueArg.Unnamed(a)), Nil, | ||
| Span(source, e.span.from, arguments.span.to, Synthesized) | ||
| ) | ||
|
|
||
| case _ => | ||
| val member = idRef() | ||
| // method call | ||
| if (isArguments) { | ||
| val (targs, vargs, bargs) = arguments() | ||
| e = Term.MethodCall(e, member, targs, vargs, bargs, span()) | ||
| } else { | ||
| e = Term.MethodCall(e, member, Nil, Nil, Nil, span()) | ||
| } |
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.
Extract into separate PR. Needs further discussion, e.g. setting an array. Do we also want a dedicated syntax for that?
This PR adds a few more infix operators. This is mostly just lexing and parsing so doesn't come with a lot of conceptual cost for the implementation.
A few things are not clear / implemented:
infixAddtoInfixPlus, but this will break a lot of things)a === banda !== bsince the tokens===are already used to represent==, ahhh.