Repository navigation
v0.4.0
Added
-
Comment Support: CTON now supports single-line comments using
#syntax. Comments are ignored during parsing, allowing for annotated data files.- Decoder skips comments (from
#to end of line) during parsing - Encoder can emit comments via new
comments:option:Cton.dump(data, comments: { "key" => "description" })
- Decoder skips comments (from
-
Validation API: New methods to validate CTON syntax without full parsing:
Cton.valid?(string)returnstrueorfalseCton.validate(string)returns aValidationResultobject with detailed error informationValidationResultincludesvalid?,errors, andto_smethodsValidationErrorincludesmessage,line,column, andsource_excerpt
-
Token Statistics API: Analyze and compare CTON vs JSON token efficiency:
Cton.stats(data)returns aStatsobject with comprehensive metricsCton.stats_hash(data)returns stats as a HashStatsincludesjson_chars,cton_chars,savings_percent,estimated_json_tokens,estimated_cton_tokensStats.compare(data)compares multiple format variants (CTON, CTON inline, CTON pretty, JSON, JSON pretty)
-
Custom Type Registry: Register custom serializers for domain objects:
Cton.register_type(klass, as: :object) { |value| ... }registers a type handlerCton.unregister_type(klass)removes a handlerCton.clear_type_registry!clears all handlers- Supports
:object,:array, and:scalarmodes
-
Enhanced CLI: New command-line options:
--stats/-s: Show token savings statistics comparing JSON vs CTON--validate: Validate CTON syntax without conversion--minify/-m: Output CTON without separators (fully inline)- Improved error messages with line/column information and colored output
-
Enhanced Error Reporting:
ParseErrornow includes structured location information:lineandcolumnattributes for precise error locationsource_excerptshowing context around the errorsuggestionsarray for helpful hintsto_hmethod for programmatic error handling