Skip to content

Fix ASN.1 lexer: recognize minus sign and fix range operator#3060

Merged
birkenfeld merged 1 commit intopygments:masterfrom
h1whelan:fix/asn1-negative-integers
Mar 25, 2026
Merged

Fix ASN.1 lexer: recognize minus sign and fix range operator#3060
birkenfeld merged 1 commit intopygments:masterfrom
h1whelan:fix/asn1-negative-integers

Conversation

@h1whelan
Copy link
Copy Markdown
Contributor

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:

  1. 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.

  2. Float regex consuming .. range operator: The float pattern \d+\.\d* allowed zero digits after the decimal point, so 50..150 was incorrectly tokenized as float 50. + punctuation . + int 150 instead of int 50 + range operator .. + int 150. Fix: require at least one digit after the decimal point (\d+\.\d+).

Test plan

  • Added tests/snippets/asn1/negative-integer.txt covering Temperature ::= INTEGER (-50..150)
  • Updated tests/examplefiles/asn1/x509.asn1.output golden file (now correctly tokenizes .. ranges)
  • All 768 snippet tests pass, all ASN.1 example file tests pass

…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>
@birkenfeld birkenfeld merged commit c3d93ad into pygments:master Mar 25, 2026
15 checks passed
@h1whelan h1whelan deleted the fix/asn1-negative-integers branch March 26, 2026 10:07
@Anteru Anteru added this to the 2.20.0 milestone Mar 26, 2026
@Anteru Anteru added the A-lexing area: changes to individual lexers label Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-lexing area: changes to individual lexers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The ASN.1 lexer seems to not accept negative integers

3 participants