# ETOOBUSY š minimal blogging for the impatient

# Ordeal::Model::Parser: grammar

**TL;DR**

Here you find the grammar for Ordeal::Model::Parser. Hopefully.

I didnāt write the grammar anywhere for documentation purposes - my bad
actually, so letās pay this *technical debt* now. Ehr yesā¦ by *reverse
engineering* the code š

The entry point in the grammar is `expression`

:

```
expression: addend ( addop addend )*
addend: ( positive_int multop )* atom ( multop positive_int )*
atom: ( identifier | sub_expression ) unaryop*
sub_expression: '(' expression ')'
addop: '-' | '+'
multop: '*' | 'x'
unaryop: shuffler | simple_slicer | slicer | sorter
shuffler: '@'
simple_slicer: int
slicer: '[' int_item_list ']'
sorter: '!'
int: simple_int | random_int
simple_int: /0|-?[1-9][0-9]*/
random_int: '{' int_item_list '}'
int_item_list: int_item ( ',' int_item )* (',')?
int_item: int_simple_range | int_range | int
int_simple_range: '#' positive_int
int_range: int '..' int
identifier: token | quoted_string
token: /[a-zA-Z][a-zA-Z0-9_]*/
quoted_string: /"([^\\"]|\\.)"/
positive_int: ...
```

I hope I didnāt get the symbols wrong:

- whitespacey stuff is not explicitly indicated to make stuff more readable
- quoted stuff is just what appears inside
- stuff between slashes are regular expressions (Backus and Naur will hopefully forgive me)
- the
`|`

character separates alternatives - the
`*`

character means āzero or more of thisā - the ā?ā character means āzero or one of thisā
- parentheses group stuff
- stuff in a sequence must appear in that sequence
- a
`positive_int`

is just like an`int`

where all actual integers inside are constrained to be strictly positive (it could be expanded in the grammar but it would be more boring than it already is!)

As anticipated, not too much of a grammar!

# The whole series

Want to look at the other parts of this series? Hereās a list of them:

- Global string matching quirks is not strictly in the series, but itās our first quest in Ordeal::Model::Parser and itās possibly the one giving a one single useful advice!
- A parser for Ordeal::Model is where the series start, introducing the motivations for the parser package.
- Ordeal::Model::Parser: grammar introduces the grammar.
- Ordeal::Model::Parser: entry point discusses the packageās main
entry point
`PARSE`

, which acts as a thin wrapper around`_expression`

. - Ordeal::Model::Parser: parsing generics deals with the starting generic helpers to build parsing functions.
- Ordeal::Model::Parser: parsing generics, 2 describes the
*hard stuff*like sequences, alternations, and the star operator. - Ordeal::Model::Parser: parsing gives an overview of the actual implementation of the grammar for Ordeal::Model.

*Comments? Octodon, , GitHub, Reddit, or drop me a line!*