Skip to content

Conversation

@SrRapero720
Copy link
Member

No description provided.

claude and others added 6 commits November 17, 2025 11:43
Implemented a complete CFGFormat class with high-performance native parser and writer.

Features:
- Native parser optimized for performance using char array processing
- Support for native CFG types: strings, numbers, booleans, arrays
- Section headers with [section.subsection] syntax
- Comments with # and // syntax
- Both quoted and bare keys
- Escape sequences in strings (\n, \t, \r, \\, \", etc)
- Array support with flexible formatting [item1, item2, ...]
- Dual separator support (= and :)
- Proper error handling with descriptive messages

Implementation details:
- FormatWriter: Buffers all output for performance, writes on close()
- FormatReader: Single-pass parser with minimal allocations
- Follows the same patterns as TOMLFormat and JSONFormat
- LinkedHashMap for preserving key order
- Stack-based group management for nested sections

The implementation is focused on performance while maintaining code clarity
and robustness, following the project's coding standards.
Fixed CFGFormat to follow the actual CFG specification from red-dove.com.
CFG is a superset of JSON, not a TOML-like format.

Key changes:
- Top-level is a mapping enclosed in { }
- Uses JSON-like syntax with : or = as separators
- Keys can be identifiers or quoted strings
- Newlines act as separators (trailing commas optional)
- Nested mappings use { } blocks, not [section] headers
- Comments with #
- Support for cross-references ${...} (basic parsing)
- Support for include directives @'file.cfg' (basic parsing)
- Support for special values `...` (basic parsing)

Native type support:
- Strings (single or double quotes)
- Numbers (integers, floats, hex like 0x123)
- Booleans (true/false)
- null
- Arrays with flexible formatting
- Nested mappings

Performance optimizations:
- Single-pass parser with char array processing
- Minimal allocations
- Buffered output for writer
- LinkedHashMap for key order preservation

Example CFG format:
{
  string_value: 'hello'
  integer_value: 42
  nested: {
    key: 'value'
  }
  list: [1, 2, 3]
}
The comments were appearing on the same line as the previous field's value
because newlines were missing after writing values and arrays. This caused
comments for field N to appear at the end of field N-1's line.

Fixed by adding newlines after:
- Single value writes
- Array writes

Now the output properly shows:
  field1: value1
  # Comment for field2
  field2: value2

Instead of:
  field1: value1  # Comment for field2
  field2: value2
Changed comment placement logic to add a blank line BEFORE comments
(when present), not after field values. This produces the desired format:

  field1: value1

  # Comment for field2
  field2: value2

Instead of:

  field1: value1
  # Comment for field2

  field2: value2

The comment is now tightly coupled with its field, with separation
from the previous field via a blank line above the comment block.
@SrRapero720 SrRapero720 merged commit 79eb6fb into main Nov 17, 2025
1 check 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.

3 participants