Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 25, 2024
1 parent 5f75aee commit 8f4c123
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ License: MIT
## Combinators
ParseBox provides two sets of symmetric combinators for runtime and static environments, modeled on EBNF constructs. Instead of functions, these combinators are composable schema fragments that describe parse operations. Their schematics can be reflected to reconstruct BNF or remapped to other tools. The following section describes the Runtime combinators and their relation to EBNF.
ParseBox offers combinators for runtime and static environments, with each combinator based on EBNF constructs. These combinators produce schema fragments that define parse operations, which ParseBox interprets during parsing. As schematics, the fragments can also be reflected as EBNF or remapped to other tools. The following section examines the Runtime combinators and their relation to EBNF.
### Const
Expand Down Expand Up @@ -215,7 +215,7 @@ ParseBox provides combinators for parsing common lexical tokens, such as numbers

### Number

The Number combinator will parse a numeric literal.
Parses numeric literals, including integers, decimals, and floating-point numbers. Invalid formats, like leading zeroes, are not matched.

```typescript
const T = Runtime.Number()
Expand Down Expand Up @@ -245,18 +245,20 @@ const R = Runtime.Parse(T, '"hello"') // const R = ['hello', '']

### Ident

The Ident combinator parses valid JavaScript identifiers. The following parses a `let` statement.
Parses valid JavaScript identifiers, typically used to extract variable or function names. The following example demonstrates parsing a `let` statement.

```bnf
<let> ::= "let" <ident> "=" <number>
```

```typescript
const Expression = Runtime.Number() // const Expression = { type: 'Number' }

const Let = Runtime.Tuple([ // const Let = {
Runtime.Const('let'), // type: 'Tuple',
Runtime.Ident(), // parsers: [
Runtime.Const('='), // { type: 'Const', value: 'let' },
Runtime.Number() // { type: 'Ident' },
Expression // { type: 'Ident' },
]) // { type: 'Const', value: '=' },
// { type: 'Number' },
// ]
Expand Down Expand Up @@ -290,9 +292,9 @@ const Let = Runtime.Tuple([
Runtime.Number() // _3
], values => LetMapping(...values))

const R = Runtime.Parse(Let, 'let value = 10') // const R = [{
const R = Runtime.Parse(Let, 'let n = 10') // const R = [{
// type: 'Let',
// ident: 'value',
// ident: 'n',
// value: 10
// }, '' ]
```
Expand Down Expand Up @@ -320,9 +322,9 @@ type Let = Static.Tuple<[
Static.Number
], LetMapping>

type R = Static.Parse<Let, 'let value = 10'> // type R = [{
type R = Static.Parse<Let, 'let n = 10'> // type R = [{
// type: 'Let',
// ident: 'value',
// ident: 'n',
// value: 10
// }, '' ]
```
Expand Down

0 comments on commit 8f4c123

Please sign in to comment.