Skip to content
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

Interaction between fractional literals and projections #876

Closed
yav opened this issue Sep 4, 2020 · 6 comments
Closed

Interaction between fractional literals and projections #876

yav opened this issue Sep 4, 2020 · 6 comments
Assignees
Labels
needs-test Missing a regression test in the test-suite parser Issues with lexing or parsing.
Milestone

Comments

@yav
Copy link
Member

yav commented Sep 4, 2020

In #875 points out that \x -> x.2.1 gives a parse error "unexpected 2.1" while previously it used to be two projections.

This is because the projection operator . is currently treated as its own operator, so the tokens for the body of the lambda are x, ., and 2.1`.

One way to fix this would be to say that we don't allow space after the . for a selector, so essentially a selector is its own token, like .2 for example. With this interpretation the tokens would be x, .2 and .2 and we'd get the old behavior.

@yav yav changed the title Interaction between fractional and projections Interaction between fractional literals and projections Sep 4, 2020
@robdockins
Copy link
Contributor

Humm... yeah that's annoying. I guess languages like JavaScript handle this by making field projections be identifiers.

I think it would be OK to disallow space after the . for projections. My only concern would be if people want to write long projection chains and put them on separate lines. Maybe it's OK if we allow this sort of thing:

someBigRecord
  .field1
  .field3
  .3.5.2
  .field20

@yav yav added needs-test Missing a regression test in the test-suite parser Issues with lexing or parsing. labels Sep 17, 2020
@brianhuffman
Copy link
Contributor

If we're going to reimplement the lexing and parsing rules for tuple projections, we might as well take care of #713 at the same time. Instead of allowing any numeric literal to be used as a tuple projection, we should allow only a list of decimal digits.

@brianhuffman
Copy link
Contributor

Something that might complicate this change a bit is that the record update syntax allows tuple selectors to appear without a preceding dot:

Cryptol> let x = (True, False)
Cryptol> { x | 1 = True }
(True, True)

@yav
Copy link
Member Author

yav commented Sep 21, 2020

That's a good point. I think we could get this to work with a bit of hackery in the parser though. Alternatively, we could go with the more consistent but uglier version where selectors always have dots at the front...

@brianhuffman
Copy link
Contributor

I should have suggested a nested tuple update like this:

Cryptol> let x = (True, (False, False))
Cryptol> { x | 1.0 = True }
(True, (True, False))

(This works in the current version only if you put a space before or after the dot in 1.0.)

@yav
Copy link
Member Author

yav commented Sep 21, 2020

This is the hackery I was referring to. A sequence like 1.2.3.4 would be tokenized as FRACTION, SELECTOR, SELECTOR. The hack would be that when we see a FRACTION at the root of a chain of selectors in an update field, we'd interpret it as two selectors instead of a fraction. Certainly a bit of a hack but I think it'd work, if we decided that this is the notation we want.

Let's discuss this in person during the ticket review tomorrow.

@atomb atomb added this to the 2.10.0 milestone Sep 22, 2020
@yav yav self-assigned this Sep 24, 2020
@yav yav closed this as completed in 5d04936 Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-test Missing a regression test in the test-suite parser Issues with lexing or parsing.
Projects
None yet
Development

No branches or pull requests

4 participants