#Taffy - Yaml parser for Gleam

1 messages · Page 1 of 1 (latest)

willow kite
#

https://github.com/qwexvf/taffy

i was writing a few libs/services that required a yaml parser so i decided to a librarly for easy reuse.

simple exmaple to how to use it.

import gleam/io
import gleam/option.{Some}
import taffy

pub fn main() {
  let config = "
server:
  host: 0.0.0.0
  port: 8080
  workers: 4

database:
  url: postgres://localhost/myapp
  pool_size: 10
  timeout_ms: 5000

features:
  - auth
  - billing
  - webhooks

logging:
  level: info
  format: json
"

  let assert Ok(value) = taffy.parse(config)

  let assert Ok(port) = taffy.get_path(value, ["server", "port"])
  let assert Ok(db_url) = taffy.get_path(value, ["database", "url"])

  io.println("starting on port " <> taffy.to_yaml(port))
  io.println("db: " <> taffy.to_yaml(db_url))
}
GitHub

A pure Gleam YAML 1.2 parser - flexible and sweet 🍬 - qwexvf/taffy

crude wadi
#

Neat! What makes it distinct to the existing yaml parsers?

#

You should rename that .erl module to use the taffy name, currently it has a name belonging to a project called “native”

#

Iterating of a list of graphemes is very slow and memory expensive. If you’re looking for things to improve rewriting the lexer to use pattern matching and splitters would be excellent

willow kite
#

Hey! thanks for the quick review!

What makes it distinct to the existing yaml parsers?
i'm not sure about other parsers but i made this lib follwing the yaml spec 1.2 (https://yaml.org/spec/1.2.2/)
I should've check other parsers before making this 😅

#

Iterating of a list of graphemes is very slow and memory expensive.
Nice catch! going to fix this now!

crude wadi
#

Cool yeah, 1.2 is the one the existing libraries support

willow kite
#

just realized but writing a wrapper for yamerl was defenitaly the way and its easier 😄

proud palm
#

I think it would be neat to have a pure gleam one, the existing libraries I had seen were bindings to yamerl and a js package

#

Why is there a list of supported yaml features? Does it not support all of the features from the spec?

willow kite
#

it supports all features in the spec! ill make the description more simple!

pseudo frigate
#

This is very nice, seems it can handle multiline descriptions too.
I am parsing a rather large document where I encounter some indentation errors. It looks as if the line:column error printout is not right.
The errors occur on line 1993-1995 but printout is for line 237 and 235.

diff
1993,1995c1993,1995
<         - objectType
<         - clientID
<         - venName
---
>       - objectType
>       - clientID
>       - venName

I print err.pos and then the resolved taffy.error_location, first is all wrong indent, second top-most fixed, third second also fixed:

7017
Unexpected trailing content: indentation at 237:12
6925
Unexpected trailing content: indentation at 235:27
6928
Unexpected trailing content: indentation at 235:30
pseudo frigate
#

Ok, it seems that it errors on the parser.parsewhere the error position is the token position and not the string position.
Seems that taffy.error_locationlooks for the string position which it would be in case the lexer.tokenizefunction fails. I think...

willow kite
#

Thanks for the report!
Going to check this today!

willow kite
#

the pos calculation was wrong! shipping this fix soon

pseudo frigate
#

Yayy, justin place! Thanks.
Unexpected trailing content: indentation at 1993:19

pseudo frigate
#

Taffy is now "responsible" for openADR spec issue 1 .

#

Now I just need to find out why oas_generator complaints when I pass the json formatted spec into it. The error printout challenges the detective part of you really.
error: UnableToDecode expected Field found Nothing at components/schemas/problem/properties/status/$ref
The trailing $refin the path looks a bit suspicious...

pseudo frigate
#

Hmm, yes maybe good to read the docs too. oas_generatoris for clients, openADR for both services and clients (current understanding).

willow kite
#

can you try updateing to the latest version?

crude wadi
#

You can do gleam upgrade taffy

pseudo frigate