Skip to content

Parsing: The '!' Alias Only Holds When It Is Glued to Both Sides - #1010

Open
daveycodez wants to merge 3 commits into
jbylund:mainfrom
daveycodez:bang-alias-adjacency
Open

Parsing: The '!' Alias Only Holds When It Is Glued to Both Sides#1010
daveycodez wants to merge 3 commits into
jbylund:mainfrom
daveycodez:bang-alias-adjacency

Conversation

@daveycodez

Copy link
Copy Markdown
Contributor

#971 made '!' an '=' alias on COLOR/MANA/NUMERIC/RARITY/YEAR/DATE, but both
parsers applied it across whitespace, which Scryfall does not. Measured live
on api.scryfall.com:

c!w      5,071        the alias
c !w         0        name-and-exact-name reading, not the alias
c! w     2,061        not the alias either
cmc!3    8,077        the alias
cmc !3       0
cmc! 3       0
r!rare  11,770        the alias
r !rare      0

So the alias requires the bang glued on BOTH sides. The hand parser now asks
space_before of the bang and of the token after it, in the NUMERIC branch and
the class-gated one; the pyparsing grammar spells the same rule as
leave_whitespace() on the bang plus a (?=\S) lookahead. A spaced bang keeps
exactly the exact-name-prefix reading a space always had — c !w parses as
it did before #971, and cmc !3 rejects as it did before #971.

Seven parity cases pin it: both parsers agree on every spaced spelling, and
none of them may produce the glued spelling's tree. Suite: api/parsing/tests
2,319 passed; ruff check and format clean.

(Found by review tooling on the Cloudflare port's sync of #971; the port carries the same fix so the two trees stay in step.)

jbylund#971 made '!' an '=' alias on COLOR/MANA/NUMERIC/RARITY/YEAR/DATE, but both
parsers applied it across whitespace, which Scryfall does not. Measured live
on api.scryfall.com:

    c!w      5,071        the alias
    c !w         0        name-and-exact-name reading, not the alias
    c! w     2,061        not the alias either
    cmc!3    8,077        the alias
    cmc !3       0
    cmc! 3       0
    r!rare  11,770        the alias
    r !rare      0

So the alias requires the bang glued on BOTH sides. The hand parser now asks
space_before of the bang and of the token after it, in the NUMERIC branch and
the class-gated one; the pyparsing grammar spells the same rule as
leave_whitespace() on the bang plus a (?=\S) lookahead. A spaced bang keeps
exactly the exact-name-prefix reading a space always had — `c !w` parses as
it did before jbylund#971, and `cmc !3` rejects as it did before jbylund#971.

Seven parity cases pin it: both parsers agree on every spaced spelling, and
none of them may produce the glued spelling's tree. Suite: api/parsing/tests
2,319 passed; ruff check and format clean.
@github-actions github-actions Bot added parser All things parser related api Changes to the HTTP API / request handling in api_resource.py tests Test suite additions or changes python size/S 32-99 changed lines labels Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Changes to the HTTP API / request handling in api_resource.py parser All things parser related python size/S 32-99 changed lines tests Test suite additions or changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant