Skip to content

geometry: accept tab as a numeric field separator - #125

Merged
tmolteno merged 2 commits into
tmolteno:masterfrom
KJ7LNW:fix-field-separator
Aug 3, 2026
Merged

geometry: accept tab as a numeric field separator#125
tmolteno merged 2 commits into
tmolteno:masterfrom
KJ7LNW:fix-field-separator

Conversation

@KJ7LNW

@KJ7LNW KJ7LNW commented Aug 3, 2026

Copy link
Copy Markdown

Description

Decks that separate geometry-card fields with tabs failed to load. Any card whose
numeric fields are tab-delimited aborted parsing at the first tab, so otherwise
valid models could not be solved. Spaces and commas already worked; tab was
simply absent from the terminator set used to close a numeric field.

The integer and real field scanners each carried their own inline terminator
test, so the two could disagree. This change gives both one shared separator
rule and adds a permanent regression test through the public file parser.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Implementation Details

  • src/c_geometry.cpp: adds the file-local query geometry_field_separator(),
    which classifies std::isspace() whitespace, the NEC comma, and the NUL
    terminating the loaded card. The character is converted to unsigned char
    before classification so negative plain-char values never reach the C
    character-classification interface. Both post-conversion scans in
    parse_geometry_card_line() call it, so the integer and real paths cannot
    drift apart. Numeric syntax checking stays in the existing scanner loops.
  • src/nec2cpp_tb.cpp: adds the regression described below.

Reproduction

<TAB> denotes one horizontal-tab byte, 0x09. Original failing deck line from
86-2-ex9.nec:

SP 0<TAB>0 .13795 .13795<TAB>.98079<TAB>78.75<TAB>45.<TAB>.11957

Before: parsing aborts at character 5, the tab immediately following the first
integer field:

GEOMETRY DATA CARD "SP" ERROR: NON-NUMERICAL CHARACTER '<TAB>' IN INTEGER FIELD AT CHAR. 5

After: the deck reaches its end card and reports TOTAL RUN TIME:.

Testing

The permanent regression writes this complete input to a temporary file, parses
it with c_geometry::parse_geometry(nec_context *, FILE *), and asserts the
segment count. It exercises tab termination in both the integer and the real
scanner.

GW<TAB>1<TAB>3<TAB>0<TAB>0<TAB>0<TAB>0<TAB>0<TAB>1<TAB>0.001
GE<TAB>0

Before: parsing aborts at the first tab after an integer field.
After: parsing completes with n_segments == 3.

cmake --build build --target nec2++ nec2++_tests
ctest --test-dir build --output-on-failure

Result:

All tests passed (568 assertions in 52 test cases)
  • Tests pass locally
  • New tests added for new functionality

Eric Wheeler added 2 commits August 2, 2026 21:56
The integer and real field scanners in parse_geometry_card_line() only
terminated a field on space, comma, or NUL. A tab immediately after a
field was consumed as part of the field instead of ending it, so decks
using tabs to separate geometry-card values (e.g. 86-2-ex9.nec) aborted
with "NON-NUMERICAL CHARACTER '<TAB>' IN INTEGER FIELD" at the tab
position.

- add geometry_field_separator(), classifying isspace(), comma, and NUL
  as one shared separator rule
- replace both duplicated scan-loop conditions with the new helper so
  the integer and real paths cannot diverge on what ends a field

Signed-off-by: Eric Wheeler <necpp@z.ewheeler.org>
The geometry parser previously rejected tab characters between fields on
geometry cards, aborting at the first tab following an integer field. This
adds a permanent regression test exercising that failure through the public
file parser.

- add a GW/GE deck delimited entirely by tabs and parse it through
  c_geometry::parse_geometry(nec_context *, FILE *), asserting n_segments == 3
  to confirm tab termination works in both the integer and real field
  scanners

Signed-off-by: Eric Wheeler <necpp@z.ewheeler.org>
@tmolteno
tmolteno merged commit 66ebf04 into tmolteno:master Aug 3, 2026
4 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.

2 participants