DevPossible.Ton Project Documentation
Developed by DevPossible, LLC
Website: https://www.devpossible.com
Contact: support@devpossible.com
Library Version: 0.1.0
TON Spec Version: 1.0
Status: Initial Development
⚠️ INITIAL DEVELOPMENT (0.x.x) - This library is in active development. The TON file format specification is stable at version 1.0, but the library implementation is at version 0.1.0 and may undergo changes before reaching 1.0.0 stable release.
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
ALWAYS use PowerShell (pwsh) commands instead of bash/Linux commands when working in this Windows environment:
- Use
pwshor PowerShell cmdlets (Get-ChildItem, Copy-Item, Remove-Item, etc.) - Use Windows-style paths with backslashes (
C:\Dev\...) - Use
dotnetCLI commands for .NET operations - Avoid Linux/bash commands like
ls,rm,cp,grep, etc.
DevPossible.Ton is a complete .NET 8.0 library for parsing, validating, and serializing TON (Text Object Notation) files. TON is a human-readable data format that combines JSON-like simplicity with advanced features like schema validation, type annotations, enums, and hierarchical object structures.
Official TON Specification: https://tonspec.com
Developed and maintained by DevPossible, LLC
- Language: C# 12.0
- Framework: .NET 8.0
- Testing: xUnit with FluentAssertions and Moq
- Package Format: NuGet
- Development Environment: Windows with PowerShell
DevPossible.Ton/
├── DevPossible.Ton.slnx # Solution file
├── README.md # Comprehensive documentation
├── CLAUDE.md # This file
├── DOCUMENTATION.md # Documentation server guide
├── launch.ps1 # PowerShell documentation launcher
├── launch-docs.bat # Batch file documentation launcher
├── package.json # NPM scripts for documentation
├── doc/ # Documentation folder
│ └── doc-html/ # HTML documentation and web project
│ ├── index.html # Main documentation page
│ ├── css/ # Stylesheets
│ ├── js/ # JavaScript files
│ ├── images/ # Images and logos
│ └── (other HTML documentation files)
└── src/ # Source code for all languages
├── CSharp/ # C#/.NET implementation
│ ├── DevPossible.Ton/ # Main library project
│ │ ├── DevPossible.Ton.csproj # Project file
│ │ ├── DevPossible.Ton.nuspec # NuGet package specification
│ │ └── src/ # All source code
│ │ ├── Examples/ # Usage examples
│ │ ├── Interfaces/ # Public interfaces
│ │ ├── Lexer/ # Tokenization (TonLexer, TonToken)
│ │ ├── Models/ # Core data models (TonDocument, TonObject, TonValue, TonEnum)
│ │ ├── Parser/ # Parsing logic (TonParser, TonParseOptions)
│ │ ├── Schema/ # Schema definitions
│ │ ├── Serializer/ # Serialization (TonSerializer, TonSerializeOptions)
│ │ └── Validator/ # Validation logic (TonValidator)
│ ├── DevPossible.Ton.Tests/ # Test project
│ │ ├── DevPossible.Ton.Tests.csproj
│ │ └── (test files organized by category)
│ └── DevPossible.Ton.Samples/ # Sample applications
│ └── (sample code and examples)
├── JavaScript/ # JavaScript/TypeScript implementation
│ ├── devpossible-ton/ # Main library
│ │ ├── package.json
│ │ ├── tsconfig.json
│ │ ├── src/ # TypeScript source
│ │ └── tests/ # Jest tests
│ ├── devpossible-ton-samples/ # Sample applications
│ └── README.md # JavaScript-specific documentation
└── Python/ # Python implementation
├── devpossible_ton/ # Main library package
│ ├── setup.py
│ ├── pyproject.toml
│ ├── devpossible_ton/ # Python source
│ └── tests/ # Python tests
├── devpossible_ton_samples/ # Sample applications
└── README.md # Python-specific documentation
- ✅ Full TON specification parser with recursive descent
- ✅ Comprehensive lexer with all token types
- ✅ Schema validation with custom rules
- ✅ Flexible serialization with multiple formats
- ✅ Type safety with automatic conversions
- ✅ Array support with square bracket syntax
- ✅ Enum and EnumSet support
- ✅ Object hierarchy with class names and instance counts
- ✅ Comments (single-line // and multi-line /* */)
- ✅ Multiple number formats (decimal, hex 0xFF, binary 0b1010, scientific)
- ✅ GUID support (with and without braces)
- ✅ Type annotations (name:string) and hints ($, %, &, ^)
- Primitives: string, integer, float, boolean, null, undefined
- Special: GUID, Date (ISO 8601)
- Collections: Arrays with mixed types and nesting
- Enums: Single values (|value|) and sets (|val1|val2|)
- Objects: Nested structures with optional class typing
# Build solution
dotnet build
# Build in Release mode
dotnet build -c Release
# Clean build
dotnet clean# Run all tests
dotnet test
# Run with detailed output
dotnet test --verbosity normal
# Run specific test category
dotnet test --filter "Category=Parser"
# Run specific test
dotnet test --filter "FullyQualifiedName~Should_Parse_Simple_Object"# Create NuGet package
dotnet pack -c Release
# Pack with specific version
dotnet pack -c Release -p:PackageVersion=1.0.0
# The package will be in: src\CSharp\DevPossible.Ton\bin\Release\DevPossible.Ton.1.0.0.nupkg- Root namespace:
DevPossible.Ton - Lexer components:
DevPossible.Ton.Lexer - All other components use root namespace
- Classes: PascalCase (e.g.,
TonParser,TonDocument) - Interfaces: IPascalCase (e.g.,
ITonParser) - Methods: PascalCase
- Properties: PascalCase
- Private fields: _camelCase with underscore prefix
- Parameters and local variables: camelCase
- One primary class per file
- File name matches class name
- Related small classes/enums can be in same file
- Test files mirror source structure with "Tests" suffix
- Test files must include Test ID references in comments
- Unit Tests: For individual components (Parser, Lexer, Serializer, Validator)
- Integration Tests: For end-to-end scenarios
- Edge Case Tests: For boundary conditions and error cases
- Performance Tests: For large document handling
- Array Tests: Specific tests for array functionality
- All tests must include Test ID references (e.g.,
// @TestID: ARR-BASIC-001)
- 162 tests total, all passing
- Categories: Lexer, Parser, Serializer, Validator, Integration, EdgeCases, Performance, Arrays
- Update the relevant model/parser/serializer components
- Add corresponding tests
- Update documentation in README.md
- Run full test suite to ensure no regressions
- Use the TestConsole project for quick testing
- The TestConsole/Program.cs can be modified for specific scenarios
- Update version number in .csproj and .nuspec
- Document changes in release notes
- Ensure backward compatibility where possible
All implementations must be test-driven based on Gherkin specifications with Test IDs.
Gherkin files are located in:
/test/gherkin/- Primary specifications with Test IDs
Each scenario has a unique Test ID format:
@TestID: [CATEGORY]-[SUBCATEGORY]-[SEQUENCE]- Example:
@TestID: ARR-BASIC-001for basic array parsing
When implementing features:
- First read the Gherkin specification and note the Test ID
- Include Test ID reference in your test implementation
- Implement tests that match Gherkin scenarios exactly
- Implement code to make tests pass
- Never modify tests to match broken implementations
- Ensure Test ID consistency across C#, JavaScript, and Python
- Recursive descent parser with lookahead
- Token-based parsing from TonLexer
- Comprehensive error reporting with line/column info
- Compact: Minimal formatting, omits nulls
- Pretty: Human-readable with indentation and all features
- Custom: Fully configurable via TonSerializeOptions
- Schema-based validation
- Support for required fields, type checking, constraints
- Custom validation rules (min/max, pattern, etc.)
Currently, all features are implemented and all tests pass. Future enhancements could include:
- Performance optimizations for very large files
- Streaming support for huge documents
- Additional schema validation rules
- VS Code/Visual Studio syntax highlighting extension
The library uses specific exception types:
TonParseException: For parsing errors (includes line/column info)TonValidationException: For validation failuresArgumentException: For invalid inputsArgumentNullException: For null parameters where not allowed
- Lexer uses compiled regex for GUIDs
- Parser minimizes string allocations
- Serializer uses StringBuilder for efficiency
- Validator caches schema lookups
CRITICAL: Tests that correlate to Gherkin tests should not be updated to deviate from what the Gherkin test specifies. Tests that do not map to a Gherkin test should only be updated when the test needs to change because it no longer matches the actual implementation. See TEST_RULES.md and TEST_ID_GUIDELINES.md for comprehensive testing guidelines.
- Tests are driven by Gherkin specifications in
/test/gherkin/directory - Every test MUST reference its Test ID (e.g.,
@TestID: ARR-BASIC-001) - Gherkin-mapped tests must not deviate from their specification - fix the implementation instead
- Non-Gherkin tests should only change when implementation requirements change
- Maintain test parity across all language implementations
- Tests define the contract - implementations must meet test requirements
- Test IDs must be preserved when modifying or implementing tests
When modifying the codebase:
- Maintain the existing code style
- Add tests for new functionality based on Gherkin specs
- Update documentation as needed
- Ensure all tests pass before committing
- Use meaningful commit messages
- For Gherkin-mapped tests: Never deviate from the specification
- For non-Gherkin tests: Only update when implementation requirements change
This project is developed and tested on Windows but should work cross-platform wherever .NET 8.0 is supported. File paths in code use forward slashes for cross-platform compatibility, but documentation uses Windows-style paths.
© 2024 DevPossible, LLC. All rights reserved.
DevPossible, LLC
Website: https://www.devpossible.com
Email: support@devpossible.com
Developed and maintained with ❤️ for the developer community