https://github.com/pietroppeter/yamly
a type-safe parser for a reasonable yaml dialect
https://github.com/pietroppeter/yamly
nim strictyaml yaml
Last synced: 2 months ago
JSON representation
a type-safe parser for a reasonable yaml dialect
- Host: GitHub
- URL: https://github.com/pietroppeter/yamly
- Owner: pietroppeter
- License: mit
- Created: 2023-01-02T20:27:27.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-03-31T12:37:27.000Z (about 3 years ago)
- Last Synced: 2025-08-15T04:46:41.673Z (10 months ago)
- Topics: nim, strictyaml, yaml
- Language: Nim
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yamly
⚠️ *work in progress*
A type-safe and loose parser for a reasonable yaml dialect (i.e. not the full yaml specs, but what you usually find around).
Parses yaml code directly to Nim types as in [jsony](https://github.com/treeform/jsony).
Indeed the implementation is a port of jsony to yaml.
Somewhat inspired by (Python library) [strictyaml](https://github.com/crdoconnor/strictyaml) for the idea that you should better give up on full Yaml specs and
and target a reasonable dialect (but I plan to support flow style)..
For a complete yaml 1.2 parser, use [NimYAML](https://github.com/flyx/NimYAML).
For another take of a restricted yaml parser, check out [nyml](https://github.com/openpeep/nyml).
Ah, there is also [yanyl](https://github.com/tanelso2/yanyl).
Features of Yaml that are **not** in scope of implementation:
- directives (stuff with %)
- anchors (&) and refs (*) and `<<`
- tagging with ! or !!
- complex mapping keys (which use ?)
- yaml set type (e.g. a list that uses `?` instead of `-`, or other formats). Note that a list can be parsed as set if the type is specified to be a nim bit set or hash set.
- cannot use tab for whitespace anywhere (in yaml you cannot use tab for indentation but you can use it for generic whitespace)
## todo
- [x] refactor to use YamlParseContext and YamlDumpContext?
- [x] refactor split in parse and dump separate submodules
- [ ] symbols
- [x] numbers
- [x] dump
- [x] parse
- [ ] octal and hex
- [ ] bool
- [ ] enum
- [ ] containers
- [ ] object
- [x] dump
- [ ] dump key that needs to be quoted (e.g. starts with ", contains invalid characters, ...)
- [ ] parse
- [ ] flow-style
- [ ] sequence
- [x] dump
- [ ] parse
- [ ] flow-style
- [ ] tuple
- [ ] array
- [x] dump
- [ ] sets
- [ ] tables
- [ ] string (non quoted, quoted and multiline)
- [ ] null
- [ ] "json"
- [ ] distinct
- [ ] document separator? which api?
## dev notes
- (!=yaml) disallowing tab in spaces
- (!=jsony) parseHook requires an indentation field
- (!=jsony) not implementing fast dumping and parsing of numbers
- (!=jsony) using unittest (I like the check output in case of failing test)
- (!=jsony) refactor api using YamlParseContext/YamlDumpcontext instead of exposing s, idx, ind in signatures
- (!=jsony) refactor: parse and dump are two separate modules
interesting features not (yet) present in jsony:
- strict mode
- easy way to skip fields when dumping
- automatic camel to snake when dumping?