Various improvements to the BQN lexer #2789
Merged
+52
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
EDIT: Apologies for the somewhat messy PR; perhaps conceptually some of these should go into different PRs. However, the changes are so small that I figured it was perhaps best to include them here as well.
Commit summary
Fix BQN lexer treating special characters as word chars
\wmatches all alphanumeric Unicode characters, including ones (e.g., 𝕊) that BQN treats special. This is especially troublesome for variables; previously, something likewould have returned
instead of
This extends to special sequences like
\b, which care about the difference between\wand\W.There are still some\b's in the code, but from what I can tell these don't produce any undesirable effects. E.g., for 2-modifiers, the BQN grammar already disallows writing something likeF_𝕣_Ginstead ofF _𝕣_ G. No guarantees that I caught everything, of course.This is, of course, nonsense, there are plenty of situations where this could arise that are accepted by BQN; e.g.,
_F ← {𝔽_𝕣},_D ← {𝔽_F𝕩}, etc. See the fixup commit.BQN lexer: Parse _𝕣 and 𝕣 correctly
BQN Lexer: Replace function * with ⋆
BQN does not actually use * (ASTERISK) anywhere, but there is a primitive function ⋆ (STAR OPERATOR).
BQN Lexer: Allow underscores in numbers
As per the spec.