Skip to content

Instantly share code, notes, and snippets.

@chinmaygarde
Created July 1, 2015 21:35
Show Gist options
  • Save chinmaygarde/1c0db4de8d03d12c84c3 to your computer and use it in GitHub Desktop.
Save chinmaygarde/1c0db4de8d03d12c84c3 to your computer and use it in GitHub Desktop.
class Foo {
Foo operator << (_) => new Foo();
Foo operator <= (_) => new Foo();
// For the last case below
Foo operator == (_) => new Foo();
}
main(List<String> arguments) {
var foo = new Foo();
// This works
foo << 1 << 2 << 3 << 4;
// This fails to parse
// foo <= 1 <= 2 <= 3 <= 4;
// I can add brackets to make the parser happy
(((foo <= 1) <= 2) <= 3) <= 4;
// But why?
// Also, why is this fine?
foo <= 2 == 3 < 4;
}
@bwilkerson
Copy link

Line 16 fails to parse because, unlike additiveExpression, which is defined to allow multiple operators:

additiveExpression:
    multiplicativeExpression (additiveOperator multiplicativeExpression)*

relational expressions are not:

relationalExpression:
    bitwiseOrExpression (typeTest | typeCast | relationalOperator bitwiseOrExpression)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment