Fix ASN.1 lexer: recognize minus sign and fix range operator#3060
Merged
birkenfeld merged 1 commit intopygments:masterfrom Mar 25, 2026
Merged
Fix ASN.1 lexer: recognize minus sign and fix range operator#3060birkenfeld merged 1 commit intopygments:masterfrom
birkenfeld merged 1 commit intopygments:masterfrom
Conversation
…tion Two fixes for the ASN.1 lexer: 1. Add `-` to the operator pattern so negative values in constraints like `(-50..150)` are tokenized correctly instead of producing an error token for the minus sign. 2. Require at least one digit after the decimal point in float literals (`\d+\.\d+` instead of `\d+\.\d*`). This prevents `50..150` from being incorrectly tokenized as float `50.` + punctuation `.` + int `150`, instead of the correct int `50` + range `..` + int `150`. Fixes pygments#3014. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Fixes #3014 — the ASN.1 lexer was producing an error token for the minus sign in value constraints like
(-50..150).Two issues found and fixed:
Missing
-operator: The operator regex didn't include-, so a standalone minus sign (used for negation in value ranges) was not matched by any rule and produced an error token. Fix: add-to the operator alternation.Float regex consuming
..range operator: The float pattern\d+\.\d*allowed zero digits after the decimal point, so50..150was incorrectly tokenized as float50.+ punctuation.+ int150instead of int50+ range operator..+ int150. Fix: require at least one digit after the decimal point (\d+\.\d+).Test plan
tests/snippets/asn1/negative-integer.txtcoveringTemperature ::= INTEGER (-50..150)tests/examplefiles/asn1/x509.asn1.outputgolden file (now correctly tokenizes..ranges)