Skip to content

Allow backslashes in quoted strings (Windows paths); v0.3.6 - #6

Merged
hugary1995 merged 2 commits into
mainfrom
fix/hit-backslash-in-quoted-strings
Jul 9, 2026
Merged

Allow backslashes in quoted strings (Windows paths); v0.3.6#6
hugary1995 merged 2 commits into
mainfrom
fix/hit-backslash-in-quoted-strings

Conversation

@hugary1995

Copy link
Copy Markdown
Contributor

Problem

The HIT lexer excluded backslash from single- and double-quoted string content (the \\ in the IN_ARRAY / IN_DARRAY character classes), so a value like 'C:\Users\me\model' failed with unexpected character '\'. That makes Windows paths unrepresentable in a HIT file — the root cause behind neml2's Windows workarounds (applied-material-modeling/neml2#414), which currently forward-slash every path written into a compiled stub .i.

Fix

Drop backslash from those two character classes so it's a literal inside quoted strings. A single-quoted value is raw (no escaping semantics), so 'C:\Users\me\model' now tokenises as the literal string. Backward-compatible — it only accepts more input.

  • Only the lexer changes; generated/Lexer.cpp regenerated with the same flex 2.6.4 + flags the build uses (--noline), #line stripped. Parser untouched.
  • Triple-quoted strings already accepted backslashes; unquoted values are unchanged (quote your paths).
  • Adds a C++ (test_hit.cpp) and a Python (test_nmhit.py) test for a backslash path in both quote styles.

Verified locally on Linux (C++ ctest + 28 Python tests). Windows CI covers it too.

After merge

Tag v0.3.6 to publish the wheels, then neml2 can bump its nmhit pin and revert its interim forward-slash workarounds (the INTERIM (nmhit-backslash) markers).

🤖 Generated with Claude Code

The HIT lexer excluded backslash from single- and double-quoted string
content (the `\\` in the IN_ARRAY / IN_DARRAY character classes), so a
value like 'C:\Users\me\model' failed to parse ("unexpected character
'\'"). That makes Windows paths unrepresentable in a HIT file -- the root
cause behind neml2's Windows workarounds (issue #414), which had to
forward-slash every path written into a stub .i.

Drop backslash from those two character classes so it is a literal inside
quoted strings (no escaping semantics; a single-quoted value is raw). Only
the lexer's DFA tables change; regenerated generated/Lexer.cpp with the same
flex 2.6.4 + flags the build uses (Parser untouched). Triple-quoted strings
already accepted backslashes; unquoted values are unchanged (quote paths).

Adds a C++ and a Python test for a backslash path in both quote styles.
…latforms

Reflect the lexer change (array/quoted-string elements may now contain
backslashes, so Windows paths are representable) and state that nmhit
builds and is tested on Linux, macOS, and Windows (GCC/Clang/MSVC).
@hugary1995
hugary1995 merged commit d139155 into main Jul 9, 2026
10 checks passed
@hugary1995
hugary1995 deleted the fix/hit-backslash-in-quoted-strings branch July 10, 2026 00:00
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.

1 participant