Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ruby-next/paco
Paco is a parser combinator library inspired by Haskell's Parsec and Parsimmon.
https://github.com/ruby-next/paco
Last synced: about 1 month ago
JSON representation
Paco is a parser combinator library inspired by Haskell's Parsec and Parsimmon.
- Host: GitHub
- URL: https://github.com/ruby-next/paco
- Owner: ruby-next
- License: mit
- Created: 2021-12-12T16:47:50.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-12-27T08:07:24.000Z (12 months ago)
- Last Synced: 2024-11-09T05:48:39.916Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 70.3 KB
- Stars: 24
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Paco
[![Gem Version](https://badge.fury.io/rb/paco.svg)](https://rubygems.org/gems/paco)
[![Build](https://github.com/skryukov/paco/workflows/Build/badge.svg)](https://github.com/skryukov/paco/actions)Paco is a parser combinator library inspired by Haskell's [Parsec] and [Parsimmon].
"But I don't need to write another JSON parser or a new language, why do I need your library then?"
Well, most probably you don't. But I can think of rare cases when you do. Say, you need to write a validation for [git branch names].
You can go with easy-peasy regex:
```ruby
branch_name_regex = /^(?!\/|.*(?:[\/.]\.|\/\/|@{|\\|\.lock$|[\/.]$))[^\040\177 ~^:?*\[]+$/branch_name_regex.match?("feature/branch-validation")
```With Paco, you can go with a little more verbose version of that rule:
```ruby
module BranchNameParser
extend Pacoclass << self
def parse(input)
parser.parse(input)
enddef parser
lookahead(none_of("/")).next(valid_chars.join)
enddef valid_chars
any_char.not_followed_by(invalid_sequences).at_least(1)
end
def invalid_sequences
alt(invalid_chars, invalid_endings)
enddef invalid_chars
alt(
string("/."),
string(".."),
string("//"),
string("@{"),
string("\\\\"),
one_of("\040\177 ~^:?*\\[")
)
enddef invalid_endings
seq(
alt(string(".lock"), one_of("/.")),
eof
)
end
end
endBranchNameParser.parse("feature/branch-validation")
```Easy? Not really, but there is a chance you can read it. 😅
See [API documentation](docs/paco.md), [examples](examples) and [specs](spec) for more info on usage.
## Installation
Add to your `Gemfile`:
```ruby
gem "paco"
```And then run `bundle install`.
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. 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`.
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/skryukov/paco.
## Alternatives
- [parslet] - A small (but featureful) PEG based parser library.
- [parsby] — Parser combinator library for Ruby inspired by Haskell's Parsec.## License
The gem is available as open source under the terms of the [MIT License].
[MIT License]: https://opensource.org/licenses/MIT
[Parsec]: https://github.com/haskell/parsec
[Parsimmon]: https://github.com/jneen/parsimmon
[parslet]: https://github.com/kschiess/parslet
[parsby]: https://github.com/jolmg/parsby
[git branch names]: https://git-scm.com/docs/git-check-ref-format#_description