···1010 <br />
1111</div>
12121313-Leveraging the power of sticky regexes and Babel code generation, `reghex` allows
1313+Leveraging the power of sticky regexes and JS code generation, `reghex` allows
1414you to code parsers quickly, by surrounding regular expressions with a regex-like
1515[DSL](https://en.wikipedia.org/wiki/Domain-specific_language).
1616···3030npm install --save reghex
3131```
32323333-##### 2. Add the plugin to your Babel configuration (`.babelrc`, `babel.config.js`, or `package.json:babel`)
3333+##### 2. Add the plugin to your Babel configuration _(optional)_
3434+3535+In your `.babelrc`, `babel.config.js`, or `package.json:babel` add:
34363537```json
3638{
···4143Alternatively, you can set up [`babel-plugin-macros`](https://github.com/kentcdodds/babel-plugin-macros) and
4244import `reghex` from `"reghex/macro"` instead.
43454646+This step is **optional**. `reghex` can also generate its optimised JS code during runtime only!
4747+4448##### 3. Have fun writing parsers!
45494650```js
4747-import match, { parse } from 'reghex';
5151+import { match, parse } from 'reghex';
48524953const name = match('name')`
5054 ${/\w+/}
···99103100104## Authoring Guide
101105102102-You can write "matchers" by importing the default import from `reghex` and
106106+You can write "matchers" by importing the `match` import from `reghex` and
103107using it to write a matcher expression.
104108105109```js
106106-import match from 'reghex';
110110+import { match } from 'reghex';
107111108112const name = match('name')`
109113 ${/\w+/}
110114`;
111115```
112116113113-As can be seen above, the `match` function, which is what we've called the
114114-default import, is called with a "node name" and is then called as a tagged
115115-template. This template is our **parsing definition**.
117117+As can be seen above, the `match` function, is called with a "node name" and
118118+is then called as a tagged template. This template is our **parsing definition**.
116119117120`reghex` functions only with its Babel plugin, which will detect `match('name')`
118121and replace the entire tag with a parsing function, which may then look like
···208211in the parsed string. This is just one feature of the regex-like DSL. The
209212available operators are the following:
210213211211-| Operator | Example | Description |
212212-| -------- | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
213213-| `?` | `${/1/}?` | An **optional** may be used to make an interpolation optional. This means that the interpolation may or may not match. |
214214-| `*` | `${/1/}*` | A **star** can be used to match an arbitrary amount of interpolation or none at all. This means that the interpolation may repeat itself or may not be matched at all. |
215215-| `+` | `${/1/}+` | A **plus** is used like `*` and must match one or more times. When the matcher doesn't match, that's considered a failing case, since the match isn't optional. |
216216-| `\|` | `${/1/} \| ${/2/}` | An **alternation** can be used to match either one thing or another, falling back when the first interpolation fails. |
217217-| `()` | `(${/1/} ${/2/})+` | A **group** can be used to apply one of the other operators to an entire group of interpolations. |
214214+| Operator | Example | Description |
215215+| -------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
216216+| `?` | `${/1/}?` | An **optional** may be used to make an interpolation optional. This means that the interpolation may or may not match. |
217217+| `*` | `${/1/}*` | A **star** can be used to match an arbitrary amount of interpolation or none at all. This means that the interpolation may repeat itself or may not be matched at all. |
218218+| `+` | `${/1/}+` | A **plus** is used like `*` and must match one or more times. When the matcher doesn't match, that's considered a failing case, since the match isn't optional. |
219219+| `\|` | `${/1/} \| ${/2/}` | An **alternation** can be used to match either one thing or another, falling back when the first interpolation fails. |
220220+| `()` | `(${/1/} ${/2/})+` | A **group** can be used to apply one of the other operators to an entire group of interpolations. |
218221| `(?: )` | `(?: ${/1/})` | A **non-capturing group** is like a regular group, but the interpolations matched inside it don't appear in the parser's output. |
219219-| `(?= )` | `(?= ${/1/})` | A **positive lookahead** checks whether interpolations match, and if so continues the matcher without changing the input. If it matches, it's essentially ignored. |
222222+| `(?= )` | `(?= ${/1/})` | A **positive lookahead** checks whether interpolations match, and if so continues the matcher without changing the input. If it matches, it's essentially ignored. |
220223| `(?! )` | `(?! ${/1/})` | A **negative lookahead** checks whether interpolations _don't_ match, and if so continues the matcher without changing the input. If the interpolations do match the matcher is aborted. |
221224222225We can combine and compose these operators to create more complex matchers.