Sha256: 1b6a0313f740e2a2b2df59696a8a9825cfc934b2a5e834342d0f049a14aea389

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

# Getting started 

## Installation

Install the gem and add it to your Gemfile:
```shell
$ bundle add dolos
```
Or manually:
```ruby
gem 'dolos'
```

## Usage

Two things to do:
- require library
- include module `Dolos` and `Dolos::Common`

```ruby
require 'dolos'

include Dolos
include Dolos::Common # Common parsers
```

### Basic parsers

A simple parser which matches one word.

```ruby
require 'dolos'
include Dolos

hello = c("Hello") # c("") is an alias for string(""). Can be read as: case-sensitive string match

hello.run("Hello").success? # => true

hello.run("hello").success? # => failure
```

After defining parser, it can be ran with `run('my-input')` method. It returns a `Result` object.

### Result

Result can be either `Success` or `Failure`. It can be checked with `success?` or `failure?` methods.

Success will also have `value` property which will contain the result of the parser. There is also `captures`, but 
that's for later.


Failure will have `inspect` method which will return a string with the error message. It will show error position as well.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dolos-0.3.1 docs/getting_started.md
dolos-0.3.0 docs/getting_started.md