kschiess/parslet — pull request #82 by RyanScottLewis (2013-04-28 03:25:36+00:00)
Title: Allow options in Parslet::ClassMethods.parse

This pull request allows options to be passed to the `rule` class method as well as specs to prove that they are working correctly.

### Options

***

`:predicate`

If `true`, it defines another rule with the atom `.maybe` attached to it.

*Without*

```rb
rule(:space) { str(' ') }
rule(:space?) { space.maybe }
```

*With*

```rb
rule(:space, predicate: true) { str(' ') }
```

***

`:repeat`

If `true`, it defines another rule with the atom `.repeat(1)` attached to it.

*Without*

```rb
rule(:space) { str(' ') }
rule(:spaces) { space.repeat(1) }
```

*With*

```rb
rule(:space, repeat: true) { str(' ') }
```

If a Hash is passed, it allows for extra options to be passed:

`:min` and `:max`

These allow a developer to set the min and max repeat arguments on the "repeated" rule.

*Without*

```rb
rule(:space) { str(' ') }
rule(:spaces) { space.repeat(3, 5) }
```

*With*

```rb
rule(:space, repeat: { min: 3, max: 5 }) { str(' ') }
```

`:predicate`

If `true`, it defines another "repeated" rule with the atom `.maybe` attached to it.

*Without*

```rb
rule(:space) { str(' ') }
rule(:spaces) { space.repeat(1) }
rule(:spaces?) { spaces.maybe }
```

*With*

```rb
rule(:space, repeat: { min: 3, max: 5, predicate: true }) { str(' ') }
```