Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 22, 2024
1 parent d70ec22 commit c0e64fb
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,31 @@ ParseBox provides encoding of BNF notation in Static and Runtime environments.
<T> ::= "X" "Y" "X"
```

**Production**
**Type**

```typescript
const T = ["X", "Y", "Z"]
```

**TypeScript**
**Static**

```typescript
import { Static } from '@sinclair/parsebox'

type T = Static.Tuple<[
Static.Const<'X'>,
Static.Const<'Y'>,
Static.Const<'Z'>
]>

type R = Static.Parse<T, 'X Y Z W'> // type R = [['X', 'Y', 'Z'], ' W']
```
**Runtime**
```typescript
import { Runtime, Static } from '@sinclair/parsebox'

// Runtime Parser
import { Runtime } from '@sinclair/parsebox'

const T = Runtime.Tuple([
Runtime.Const('X'),
Expand All @@ -52,15 +65,6 @@ const T = Runtime.Tuple([

const R = Runtime.Parse(T, 'X Y Z W') // const R = [['X', 'Y', 'Z'], ' W']

// Static Parser

type T = Static.Tuple<[
Static.Const<'X'>,
Static.Const<'Y'>,
Static.Const<'Z'>
]>

type R = Static.Parse<T, 'X Y Z W'> // type R = [['X', 'Y', 'Z'], ' W']
```

Which can be used to construct [Expression](https://www.typescriptlang.org/play/?moduleResolution=99&module=199#code/JYWwDg9gTgLgBAbzgZRgQxsAxnAvnAMyghDgHIABAZ2ADssAbNYKAejDSioFMAjCAB5kAUMNas4AWmkzZc+QsVLlKyWIkBRAWnANu6qaqPGTq0TACeYbnABK3KgFcG8ALwp0mLADoACpx4AHi0wKAAacgE4ACo4AAoLOABqOAAvAEoyAD44XNzxOEtrOwdnNzgAbQRhPNq6+obGpuaC3L0CGAAuOAAiAR6AbhrmkdGxuta4CGsoDGhunujB4fHVtYmJXKhgAHMACy7EFfWT8cna9sOei2XTu7HzvOnuWZh53qTb++-Gx63dg4LVJfH6gvKTXBDMHQuAFXARH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ax](https://www.typescriptlang.org/play/?moduleResolution=99&module=199#code/JYWwDg9gTgLgBAbzgBQIZQM4FM4F84BmUEIcA5AAIbAB2AxgDarBQD0MAnmFgEYQAerDBxoxU-MgChQkWIjgBlMTGB08hYqUrV6TFuy68BUyXQg0M8AGIQIcALwp02ABQADEBAAmAVwY4bOwRJSTg4Tm44ACEHULCUVQBrAB4AQQAacmAvMgA+OAAyODiwtFhgVAZkgHkQYBg0zLJsvNyQsIicVIdEErhsgC44SyhaAHM+mm8sDCHUgG0AXTjcENw3AEoQswt4GMdAgDoASXBoGBcyKLItyU7onqVUFTpkzogCaPz4n9-WVnChgejmCvzB4IhkPi-1+g2GMFGNDGAG4+lD0Ri4DD8EVQZj8VCYT8pl4ZgB+IZ4gnUv4AiFwkbjVE0lnQungkkzIaHHlLZmsllE+K4JZwAA+cB8NFJBFoWC8-IF1OxQA) parsers at runtime and inside the type system.
Expand All @@ -77,11 +81,11 @@ License MIT

## Contents

- [Standard](#Parsers)
- [Standard](#Standard)
- [Const](#Const)
- [Tuple](#Tuple)
- [Union](#Union)
- [Extended](#Parsers)
- [Extended](#Extended)
- [Array](#Array)
- [Optional](#Optional)
- [Terminals](#Terminals)
Expand Down Expand Up @@ -110,7 +114,7 @@ The Const combinator parses for the next occurrence of the specified string. Whi
<T> ::= "X"
```

**Production**
**Type**

```typescript
type T = 'X'
Expand All @@ -137,7 +141,7 @@ The Tuple parser matches a sequence of interior parsers. An empty tuple can be u
<T> ::= "X" "Y" "Z"
```

**Production**
**Type**

```typescript
type T = ['X', 'Y', 'Z']
Expand Down Expand Up @@ -169,7 +173,7 @@ The Union combinator parses using one of the interior parsers, attempting each i
<T> ::= "X" | "Y" | "Z"
```

**Production**
**Type**

```typescript
type T = 'X' | 'Y' | 'Z'
Expand Down Expand Up @@ -208,7 +212,7 @@ The Array combinator will parse for zero or more the interior parser. This combi
<T> ::= { "X" }
```

**Production**
**Type**

```typescript
type T = 'X'[]
Expand Down Expand Up @@ -239,7 +243,7 @@ The Optional combinator will parse for zero or one of the interior parser. This
<T> ::= [ "X" ]
```

**Production**
**Type**

```typescript
type T = ['X'] | []
Expand Down

0 comments on commit c0e64fb

Please sign in to comment.