Skip to content

Commit 4248c91

Browse files
committed
docs
1 parent 581d940 commit 4248c91

File tree

1 file changed

+61
-27
lines changed

1 file changed

+61
-27
lines changed

readme.md

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ License: MIT
7373
- [Epsilon](#Epsilon)
7474
- [Tokens](#Tokens)
7575
- [Ident](#Ident)
76-
- [BigInt](#BigInt)
7776
- [Integer](#Integer)
77+
- [BigInt](#BigInt)
7878
- [Number](#Number)
7979
- [String](#String)
8080
- [Mapping](#Mapping)
@@ -237,11 +237,68 @@ const R2 = Runtime.Parse(T, 'Y Z') // const R2 = [[], 'Y Z']
237237

238238
## Tokens
239239

240-
ParseBox provides combinators for parsing common lexical tokens, such as numbers, identifiers, and strings, enabling static, optimized parsing of typical JavaScript constructs.
240+
ParseBox includes several specialized combinators used to quickly parse common language tokens.
241+
242+
### Ident
243+
244+
Parses an identifier
245+
246+
```typescript
247+
const Expression = Runtime.Number() // const Expression = { type: 'Number' }
248+
249+
const Let = Runtime.Tuple([ // const Let = {
250+
Runtime.Const('let'), // type: 'Tuple',
251+
Runtime.Ident(), // parsers: [
252+
Runtime.Const('='), // { type: 'Const', value: 'let' },
253+
Expression // { type: 'Ident' },
254+
]) // { type: 'Const', value: '=' },
255+
// { type: 'Number' },
256+
// ]
257+
// }
258+
259+
const R = Runtime.Parse(Let, 'let n = 10') // const R = [[ 'let', 'n', '=', '10'], '' ]
260+
261+
```
262+
263+
### Integer
264+
265+
Parses a literal integer
266+
267+
```typescript
268+
const T = Runtime.Integer()
269+
270+
// ...
271+
272+
const R1 = Runtime.Parse(T, '1') // const R1 = ['1', '']
273+
274+
const R2 = Runtime.Parse(T, '3.14') // const R2 = ['3', '.14']
275+
276+
const R3 = Runtime.Parse(T, '.1') // const R3 = []
277+
278+
const E = Runtime.Parse(T, '01') // const E = ['0', '1']
279+
```
280+
281+
### BigInt
282+
283+
Parses a literal bigint number. This combinator will succeed if the number is integer and trailed by a `n`. The `n` is omitted from the result.
284+
285+
```typescript
286+
const T = Runtime.BigInt()
287+
288+
// ...
289+
290+
const R1 = Runtime.Parse(T, '1n') // const R1 = ['1', '']
291+
292+
const R2 = Runtime.Parse(T, '1n2') // const R2 = ['1', '2']
293+
294+
const R3 = Runtime.Parse(T, '.1n') // const R3 = []
295+
296+
const E = Runtime.Parse(T, '01n') // const E = []
297+
```
241298

242299
### Number
243300

244-
Parses numeric literals, including integers, decimals, and floating-point numbers. Invalid formats, like leading zeroes, are not matched.
301+
Parses a number with fractional parts
245302

246303
```typescript
247304
const T = Runtime.Number()
@@ -254,7 +311,7 @@ const R2 = Runtime.Parse(T, '3.14') // const R2 = ['3.14', '']
254311

255312
const R3 = Runtime.Parse(T, '.1') // const R3 = ['.1', '']
256313

257-
const E = Runtime.Parse(T, '01') // const E = []
314+
const E = Runtime.Parse(T, '01') // const E = ['0', '1']
258315
```
259316

260317
### String
@@ -269,30 +326,7 @@ const T = Runtime.String(['"'])
269326
const R = Runtime.Parse(T, '"hello"') // const R = ['hello', '']
270327
```
271328

272-
### Ident
273-
274-
Parses valid JavaScript identifiers, typically used to extract variable or function names. The following example demonstrates parsing a `let` statement.
275-
276-
```bnf
277-
<let> ::= "let" <ident> "=" <number>
278-
```
279329

280-
```typescript
281-
const Expression = Runtime.Number() // const Expression = { type: 'Number' }
282-
283-
const Let = Runtime.Tuple([ // const Let = {
284-
Runtime.Const('let'), // type: 'Tuple',
285-
Runtime.Ident(), // parsers: [
286-
Runtime.Const('='), // { type: 'Const', value: 'let' },
287-
Expression // { type: 'Ident' },
288-
]) // { type: 'Const', value: '=' },
289-
// { type: 'Number' },
290-
// ]
291-
// }
292-
293-
const R = Runtime.Parse(Let, 'let n = 10') // const R = [[ 'let', 'n', '=', '10'], '' ]
294-
295-
```
296330

297331

298332
## Mapping

0 commit comments

Comments
 (0)