uiua-lang / uiua

A stack-based array programming language
https://www.uiua.org
MIT License
1.51k stars 106 forks source link

Allow subscript numbers in identifiers #516

Closed Omnikar closed 2 months ago

Omnikar commented 2 months ago

Subscripts will format from __ followed by consecutive digits. Identifiers are canonicalized during parsing so that A__1 and A₁ resolve to the same identifier (A₁) even when code is not formatted.

kaikalii commented 2 months ago

Could cananicalization be done in the lexer? I think it makes more sense there.

Omnikar commented 2 months ago

That's what I initially thought, but at least from what I've gleaned from the code, the lexer returns identifier tokens as just the span they occupy in the code, so it's not possible for me to change the content of the actual identifier returned by the lexer. Since my other PR adding double exclamation points was also a form of identifier canonicalization, I just decided to put this in the same place.

Omnikar commented 2 months ago

Also, since there are multiple canonicalization steps now, should they be separated into a complete canonicalization function like canonicalize_ident that just calls canonicalize_exclams and canonicalize_subscripts?

kaikalii commented 2 months ago

Also, since there are multiple canonicalization steps now, should they be separated into a complete canonicalization function like canonicalize_ident that just calls canonicalize_exclams and canonicalize_subscripts?

Yes probably. Ya I forgot that about the ident tokens.

Omnikar commented 2 months ago

Okay I added canonicalize_ident.