Skip to content

Commit 0cfaed9

Browse files
committed
updates
1 parent 8ca92be commit 0cfaed9

File tree

18 files changed

+148
-174
lines changed

18 files changed

+148
-174
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export interface Array<Parser extends IParser = IParser, Mapping extends IMappin
4040
// Parse
4141
// ------------------------------------------------------------------
4242
export type ParseArray<Parser extends IParser, Input extends string, Result extends unknown[] = []> = (
43-
Parse<Parser, Input> extends [infer Element extends unknown, infer Rest extends string]
44-
? ParseArray<Parser, Rest, [...Result, Element]>
43+
Parse<Parser, Input> extends [infer Element extends unknown, infer InputRest extends string]
44+
? ParseArray<Parser, InputRest, [...Result, Element]>
4545
: [Result, Input]
4646
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import type { IParser, IMapping, Identity } from './parser.ts'
30-
import * as Token from '../../token/index.ts'
30+
import * as Token from '../token/index.ts'
3131

3232
// ------------------------------------------------------------------
3333
// Type
@@ -40,5 +40,5 @@ export interface Const<Const extends string = string, Mapping extends IMapping =
4040
// Parse
4141
// ------------------------------------------------------------------
4242
export type ParseConst<Const extends string, Input extends string> = (
43-
Token.TConst<Input, Const>
43+
Token.TConst<Const, Input>
4444
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import type { IParser, IMapping, Identity } from './parser.ts'
30-
import * as Token from '../../token/index.ts'
30+
import * as Token from '../token/index.ts'
3131

3232
// ------------------------------------------------------------------
3333
// Type

src/static/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,15 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
export * as Static from './static.ts'
29+
export * from './array.ts'
30+
export * from './const.ts'
31+
export * from './ident.ts'
32+
export * from './number.ts'
33+
export * from './optional.ts'
34+
export * from './parse.ts'
35+
export * from './parser.ts'
36+
export * from './string.ts'
37+
export * from './tuple.ts'
38+
export * from './union.ts'
39+
export * from './until_1.ts'
40+
export * from './until.ts'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import type { IParser, IMapping, Identity } from './parser.ts'
30-
import * as Token from '../../token/index.ts'
30+
import * as Token from '../token/index.ts'
3131

3232
// ------------------------------------------------------------------
3333
// Type
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export interface Optional<Parser extends IParser = IParser, Mapping extends IMap
3939
// ------------------------------------------------------------------
4040
// Optional
4141
// ------------------------------------------------------------------
42-
export type ParseOptional<Input extends string, Parser extends IParser> = (
43-
Parse<Parser, Input> extends [infer Value extends unknown, infer Rest extends string]
44-
? [[Value], Rest]
42+
export type ParseOptional<Parser extends IParser, Input extends string> = (
43+
Parse<Parser, Input> extends [infer Value extends unknown, infer InputRest extends string]
44+
? [[Value], InputRest]
4545
: [[], Input]
4646
)

src/static/parse.ts

Lines changed: 44 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,45 @@
1-
/*--------------------------------------------------------------------------
21

3-
ParseBox
4-
5-
The MIT License (MIT)
6-
7-
Copyright (c) 2024-2025 Haydn Paterson
8-
9-
Permission is hereby granted, free of charge, to any person obtaining a copy
10-
of this software and associated documentation files (the "Software"), to deal
11-
in the Software without restriction, including without limitation the rights
12-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13-
copies of the Software, and to permit persons to whom the Software is
14-
furnished to do so, subject to the following conditions:
15-
16-
The above copyright notice and this permission notice shall be included in
17-
all copies or substantial portions of the Software.
18-
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25-
THE SOFTWARE.
26-
27-
---------------------------------------------------------------------------*/
28-
29-
// deno-fmt-ignore-file
30-
31-
import { Token } from '../token/index.ts'
32-
import * as Types from './types.ts'
33-
34-
35-
// ------------------------------------------------------------------
36-
// Ident
37-
// ------------------------------------------------------------------
38-
39-
// ------------------------------------------------------------------
40-
// Number
41-
// ------------------------------------------------------------------
42-
43-
// ------------------------------------------------------------------
44-
// Optional
45-
// ------------------------------------------------------------------
46-
47-
// ------------------------------------------------------------------
48-
// String
49-
// ------------------------------------------------------------------
50-
51-
// ------------------------------------------------------------------
52-
// Tuple
53-
// ------------------------------------------------------------------
54-
55-
// ------------------------------------------------------------------
56-
// Union
57-
// ------------------------------------------------------------------
58-
59-
// ------------------------------------------------------------------
60-
// Until
61-
// ------------------------------------------------------------------
62-
63-
// ------------------------------------------------------------------
64-
// UntilNonEmpty
65-
// ------------------------------------------------------------------
2+
import type { ParseArray, Array } from './array.ts'
3+
import type { ParseConst, Const } from './const.ts'
4+
import type { ParseIdent, Ident } from './ident.ts'
5+
import type { ParseNumber, Number } from './number.ts'
6+
import type { ParseOptional, Optional } from './optional.ts'
7+
import type { ParseString, String } from './string.ts'
8+
import type { ParseTuple, Tuple } from './tuple.ts'
9+
import type { ParseUnion, Union } from './union.ts'
10+
import type { ParseUntil_1, Until_1 } from './until_1.ts'
11+
import type { ParseUntil, Until } from './until.ts'
12+
13+
import type { IParser } from './parser.ts'
14+
15+
// ------------------------------------------------------------------
16+
// ParseInput
17+
// ------------------------------------------------------------------
18+
type ParseInput<Input extends string, Parser extends IParser> = (
19+
Parser extends Array<infer Parser extends IParser> ? ParseArray<Parser, Input> :
20+
Parser extends Const<infer Const extends string> ? ParseConst<Const, Input> :
21+
Parser extends Ident ? ParseIdent<Input> :
22+
Parser extends Number ? ParseNumber<Input> :
23+
Parser extends Optional<infer Parser extends IParser> ? ParseOptional<Parser, Input> :
24+
Parser extends String ? ParseString<Input> :
25+
Parser extends Tuple<infer Parsers extends IParser[]> ? ParseTuple<Parsers, Input> :
26+
Parser extends Union<infer Parsers extends IParser[]> ? ParseUnion<Parsers, Input> :
27+
Parser extends Until<infer End extends string[]> ? ParseUntil<End, Input> :
28+
Parser extends Until_1<infer End extends string[]> ? ParseUntil_1<End, Input> :
29+
[]
30+
)
31+
// ------------------------------------------------------------------
32+
// ParseMapping
33+
// ------------------------------------------------------------------
34+
type ParseMapping<Parser extends IParser, ParseResult extends unknown = unknown> = (
35+
(Parser['mapping'] & { input: ParseResult })['output']
36+
)
37+
// ------------------------------------------------------------------
38+
// Parse
39+
// ------------------------------------------------------------------
40+
/** Parses code with the given parser */
41+
export type Parse<Parser extends IParser, Input extends string> = (
42+
ParseInput<Input, Parser> extends [infer ParseResult extends unknown, infer InputRest extends string]
43+
? [ParseMapping<Parser, ParseResult>, InputRest]
44+
: []
45+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import type { IParser, IMapping, Identity } from './parser.ts'
30-
import * as Token from '../../token/index.ts'
30+
import * as Token from '../token/index.ts'
3131

3232
// ------------------------------------------------------------------
3333
// Type
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export interface Tuple<Parsers extends IParser[] = [], Mapping extends IMapping
4141
// ------------------------------------------------------------------
4242
export type ParseTuple<Parsers extends IParser[], Input extends string, Result extends unknown[] = []> = (
4343
Parsers extends [infer Left extends IParser, ...infer Right extends IParser[]]
44-
? Parse<Left, Input> extends [infer Value extends unknown, infer Rest extends string]
45-
? ParseTuple<Right, Rest, [...Result, Value]>
44+
? Parse<Left, Input> extends [infer Element extends unknown, infer InputRest extends string]
45+
? ParseTuple<Right, InputRest, [...Result, Element]>
4646
: []
4747
: [Result, Input]
4848
)

0 commit comments

Comments
 (0)