rbtoon 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/lib/rbtoon/generated_parser.rb +737 -0
- data/lib/rbtoon/handler.rb +91 -0
- data/lib/rbtoon/nodes/array.rb +113 -0
- data/lib/rbtoon/nodes/base.rb +80 -0
- data/lib/rbtoon/nodes/blank.rb +15 -0
- data/lib/rbtoon/nodes/object.rb +106 -0
- data/lib/rbtoon/nodes/root.rb +29 -0
- data/lib/rbtoon/nodes/scalar.rb +81 -0
- data/lib/rbtoon/parse_error.rb +42 -0
- data/lib/rbtoon/parser.rb +37 -0
- data/lib/rbtoon/scanner.rb +452 -0
- data/lib/rbtoon/token.rb +33 -0
- data/lib/rbtoon/version.rb +7 -0
- data/lib/rbtoon.rb +126 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3f3136826afc12bca7e76d753814f29fb655ae4609e8efab50e70d2f49c1db3f
|
|
4
|
+
data.tar.gz: 1f9573d0e420ce219d19398c25d98790ef372b882ef16ebb739fe826fddcddcc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 39bf53267ebed69b0b417190c3c64ec9f4c5311cbd6ed8af1820643238f66f593a94028c79bb97f7b70ca2aac262d61ccf3f88feab934c4166ec54abf5db7d16
|
|
7
|
+
data.tar.gz: 9461f6cc52f02033e8f0c30e24f9e077125d9c20e728b0d691d37f73a15378a2fb1a7da5ee0e16448d2b5d4152c8cd24fda65dec6060f04417fe9b764471a706
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Taichi Ishitani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[](https://badge.fury.io/rb/rbtoon)
|
|
2
|
+
[](https://github.com/taichi-ishitani/rbtoon/actions/workflows/regression.yml)
|
|
3
|
+
[](https://codecov.io/gh/taichi-ishitani/rbtoon)
|
|
4
|
+
|
|
5
|
+
[](https://ko-fi.com/A0A231E3I)
|
|
6
|
+
|
|
7
|
+
# RbToon
|
|
8
|
+
|
|
9
|
+
[Toon](https://toonformat.dev) is a structural text format optimized for LLM input.
|
|
10
|
+
RbToon is a Racc-based decoder gem that decodes Toon input into Ruby objects.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bundle add rbtoon
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
gem install rbtoon
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
You can use the methods below to decode Toon into Ruby objects.
|
|
29
|
+
|
|
30
|
+
* Decode the given Toon string
|
|
31
|
+
* `RbToon.decode`
|
|
32
|
+
* Decode the Toon string read from the given file path
|
|
33
|
+
* `RbToon.decode_file`
|
|
34
|
+
|
|
35
|
+
All hash keys are symbolized when the `symbolize_names` option is set to `true`.
|
|
36
|
+
|
|
37
|
+
```ruby
|
|
38
|
+
require 'rbtoon'
|
|
39
|
+
|
|
40
|
+
toon = RbToon.decode(<<~'TOON', symbolize_names: true)
|
|
41
|
+
context:
|
|
42
|
+
task: Our favorite hikes together
|
|
43
|
+
location: Boulder
|
|
44
|
+
season: spring_2025
|
|
45
|
+
friends[3]: ana,luis,sam
|
|
46
|
+
hikes[3]{id,name,distanceKm,elevationGain,companion,wasSunny}:
|
|
47
|
+
1,Blue Lake Trail,7.5,320,ana,true
|
|
48
|
+
2,Ridge Overlook,9.2,540,luis,false
|
|
49
|
+
3,Wildflower Loop,5.1,180,sam,true
|
|
50
|
+
TOON
|
|
51
|
+
|
|
52
|
+
# output
|
|
53
|
+
# {context: {task: "Our favorite hikes together", location: "Boulder", season: "spring_2025"},
|
|
54
|
+
# friends: ["ana", "luis", "sam"],
|
|
55
|
+
# hikes:
|
|
56
|
+
# [{id: 1, name: "Blue Lake Trail", distanceKm: 7.5, elevationGain: 320, companion: "ana", wasSunny: true},
|
|
57
|
+
# {id: 2, name: "Ridge Overlook", distanceKm: 9.2, elevationGain: 540, companion: "luis", wasSunny: false},
|
|
58
|
+
# {id: 3, name: "Wildflower Loop", distanceKm: 5.1, elevationGain: 180, companion: "sam", wasSunny: true}]}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The `RbToon::ParseError` exception is raised if the given Toon includes errors listed in [here](https://github.com/toon-format/spec/blob/main/SPEC.md#14-strict-mode-errors-and-diagnostics-authoritative-checklist).
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
begin
|
|
65
|
+
RbToon.decode(<<~'TOON')
|
|
66
|
+
freends[4]: ana,Luis,sam
|
|
67
|
+
TOON
|
|
68
|
+
rescue RbToon::ParseError => e
|
|
69
|
+
puts e
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# output
|
|
73
|
+
# expected 4 array items, but got 3 -- filename: unknown line: 1 column: 8
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For more details about APIs, please visit the [documentation page](https://taichi-ishitani.github.io/rbtoon/).
|
|
77
|
+
|
|
78
|
+
## Contributing
|
|
79
|
+
|
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/taichi-ishitani/rbtoon.
|
|
81
|
+
|
|
82
|
+
* [Issue Tracker](https://github.com/taichi-ishitani/rbtoon/issues)
|
|
83
|
+
* [Pull Request](https://github.com/taichi-ishitani/rbtoon/pulls)
|
|
84
|
+
* [Discussion](https://github.com/taichi-ishitani/rbtoon/discussions)
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
Copyright © 2025 Taichi Ishitani.
|
|
89
|
+
RbToon is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT), see [LICENSE.txt](LICENSE.txt) for further details.
|