DEV Community

Cover image for Haye.cr: Expressive string syntax to Array/Hash and Vice-Versa parser for Crystal. Based on the javascript version.
Wilson Tovar
Wilson Tovar

Posted on

Haye.cr: Expressive string syntax to Array/Hash and Vice-Versa parser for Crystal. Based on the javascript version.

I have published the Crystal version of Haye: An expressive string syntax to Array/Hash and Vice-Versa parser for Crystal. Based on the javascript version.

GitHub repo: https://github.com/krthr/haye.cr

Here is an example:

Usage

require "haye.cr"
Enter fullscreen mode Exit fullscreen mode

Pipe -> Array

expression = 's'
parsed = Haye.fromPipe(expression) # Haye.fromPipe(expression, Haye::PresenterTypes::Array)
Enter fullscreen mode Exit fullscreen mode

Output (Haye::Presenters::Node[])

[
  #<Haye::Presenters::Node:0x7f11fd891e40 
    @name="required", 
    @args=[]
  >, 
  #<Haye::Presenters::Node:0x7f11fd891de0 
    @name="email", 
    @args=["unique", "users"]
  >
]
Enter fullscreen mode Exit fullscreen mode

Pipe -> Hash

expression = 's'
parsed = Haye.fromPipe(expression, Haye::PresenterTypes::Hash)
Enter fullscreen mode Exit fullscreen mode

Output (Hash)

{
  "required" => [], 
  "email" => ["unique", "users"]
}
Enter fullscreen mode Exit fullscreen mode

I hope you enjoy!

Top comments (0)