Project

seisu-ruby

0.0
The project is in a healthy, maintained state
A Ruby library that parses a string written in a custom mini-language and evaluates it to return an array of integers.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 2.0.0
 Project Readme

Seisu::Ruby

seisu-ruby is a library that parses a string written in a custom mini-language and evaluates it to return an array of integers.

For example, the input string "1, [3..5], odd{[8..12]}" would be evaluated to [1, 3, 4, 5, 9, 11].

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add seisu-ruby

If bundler is not being used to manage dependencies, install the gem by executing:

gem install seisu-ruby

Usage

The simplest way to use the library is to call the Seisu.parse method.

require 'seisu'

result = Seisu.parse("1, [3..5], odd{[8..12]}")
p result
#=> [1, 3, 4, 5, 9, 11]

Supported Syntax

The mini-language supports the following features:

Feature Syntax Example Result
Numbers 1, +5, -10 1, -5 [1, -5]
Ranges [start..end] [1..5] [1, 2, 3, 4, 5]
[5..1] [5, 4, 3, 2, 1]
Ranges with steps [start..end:step] [1..10:2] [1, 3, 5, 7, 9]
[10..1:-2] [10, 8, 6, 4, 2]
Union , 1, 2, 5 [1, 2, 5]
Difference ! [1..5] ! 3 [1, 2, 4, 5]
Parity Filters odd{...} / even{...} odd{[1..5]} [1, 3, 5]
even{[1..5]} [2, 4]
Grouping {...} {[1..3], 5} [1, 2, 3, 5]

Operator Precedence

The difference operator (!) has higher precedence than the union operator (,).

Seisu.parse("1, 2, 3 ! 3, 4, 5")
# is equivalent to "1, 2, (3 ! 3), 4, 5"
#=> [1, 2, 4, 5]

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/cu39/seisu-ruby.