Fix re.match vs re.search bug in HaxeLexer and ActionScript3Lexer analyse_text#3035
Open
veeceey wants to merge 1 commit intopygments:masterfrom
Open
Fix re.match vs re.search bug in HaxeLexer and ActionScript3Lexer analyse_text#3035veeceey wants to merge 1 commit intopygments:masterfrom
veeceey wants to merge 1 commit intopygments:masterfrom
Conversation
… 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
analyse_textinHaxeLexerandActionScript3Lexerwhich usere.matchinstead ofre.searchto look for type annotation patterns (\w+\s*:\s*\w). Sincere.matchonly checks at the beginning of the string and source files typically start with comments, package declarations, or imports, the pattern almost never matches, makinganalyse_texteffectively non-functional for language detection.Fixes #3030
Changes
pygments/lexers/haxe.py:re.match->re.search, score0.3->0.1pygments/lexers/actionscript.py:re.match->re.search, score0.3->0.1Test plan
test_guess.pypass (no regressions)test_guess_carbon_lexerstill correctly identifies Carbon code (CarbonLexer returns 0.2, which beats HaxeLexer's 0.1)🤖 Generated with Claude Code