Skip to content
generated from treeform/nimtemplate

a type-safe parser for a reasonable yaml dialect

License

Notifications You must be signed in to change notification settings

pietroppeter/yamly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. Indeed the implementation is a port of jsony to yaml.

Somewhat inspired by (Python library) 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. For another take of a restricted yaml parser, check out nyml. Ah, there is also 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

  • refactor to use YamlParseContext and YamlDumpContext?
  • refactor split in parse and dump separate submodules
  • symbols
    • numbers
      • dump
      • parse
      • octal and hex
    • bool
    • enum
  • containers
    • object
      • dump
        • dump key that needs to be quoted (e.g. starts with ", contains invalid characters, ...)
      • parse
      • flow-style
    • sequence
      • dump
      • parse
      • flow-style
    • tuple
    • array
      • 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?

About

a type-safe parser for a reasonable yaml dialect

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages