Skip to content

Fix re.match vs re.search bug in HaxeLexer and ActionScript3Lexer analyse_text#3035

Open
veeceey wants to merge 1 commit intopygments:masterfrom
veeceey:fix/analyse-text-re-match-to-search
Open

Fix re.match vs re.search bug in HaxeLexer and ActionScript3Lexer analyse_text#3035
veeceey wants to merge 1 commit intopygments:masterfrom
veeceey:fix/analyse-text-re-match-to-search

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 10, 2026

Summary

  • Fix analyse_text in HaxeLexer and ActionScript3Lexer which use re.match instead of re.search to look for type annotation patterns (\w+\s*:\s*\w). Since re.match only checks at the beginning of the string and source files typically start with comments, package declarations, or imports, the pattern almost never matches, making analyse_text effectively non-functional for language detection.
  • Lower the priority score from 0.3 to 0.1 because this pattern is very generic and matches many languages (Python dict comprehensions, Carbon type annotations, etc.), avoiding false positives when guessing the lexer.

Fixes #3030

Changes

  • pygments/lexers/haxe.py: re.match -> re.search, score 0.3 -> 0.1
  • pygments/lexers/actionscript.py: re.match -> re.search, score 0.3 -> 0.1

Test plan

  • All 678 tests in test_guess.py pass (no regressions)
  • All 34 Haxe/ActionScript-related tests pass
  • test_guess_carbon_lexer still correctly identifies Carbon code (CarbonLexer returns 0.2, which beats HaxeLexer's 0.1)
  • HaxeLexer and AS3Lexer now correctly return 0.1 for typical source files that start with comments/imports

🤖 Generated with Claude Code

… ActionScript3Lexer

Both HaxeLexer.analyse_text and ActionScript3Lexer.analyse_text use
re.match to look for type annotation patterns (r'\w+\s*:\s*\w'), but
re.match only checks at the beginning of the string. Since source files
typically start with comments, package declarations, or imports, the
pattern would almost never match, making analyse_text effectively
useless for language detection.

Changed re.match to re.search so the pattern is found anywhere in the
text. Also lowered the priority from 0.3 to 0.1 because this pattern
is very generic and matches many languages (Python dicts, Carbon, etc).

Fixes pygments#3030

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

HaxeLexer.analyse_text and ActionScript3.analyse_text re.match bug

1 participant