-
Notifications
You must be signed in to change notification settings - Fork 323
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
Autoscope syntax #9372
Autoscope syntax #9372
Conversation
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.
Way more elegant than my original isDotDotOperator
check. Thank you for implementing this so promptly.
engine/runtime-parser/src/main/java/org/enso/compiler/core/TreeToIr.java
Show resolved
Hide resolved
engine/runtime-parser/src/main/java/org/enso/compiler/core/TreeToIr.java
Show resolved
Hide resolved
engine/runtime-parser/src/main/java/org/enso/compiler/core/TreeToIr.java
Show resolved
Hide resolved
@@ -162,6 +162,11 @@ macro_rules! with_ast_definition { ($f:ident ($($args:tt)*)) => { $f! { $($args) | |||
pub opr: token::Operator<'s>, | |||
pub rhs: Option<Tree<'s>>, | |||
}, | |||
/// Application of the autoscope operator to an identifier, e.g. `..True`. | |||
AutoscopedIdentifier { |
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.
Right now we only support autoscoped constructors. Shouldn't this class be rather called AutoscopedConstructor
?
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.
That's a good question. I actually called it that originally, but then changed my mind. It felt odd to use the term constructor in the parser, when there is no clear syntactic distinction between a constructor reference and another type of identifier. The parser only knows that the operator has been applied to an identifier token, and I think it's up to the semantic layer to determine whether the ident refers to a constructor (which also has to be one of the constructors of the appropriate type, right?) or to something else entirely. So I guess the question is, should the parser name it based on what it is syntactically, or what it is in its semantically-valid usage? I'm inclined to the former; we'd be forgoing the merits of having the same (semantically-informed) term throughout the stack, but that makes sense to me because it's not the same thing in the parser and in the engine--the engine narrows it based on semantic constraints. Does that make sense to you @JaroslavTulach?
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.
@kazcw Do we still have the syntactic distinction between regular names and type-names/constructors? i.e. lowercase
name and Uppercase
constructor?
If so, we could raise a syntax error when we encounter the ..
operator with a lowercase name - because currently that is not valid syntax.
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.
Yeah, I can narrow it to capital (type-or-constructor) identifiers. I was also just thinking, the parser has 3 contexts: pattern, type, and expression.
- Clearly this is allowed in expression context.
- It should be disallowed in type contexts, right? Like
x : ..True
- What about patterns? Would it be a syntax error in the LHS of a case-of arrow?
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.
Indeed, currently I think we only allow autoscoping in the expression context.
So it seems sensible to raise a syntax error in the other contexts. @JaroslavTulach is that right?
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 patterns?
FYI: https://github.com/orgs/enso-org/discussions/8646#discussioncomment-8604696 - e.g. it is an error to use ..
in pattern matching LHS.
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.
Indeed, currently I think we only allow autoscoping in the expression context.
So it seems sensible to raise a syntax error in the other contexts. @JaroslavTulach is that right?
The most convincing @wdanilo argument against using ~
was that we couldn't differentiate between type and value level: https://github.com/orgs/enso-org/discussions/8646#discussioncomment-8677685
If we want to differentiate on the parser level between expression context and type context, can we go back to ~
;-? CCing @jdunkerley
The only file that parses differently after this PR is |
Pull Request Description
Add autoscope syntax (
..Ident
).Important Notes
Tree.Autoscope
toSuspendedDefaultArguments
.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.
./run ide build
.