RbToon
Toon is a structural text format optimized for LLM input. RbToon is a Racc-based decoder gem that decodes Toon input into Ruby objects.
Installation
Install the gem and add to the application’s Gemfile by executing:
bundle add rbtoon
If bundler is not being used to manage dependencies, install the gem by executing:
gem install rbtoon
Usage
You can use the methods below to decode Toon into Ruby objects.
-
Decode the given Toon string
-
Decode the Toon string read from the given file path
All hash keys are symbolized when the symbolize_names option is set to true.
require 'rbtoon' toon = RbToon.decode(<<~'TOON', symbolize_names: true) context: task: Our favorite hikes together location: Boulder season: spring_2025 friends[3]: ana,luis,sam hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}: 1,Blue Lake Trail,7.5,320,ana,true 2,Ridge Overlook,9.2,540,luis,false 3,Wildflower Loop,5.1,180,sam,true TOON # output # {context: {task: "Our favorite hikes together", location: "Boulder", season: "spring_2025"}, # friends: ["ana", "luis", "sam"], # hikes: # [{id: 1, name: "Blue Lake Trail", distanceKm: 7.5, elevationGain: 320, companion: "ana", wasSunny: true}, # {id: 2, name: "Ridge Overlook", distanceKm: 9.2, elevationGain: 540, companion: "luis", wasSunny: false}, # {id: 3, name: "Wildflower Loop", distanceKm: 5.1, elevationGain: 180, companion: "sam", wasSunny: true}]}
The RbToon::ParseError exception is raised if the given Toon includes errors listed in here.
begin RbToon.decode(<<~'TOON') freends[4]: ana,Luis,sam TOON rescue RbToon::ParseError => e puts e end # output # expected 4 array items, but got 3 -- filename: unknown line: 1 column: 8
For more details about APIs, please visit the documentation page.
Contributing
Bug reports and pull requests are welcome on GitHub at github.com/taichi-ishitani/rbtoon.
License
Copyright © 2025 Taichi Ishitani. RbToon is licensed under the terms of the MIT License, see LICENSE.txt for further details.