Show HN: YPS: YAML Positioning System

github.com

4 points by taichi730 17 hours ago

I'm pleased to introduce a new Ruby Gem: YPS: YAML Positioning System. https://github.com/taichi-ishitani/yps

YAML is a popular data serialization format in the Ruby ecosystem. We can easily parse YAML into Ruby objects using the built-in `YAML` standard library. However, it becomes difficult to pinpoint invalid or unexpected values within a large YAML document because the parsed Ruby objects lack position information (i.e., filename, line, and column).

YPS was developed to resolve this exact problem.

YPS parses a given YAML string and adds each parsed Ruby object, except for Hash key, with its position information. You can use `#position` method to get the position info of the receiver object like below:

``` require 'yps'

yaml = YPS.load(<<~'YAML') children: - name: kanta age: 8 - name: kaede age: 3 YAML

# output # name: kanta (filename: unknown line 2 column 11) # age: 8 (filename: unknown line 3 column 10) # name: kaede (filename: unknown line 4 column 11) # age: 3 (filename: unknown line 5 column 10) yaml['children'].each do |child| child.each do |key, value| puts "#{key}: #{value} (#{value.position})" end end ```