~sircmpwn/hare#904: 
Tuple indexing lexing issues

Tuple indexing in Hare is currently kinda awful. The issue is x.0.0 should parse as getting the 0th element from the 0th element of x. But 0.0 is normally lexed as a float constant. So, currently the lexers in harec and hare::lex are context-dependent, since they don't lex float constants after a . token. We should put more thought into this syntax, so lexer hacks like this stop being necessary.

Status
REPORTED
Submitter
~sebsite
Assigned to
No-one
Submitted
1 year, 6 months ago
Updated
3 months ago
Labels
design

~sebsite 1 year, 4 months ago

One idea I brought up on IRC a while back was to just re-use array indexing syntax for tuples. so x.0.0 becomes x[0][0]. The one caveat is that the index needs to be translation compatible.

Another idea is to handle float literals in the parser rather than in the lexer. That is, integer literals are tokens, and float literals are expressions created with integer literal tokens and a "." token (or an "integer literal" with a float suffix). This would require that we store number literal tokens as strings, and delegate conversion to an actual number to the parser.

~sircmpwn 1 year, 10 days ago

Sebastian referenced this ticket in commit 18ecd83.

~sebsite 3 months ago

I've been thinking about this, and... maybe this is Fine actually. Like, it feels very icky that lexing is context-dependent, but the implementation isn't actually that difficult. The current syntax is nice to use, so maybe we should just accept that it introduces a quirk in the lexer and leave it as-is?

Register here or Log in to comment, or comment via email.