Skip to content

fix: parse single-quoted values as backward-compat containers (#5, partial) - #33

Merged
jameskermode merged 1 commit into
masterfrom
fix/single-quote-arrays
Jun 9, 2026
Merged

jameskermode merged 1 commit into
masterfrom
fix/single-quote-arrays

Conversation

@jameskermode

Copy link
Copy Markdown
Member

What

The old Fortran/C extxyz reader treated ', " and {} as equivalent quote containers, but the new implementation dropped ' support. Real-world files using e.g. pbc='F F F' (see issue #8's example) therefore failed:

  • pure-Python backend: SyntaxError
  • C backend: silently fell back to defaults and dropped the value (so pbc wrongly became all-true)

This restores ' as a quote container equivalent to " — ints/floats/bools, no strings:

input result
pbc='F F F' pbc = [F, F, F]
k='1 2 3' int array [1, 2, 3]
k='3' scalar 3
k='hello' bare string 'hello' (unchanged — not numeric)

' and " now behave identically, on both backends.

How

One-line grammar change in grammar/extxyz_kv_grammar.py (adds a '…' Sequence to old_one_d_array). python/extxyz/extxyz_kv_grammar.py is a symlink to it and the C grammar is generated from it, so there's a single source of truth. Both tree walkers (parse_tree in extxyz.c, the pyleri visitor) dispatch on OLD_ONE_D_ARRAY + content type rather than the quote character, so no parser code change was needed. README spec updated.

Scope

This is the parser-only part of #5, per maintainer decision. The larger #5 proposal — a string-only single-quote container with writer-side disambiguation so strings that look like arrays round-trip — remains deferred (the thread never reached consensus: single-quote-as-string vs {"…"}). This PR deliberately does not close #5.

Verification

  • New tests/test_single_quote.py — 10 cases, both backends.
  • Full core suite (30) + ase-extxyz suite (38) green.
  • leaks clean on a single-quote file; C driver parses pbc/k correctly.

🤖 Generated with Claude Code

The old Fortran/C reader treated ', " and {} as equivalent quote containers,
but the new implementation had dropped ' support. Real-world files using e.g.
`pbc='F F F'` therefore failed: the pure-Python backend raised, and the C
backend silently fell back to defaults (losing the value).

Add ' as a quote container equivalent to " in the grammar (ints/floats/bools,
no strings) — one source of truth, since python/extxyz/extxyz_kv_grammar.py is
a symlink to grammar/extxyz_kv_grammar.py and the C grammar is generated from
it. Both tree walkers dispatch on OLD_ONE_D_ARRAY + content type, so no parser
code change was needed.

`'1 2 3'` -> int array, `'3'` -> scalar 3, `pbc='F F F'` -> [F,F,F]; `'hello'`
stays a bare string (non-numeric). The string-only single-quote container
(writer-side disambiguation) remains deferred as the larger issue #5 design.

README spec updated; new tests cover both backends; ase-extxyz suite + leaks
clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jameskermode
jameskermode merged commit 546eaa0 into master Jun 9, 2026
42 of 43 checks passed
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.

Round-tripping string values that look like backward compatible arrays

1 participant