Skip to content

Hare: add word boundaries to as and is operators - #3309

Open
ump45nose wants to merge 1 commit into
pygments:masterfrom
ump45nose:fix/3308-hare-as-is-word-boundary
Open

ump45nose wants to merge 1 commit into
pygments:masterfrom
ump45nose:fix/3308-hare-as-is-word-boundary

Conversation

@ump45nose

Copy link
Copy Markdown

Fixes #3308.

Summary

The Hare lexer listed the operators as and is alongside the
symbol operators =>, .. and ... in a single words()
rule without word boundaries. Because as and is consist of
word characters, the rule matched them as a prefix of any identifier
starting with those letters, e.g. isfile was split into an
Operator is followed by Name file.

This change adds word boundaries to the word-like operators only, and
keeps the symbol operators (=>, .., ...) matching
unconditionally, as those must also match next to word characters
(e.g. i < len && arr[i].. style syntax).

Changes

  • pygments/lexers/hare.py: split the operator rule so as/is use
    prefix/suffix word boundaries while =>, .., ... stay
    unbounded.
  • tests/snippets/hare/test_keyword_operators.txt: regression snippet
    covering identifiers such as isfile, ascii, is_valid and the
    standalone as/is operators.
  • CHANGES: changelog entry under 2.22.0.

Tests

Verified locally with the full test suite:

  • pytest tests/ → 5331 passed, 16 skipped
  • The new regression snippet fails without the lexer change and passes
    with it.

The operators were matched anywhere, so identifiers such as `isfile`
were split into `is` and `file`. Only word-like operators need
boundaries; symbol operators like `=>` and `..` must keep matching
regardless of surrounding whitespace.

Fixes pygments#3308.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hare: as, is

1 participant