Skip to content

fix: lex a name starting with a cell address and a period - #67

Closed
gthb wants to merge 2 commits into
borgar:masterfrom
gthb:fix/lex-cellref-plus-dot-as-name
Closed

gthb wants to merge 2 commits into
borgar:masterfrom
gthb:fix/lex-cellref-plus-dot-as-name

Conversation

@gthb

@gthb gthb commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Lex a name that starts with a cell reference and then a period, as one token.

CH4.as.CO2e lexed as the range CH4 followed by an unknown .as.CO2e, so parse refused the formula.

Dotted sheet names broke similarly: TS1.5!B7 and EO9904.2!mthend (both in benchmark/formulas.json) lexed as range unknown context ! range.

A period after a range is one of two things:

  • it opens a trim operator (.:, .:.), and the range still ends;
  • it continues a name, and that must overrule the lexing of a range ... but only where that range text plus a period is valid as a name

(Or it may dereference a field of linked data in that cell. But that syntax is not supported yet, and anyway Excel's parser may well lex it as a name.)

New helper function periodContinuesName checks this when that period is hit:

  • the period must not be followed by a :

  • the period must be preceded by a run of [A-Za-z0-9]
    ... which starts with a letter
    ... and is not itself preceded by $ or [ or ] (the characters that are valid in a range and not in a name)

That check is enough, because it is reached only within lexRange, so we know the preceding characters are valid in a range token.

gthb added 2 commits September 6, 2026 23:56
Lex a name that starts with a cell reference and then a period, as one token.

`CH4.as.CO2e` lexed as the range `CH4` followed by an unknown `.as.CO2e`, so
`parse` refused the formula.

Dotted sheet names broke similarly: `TS1.5!B7` and `EO9904.2!mthend` (both in
`benchmark/formulas.json`) lexed as `range` `unknown` `context` `!` `range`.

A period after a range is one of two things:

- it opens a trim operator (`.:`, `.:.`), and the range still ends;
- it continues a name, and that must overrule the lexing of a range -- but only
  where that range text plus a period is valid as a name

(Or it may dereference a field of linked data in that cell. But that syntax is
not supported yet, and anyway Excel's parser may well lex it as a name.)

New helper function `periodContinuesName` checks this when that period is hit:

- the period must not be followed by a `:`

- the period must be preceded by a run of `[A-Za-z0-9]`
  ... which starts with a letter
  ... and is not itself preceded by `$` or `[` or `]`
  (the characters that are valid in a range and not in a name).

That check is enough, because it is reached only within `lexRange`, so we know
the preceding characters are valid in a range token.
The comment said Excel writes the reference unquoted. That is what the formula
bar shows; the file gets 'TS1.5'!B7. Measured on Excel for Mac, typed in and
hand-written into <f> alike, and on both sides of the resave.

The test is unaffected: Excel accepts the unquoted spelling as input, which is
why the lexer has to read it.
@borgar

borgar commented Sep 14, 2026

Copy link
Copy Markdown
Owner

I have made a simpler fix to this in #70.

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.

2 participants