Add python examples and relax integer parsing to accept ints in float representation#3
Merged
Conversation
This is the initial work for the nec-import crate, which will be responsible for parsing NEC files and converting them into a format that can be used by the rest of the Arcanum project. This commit includes the basic structure of the crate, as well as some initial tests and documentation. Also included are a CONTRIBUTING.md file and a GitHub Actions workflow for
Add example utilities and fix integer parsing for scientific notation Add two example Python programs in examples/: - nec2json.py: parses a .nec file and writes SimulationInput as JSON to stdout; warnings go to stderr; suitable for piping to jq or other tools - nec_inspect.py: prints a human-readable annotated breakdown of a parsed deck, organized by card category (geometry, ground, frequencies, excitations, loads, output requests, warnings) Fix FieldParseFailure when NEC generators write integer fields in scientific notation (e.g. "0.00000E+00"). Tools such as 4nec2 write every field uniformly in this format, including semantically-integer fields like the GM card's ITS (tag increment). The lexer now falls back to float parsing when i32 parsing fails, accepting the value as an integer if it has no fractional part. Non-whole floats in integer fields continue to produce a hard error. Add validation cases and Rust tests: - V-FMT-006: scientific notation accepted in integer fields (GM ITS field) - V-FMT-006 negative case: non-whole float in integer field still errors Update input-format.md Section 2.2 and validation.md to document this behavior and the new test cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added two python examples to demonstrate how to use the python bindings for nec-input.
nec_inspect.py parses a .nec inpout file and prints information about the cards
nec2json parses an input file and outputs the content in json
I encountered an issue because existing tools write .nec files with a float representation of integer fields, e.g. "0.00000E+00".
The parser now allows this if there is no fractional part of the value in an integer field.
I added test cases for this change, and updated the documentation.