-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add tuple projection labels #819
base: develop
Are you sure you want to change the base?
Conversation
5017d6d
to
8fd8d8e
Compare
The thing that I am unsure about is how the new tokenization corresponds to the mental picture of the syntax. In my mind, the "dot" represents a separator which means that I expect that The way I see it, the main culprits are tuples and floats. I tested some variations on the dot as a separator in lambdas and could not find a good alternative. So I am throwing in some alternate suggestions of how this issue could be fixed:
|
I think your point 1 is a very neat change that also makes it so that labels fully overlap with identifiers, rather than identifiers and integers. Point 3 is also interesting in that it fixes the issue and enables some float syntax we wouldn’t have otherwise (also, e.g., After some thinking, I think I don’t support my previous suggestion any more, and that I’d rather do your 1, or 3, or drop tuple-projection. Dropping is a nice thing for a surface language intended to be read, since it encourages names, but of course, mcore isn’t a surface language. Then again, it’s a decently common feature in languages, and it would be nice to have a clean way of pprinting the corresponding mcore. |
I like point 1 because It removes one instance of syntactic sugar. I also like point 3. Not only for not overlapping with tuple projections, but I also think the code becomes more readable with an f suffix rather than, a possible non-existing, decimal. |
But alternative 1 would conflict with ordinary field names. I.e., "_0" is a legal identifier. That is, the syntactic sugar of tuples pollutes the ordinary namespace. This might be OK, but we need to think of the consequences of that. |
In terms of confusion when directly creating records? Or in general with labels starting with an underscore?
I think that this feels fine, the only potential issue I see in the short term is that we probably need to have some more metadata when pretty printing records. Such that a record explicitly created as There should be no syntax issue specific to tuple projection since that should equally apply to records. |
Technically the current way things work also has tuples pollute the ordinary namespace, it's just that it's a bit more inconvenient to write those labels since you have to say, e.g., The description of the syntax sugar for tuples would change roughly as follows:
becomes
along with the corresponding change for tuple types. The only change is that it's easier to write a record that looks like a mixed record and tuple; I also don't think we should special case and remember how things were printed originally, unless we want to do that for everything, e.g.,
|
Perhaps not in the case of MCore, but for a language intended for end users I think that this is quite important, especially when auto formatting the code. I would be quite annoyed if I write something as Having high-level hints of AST nodes being generated as part of syntactic sugar does not sound too unreasonable. These would likely get lost in certain transformations when compiling, but this syntactic information is not likely needed at that point. |
After discussions with @elegios, this PR also changes parsing of record projections so that
.<uint>
is now treated as a token. This means that it is now possible to write projections from nested tuples as:Before we had to project from nested tuples using
((1, (2, 3)).1).0
or(1, (2, 3)).1 .0
, as1.0
would parse as a float. However, this change means that we cannot write lambdas aslam x.1
, instead we need to write it aslam x. 1
.