yaml_rep
Version, currently master branch1 version
- master branchlatestNov 23, 2016
github.com/trans/yamldom.cr
YAML Intermediate Represention
Installation
# Add this to your shard.yml
dependencies:
yaml_rep:
github: trans/yamldom.cr
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
- no constraint declared
- License
- MIT
- Author
- trans
Dependencies
This version declares no dependencies.
README
YAML DOM
IMPORTANT!!! This project has been shit-canned because Crystal can't polymorph enumeration over Array and Hash. That makes this kind of API, while already difficult (because Crystal is a strongly typed language), essentially impossible. Sorry kids, you are stuck with pull parsing.
Intermediate Representation
The YAML DOM library provides a YAML composer that the models YAML Intermediate
Representation. This model preserves information lost when using the
current Crystal "parser". In particular tag information is preserved
and accessible.
Installation
Add this to your application's shard.yml:
dependencies:
yamldom:
github: trans/yamldom.cr
Usage
First, lets see how we can get the intermediate representation of a YAML document.
require "yamldom"
yaml = <<-YAML
--- !foo
- EXAMPLE
- 100
YAML
doc = YAML.compose(yaml)
doc.tag #=> "!foo"
doc.value #=> ["EXAMPLE", "100"]
doc.class #=> YAML::Sequence
There are a few things to notice here. First we were able to get the tag.
Second, the class of object compose retuirns a YAML::Node and there are
three types of such nodes, YAML::Scalar, YAML::Sequence and YAML::Mapping.
If we look at the elements inside the sequence we will see it is made up
of other nodes.
doc.value.node(0).to_s #=> "EXAMPLE"
doc.value.node(0).class #=> YAML::Scalar
We use #node to access the node itself. For convenience the usual #[] method accesses
the underlying value.
doc.value[0] #=> "EXAMPLE"
doc.value[0].class #=> String
This makes it fairly easy to work with the DOM API.
Lastly note that the value 100 in the document is still a String.
doc.value[0] #=> "100"
It isn't an Integer because composition is a stage before construction in which the node would be converted to a native data type (and extra information like tag lost).
Development
If you'd like to help this project improve, familiarize yourself with the YAML sepcification and have at it.
Contributing
- Fork it ( https://github.com/trans/yamldom/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- trans trans - creator, maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Nov 23, 2016
- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/trans/yamldom.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1
