-
Notifications
You must be signed in to change notification settings - Fork 77
Add a special syntax for binary operators #1065
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
Comments
Cool, that you have done something. For me this topic is a hot potato that I would avoid to touch, since it is very subjective. There are already some solutions out there with different syntaxes. What I like:
What could be better:
Other proposal:
Instead of the equal alternative operator | we could use a ordered alternative operator like |>…
Instead of |
I agree with @Lotes here. I actually had a very similar syntax in mind: // Using `|` for normal alternatives, `,` for splitting operators
operator BinaryExpression on Primary:
'+' | '-', '*' | '/', '^', '..', '=';
// Use `<` and `>` for associativity
operator BinaryExpression on Primary:
<= '+' | '-', // left associative by default
<= '*' | '/',
=> '^', // right associative
<> '..', // no associativity
=> '='; // right associative again To explain my reasoning here a bit: Using I would also remove the infix information, since this style of operator usage is only useful in case you have an infix notation. Prefix notation can easily be parsed in a different way (think |
Add a rename operator as code actions I used |
Motivation is in the discussion #751.
The proposal is to add the ability to define binary operations shorter with the following syntax:
@binary_op
-- an annotation to defined a rule with the special syntaxleft_operand
,right_operand
,operator
-- arguments of the annotation that reflect property names in the generated interfaceBinaryExpression
left_operand
,right_operand
,operator
@binary_op
consists of comma-separated operator declarations; the order of these declarations reflects the operator precedenceinfix(r|l|n)
The syntax above must be semantically equivalent to the current syntax:
Unary operators must be defined using the current syntax, for example:
Both syntaxes have to generate the same types for the
ast.ts
:The text was updated successfully, but these errors were encountered: