-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add CSON (CoffeeScript Object Notation) codec #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: streamich <[email protected]>
Co-authored-by: streamich <[email protected]>
Co-authored-by: streamich <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run linter and formatter when you are done.
src/cson/CsonDecoder.ts
Outdated
|
||
try { | ||
// Use the cson-parser library to parse the CSON text | ||
const csonParser = require('cson-parser'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not use cson-parser
implement the parsing from scratch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented a complete CSON parser from scratch without using the cson-parser
library. The new implementation supports all CSON features including comments, unquoted keys, flexible arrays, multi-line strings, and indentation-based nested objects. All 46 existing tests continue to pass. The dependency has been removed from package.json. (commit b0ab0bc)
Co-authored-by: streamich <[email protected]>
I've run both the linter and formatter on the codebase. All linting errors in the new CSON code have been fixed and the code has been properly formatted using Prettier. (commit b0ab0bc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run formatter and linter when done.
src/cson/CsonParser.ts
Outdated
* Supports CSON-specific features like comments, unquoted keys, and flexible syntax | ||
*/ | ||
|
||
export class CsonParser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do not create a seprate
CsonParser
class, parse inCsonDecoder
class. Decoder is our parser. - You have to parse from
Uint8Array
(useReader
), notstring
. See how it is done inJsonDecoder
and other codecs in this repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've implemented both requested changes:
-
Removed separate CsonParser class - All parsing logic is now directly integrated into the CsonDecoder class, following the same pattern as other decoders in the repository.
-
Parse from Uint8Array using Reader - The decoder now parses directly from bytes using the Reader class, eliminating the string conversion step. The implementation follows the same byte-level parsing approach as JsonDecoder with methods like
readValue()
,readString()
,readNumber()
, etc.
All 46 CSON tests continue to pass, and the full test suite (2775 tests) also passes. The refactor maintains all CSON features while improving performance through direct byte parsing.
(commit a16308b)
…ate parser class Co-authored-by: streamich <[email protected]>
…ctly in CsonDecoder with Uint8Array Co-authored-by: streamich <[email protected]>
Linter and formatter have been run successfully. The linter completed without any issues in the CSON code, and the formatter showed all files as "unchanged" indicating the code was already properly formatted. All 2775 tests continue to pass. (commit a16308b) |
This PR implements a complete CSON (CoffeeScript Object Notation) codec for the json-pack library, adding support for a human-readable alternative to JSON with enhanced syntax features.
What is CSON?
CSON is CoffeeScript Object Notation - a more flexible and readable format than JSON that supports:
#
) and multi-line (###
) comments'''
)Implementation
CsonEncoder
@jsonjoy.com/base64
utilities for binary data encodingCsonDecoder
cson-parser
library for robust parsingExample Usage
Testing
Documentation
Dependencies
cson-parser
for robust CSON parsing (minimal footprint)The CSON codec provides an excellent option for configuration files and human-editable data while maintaining json-pack's performance standards.
Fixes #23.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.