L43Peg
A Parse Expression Grammar library for Ruby
Table Of Contents
- Quick Start:
- Built In Parsers...
- Concepts...
- Combinators...
- Author
- LICENSE <!-- END TOC -->
Quick Start: ^
Given we import everyting into our namespace
require 'l43_peg'
Kernel.include L43Peg # not the same as RSpec's include
Then we can use the parse function to parse a string or an instance of Input
parse("a", with: char_parser) => Success
parse("a", with: char_parser("b")) => Failure
And parsers that do not need any arguments can be passed in as symbols
parse("a", with: :char_parser) => :ok, "a", _
And we can deconstruct the result into a status, ast and the rest Input instance.
parse("a", with: char_parser) => :ok, "a", {src: ""}
parse("ab", with: char_parser) => :ok, "a", {src: "b"}
parse(Input.new(src: "ab"), with: char_parser) => :ok, "a", {src: "b"}
And we can also deconstruct it into a Hash which provides even more information
parse("+42", with: int_parser) => {ok: true, ast: 42, parsed: "+42"}
Complete Documentation
Built In Parsers... ^
...are described here
Concepts... ^
...are described here
Combinators... ^
... which are the working horses of any PEG library are described here
Author ^
Copyright © 202[4,5,6] Robert Dober robert.dober@gmail.com
LICENSE ^
GNU AFFERO GENERAL PUBLIC LICENSE, Version 3, 19 November 2007. Please refer to LICENSE for details.
<!-- SPDX-License-Identifier: AGPL-3.0-or-later -->