Skip to content

LogicValue radix strings do not round-trip with literal or empty separators #722

Description

@Shubham-Padkonde

Describe the bug

LogicValue.toRadixString can produce a string that ofRadixString cannot read when both receive the same separator. Empty separators are accepted by the formatter but rejected by the parser; closing brackets and backslashes are interpolated into the parser's regular expression instead of being treated literally.

To Reproduce

import 'package:rohd/rohd.dart';

void main() {
  final value = LogicValue.ofInt(39, 10);
  for (final separator in ['', ']', r'\', '_']) {
    final encoded = value.toRadixString(sepChar: separator);
    try {
      print('$encoded -> ${LogicValue.ofRadixString(encoded, sepChar: separator)}');
    } catch (error) {
      print('$encoded -> $error');
    }
  }
}

Expected behavior

Each formatted value round-trips when its separator is passed to the parser. _ already works.

Actual behavior

  • Empty separator: LogicValueConstructionException: separation character invalid.
  • ]: LogicValueConstructionException: radix string stopped parsing at character position 5.
  • Backslash: FormatException: Unterminated character class.

Environment

Windows, Dart 3.13.4, current main d22fe80eb38241b524539ccbb9d6bd9842c943d3, ROHD 0.6.11.

Additional context

A local fix treats the separator literally using RegExp.escape and accepts an empty separator consistently with the formatter. Three new round-trip cases fail before and pass afterward; controls cover other punctuation separators, all five supported radices, and four-state values for non-decimal radices. The two LogicValue test modules pass all 181 tests. The full suite requires Icarus Verilog, which is unavailable locally. Investigation and validation used OpenAI Codex assistance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions