Skip to content

Commit 0711ede

Browse files
committed
Revision 0.11.3
1 parent 39f5c56 commit 0711ede

33 files changed

+891
-311
lines changed

src/build/common/comment.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ function FromTuple(parser: Runtime.ITuple): string {
6868
function FromUnion(parser: Runtime.IUnion): string {
6969
return parser.parsers.map((parser) => `${FromParser(parser)}`).join(' | ')
7070
}
71+
function FromUnsignedInteger(parser: Runtime.IUnsignedInteger): string {
72+
return `<UnsignedInteger>`
73+
}
74+
function FromUnsignedNumber(parser: Runtime.IUnsignedNumber): string {
75+
return `<UnsignedNumber>`
76+
}
7177
function FromUntil_1(parser: Runtime.IUntil_1): string {
7278
return `string`
7379
}
@@ -79,15 +85,17 @@ function FromParser(parser: Runtime.IParser): string {
7985
Runtime.IsArray(parser) ? FromArray(parser) :
8086
Runtime.IsBigInt(parser) ? FromBigInt(parser) :
8187
Runtime.IsConst(parser) ? FromConst(parser) :
82-
Runtime.IsInteger(parser) ? FromInteger(parser) :
8388
Runtime.IsIdent(parser) ? FromIdent(parser) :
89+
Runtime.IsInteger(parser) ? FromInteger(parser) :
8490
Runtime.IsNumber(parser) ? FromNumber(parser) :
8591
Runtime.IsOptional(parser) ? FromOptional(parser) :
8692
Runtime.IsRef(parser) ? FromRef(parser) :
8793
Runtime.IsRest(parser) ? FromRest(parser) :
8894
Runtime.IsString(parser) ? FromString(parser) :
8995
Runtime.IsTuple(parser) ? FromTuple(parser) :
9096
Runtime.IsUnion(parser) ? FromUnion(parser) :
97+
Runtime.IsUnsignedInteger(parser) ? FromUnsignedInteger(parser) :
98+
Runtime.IsUnsignedNumber(parser) ? FromUnsignedNumber(parser) :
9199
Runtime.IsUntil_1(parser) ? FromUntil_1(parser) :
92100
Runtime.IsUntil(parser) ? FromUntil(parser) :
93101
Unreachable(parser)

src/build/common/infer.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ function InferIdent(parser: Runtime.IIdent) {
4747
function InferInteger(parser: Runtime.IInteger) {
4848
return `string`
4949
}
50+
function InferNumber(parser: Runtime.INumber) {
51+
return `string`
52+
}
5053
function InferOptional(parser: Runtime.IParser) {
5154
return `([${Infer(parser)}] | [])`
5255
}
53-
function InferUnion(parsers: Runtime.IParser[]): string {
54-
return [...new Set(parsers.map((parser) => Infer(parser)))].join(' | ')
55-
}
5656
function InferString(parser: Runtime.IString) {
5757
return `string`
5858
}
@@ -62,12 +62,18 @@ function InferRef(parser: Runtime.IRef) {
6262
function InferRest(parser: Runtime.IRest) {
6363
return `string`
6464
}
65-
function InferNumber(parser: Runtime.INumber) {
66-
return `string`
67-
}
6865
function InferTuple(parsers: Runtime.IParser[]): string {
6966
return `[${parsers.map(() => 'unknown').join(', ')}]`
7067
}
68+
function InferUnion(parsers: Runtime.IParser[]): string {
69+
return [...new Set(parsers.map((parser) => Infer(parser)))].join(' | ')
70+
}
71+
function InferUnsignedInteger(parser: Runtime.IUnsignedInteger) {
72+
return `number`
73+
}
74+
function InferUnsignedNumber(parser: Runtime.IUnsignedNumber) {
75+
return `number`
76+
}
7177
function InferUntil_1(parser: Runtime.IUntil_1) {
7278
return `string`
7379
}
@@ -79,15 +85,17 @@ export function Infer(parser: Runtime.IParser): string {
7985
Runtime.IsArray(parser) ? InferArray(parser.parser) :
8086
Runtime.IsBigInt(parser) ? InferBigInt(parser) :
8187
Runtime.IsConst(parser) ? InferConst(parser) :
82-
Runtime.IsInteger(parser) ? InferInteger(parser) :
8388
Runtime.IsIdent(parser) ? InferIdent(parser) :
89+
Runtime.IsInteger(parser) ? InferInteger(parser) :
8490
Runtime.IsNumber(parser) ? InferNumber(parser) :
8591
Runtime.IsOptional(parser) ? InferOptional(parser.parser) :
8692
Runtime.IsRef(parser) ? InferRef(parser) :
8793
Runtime.IsRest(parser) ? InferRest(parser) :
8894
Runtime.IsString(parser) ? InferString(parser) :
8995
Runtime.IsTuple(parser) ? InferTuple(parser.parsers) :
9096
Runtime.IsUnion(parser) ? InferUnion(parser.parsers) :
97+
Runtime.IsUnsignedInteger(parser) ? InferUnsignedInteger(parser) :
98+
Runtime.IsUnsignedNumber(parser) ? InferUnsignedNumber(parser) :
9199
Runtime.IsUntil_1(parser) ? InferUntil_1(parser) :
92100
Runtime.IsUntil(parser) ? InferUntil(parser) :
93101
Unreachable(parser)

src/build/runtime/parse.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ function FromUnion(name: string, parsers: Runtime.IParser[]): string {
122122
return parsers.length === 0 ? '[]' : parsers.reduceRight((result, right) => `If(${FromParser(name, right)}, ([_0, input]) => [_0, input], () => ${result})`, '[]')
123123
}
124124
// ------------------------------------------------------------------
125+
// UnsignedInteger
126+
// ------------------------------------------------------------------
127+
function FromUnsignedInteger(name: string): string {
128+
return `Token.UnsignedInteger(input)`
129+
}
130+
// ------------------------------------------------------------------
131+
// UnsignedNumber
132+
// ------------------------------------------------------------------
133+
function FromUnsignedNumber(name: string): string {
134+
return `Token.UnsignedNumber(input)`
135+
}
136+
// ------------------------------------------------------------------
125137
// Until_1
126138
// ------------------------------------------------------------------
127139
function FromUntil_1(name: string, end: string[]): string {
@@ -152,6 +164,8 @@ function FromParser(name: string, parser: Runtime.IParser): string {
152164
Runtime.IsString(parser) ? FromString(name, parser.quotes) :
153165
Runtime.IsTuple(parser) ? FromTuple(name, parser.parsers) :
154166
Runtime.IsUnion(parser) ? FromUnion(name, parser.parsers) :
167+
Runtime.IsUnsignedInteger(parser) ? FromUnsignedInteger(name) :
168+
Runtime.IsUnsignedNumber(parser) ? FromUnsignedNumber(name) :
155169
Runtime.IsUntil_1(parser) ? FromUntil_1(name, parser.end) :
156170
Runtime.IsUntil(parser) ? FromUntil(name, parser.end) :
157171
Unreachable(parser)

src/build/static/parse.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ function FromUnion(name: string, parsers: Runtime.IParser[]): string {
121121
return parsers.length === 0 ? '[]' : `(${parsers.reduceRight((result, right) => `${FromParser(name, right)} extends [infer _0, infer Input extends string] ? [_0, Input] : ${result}`, '[]')})`
122122
}
123123
// ------------------------------------------------------------------
124+
// UnsignedInteger
125+
// ------------------------------------------------------------------
126+
function FromUnsignedInteger(name: string): string {
127+
return `Token.TUnsignedInteger<Input>`
128+
}
129+
// ------------------------------------------------------------------
130+
// UnsignedNumber
131+
// ------------------------------------------------------------------
132+
function FromUnsignedNumber(name: string): string {
133+
return `Token.TUnsignedNumber<Input>`
134+
}
135+
// ------------------------------------------------------------------
124136
// Until_1
125137
// ------------------------------------------------------------------
126138
function FromUntil_1(name: string, end: string[]): string {
@@ -142,15 +154,17 @@ function FromParser(name: string, parser: Runtime.IParser): string {
142154
Runtime.IsArray(parser) ? FromArray(name, parser.parser) :
143155
Runtime.IsBigInt(parser) ? FromBigInt(name) :
144156
Runtime.IsConst(parser) ? FromConst(name, parser.const) :
145-
Runtime.IsInteger(parser) ? FromInteger(name) :
146157
Runtime.IsIdent(parser) ? FromIdent(name) :
158+
Runtime.IsInteger(parser) ? FromInteger(name) :
147159
Runtime.IsNumber(parser) ? FromNumber(name) :
148160
Runtime.IsOptional(parser) ? FromOptional(name, parser) :
149161
Runtime.IsRef(parser) ? FromRef(name, parser.ref) :
150162
Runtime.IsRest(parser) ? FromRest(name) :
151163
Runtime.IsString(parser) ? FromString(name, parser.quotes) :
152164
Runtime.IsTuple(parser) ? FromTuple(name, parser.parsers) :
153165
Runtime.IsUnion(parser) ? FromUnion(name, parser.parsers) :
166+
Runtime.IsUnsignedInteger(parser) ? FromUnsignedInteger(name) :
167+
Runtime.IsUnsignedNumber(parser) ? FromUnsignedNumber(name) :
154168
Runtime.IsUntil_1(parser) ? FromUntil_1(name, parser.end) :
155169
Runtime.IsUntil(parser) ? FromUntil(name, parser.end) :
156170
Unreachable(parser)

src/runtime/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ export { type IRest, Rest, IsRest, } from './rest.ts'
4343
export { type IString, IsString, String } from './string.ts'
4444
export { type ITuple, IsTuple, Tuple } from './tuple.ts'
4545
export { type IUnion, IsUnion, Union } from './union.ts'
46+
export { type IUnsignedInteger, IsUnsignedInteger, UnsignedInteger } from './unsigned_integer.ts'
47+
export { type IUnsignedNumber, IsUnsignedNumber, UnsignedNumber } from './unsigned_number.ts'
4648
export { type IUntil_1, IsUntil_1, Until_1 } from './until_1.ts'
4749
export { type IUntil, IsUntil, Until } from './until.ts'

src/runtime/parse.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ import { ParseRest, IsRest } from './rest.ts'
4646
import { ParseString, IsString } from './string.ts'
4747
import { ParseTuple, IsTuple } from './tuple.ts'
4848
import { ParseUnion, IsUnion } from './union.ts'
49+
import { ParseUnsignedInteger, IsUnsignedInteger } from './unsigned_integer.ts'
50+
import { ParseUnsignedNumber, IsUnsignedNumber} from './unsigned_number.ts'
4951
import { ParseUntil_1, IsUntil_1 } from './until_1.ts'
5052
import { ParseUntil, IsUntil } from './until.ts'
5153

@@ -66,6 +68,8 @@ export function ParseParser<Parser extends IParser>(context: IProperties, parser
6668
IsString(parser) ? ParseString(parser.quotes, input) :
6769
IsTuple(parser) ? ParseTuple(context, parser.parsers, input) :
6870
IsUnion(parser) ? ParseUnion(context, parser.parsers, input) :
71+
IsUnsignedInteger(parser) ? ParseUnsignedInteger(input) :
72+
IsUnsignedNumber(parser) ? ParseUnsignedNumber(input) :
6973
IsUntil(parser) ? ParseUntil(parser.end, input) :
7074
IsUntil_1(parser) ? ParseUntil_1(parser.end, input) :
7175
[]

src/runtime/unsigned_integer.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*--------------------------------------------------------------------------
2+
3+
ParseBox
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2024-2026 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 * as Token from '../token/index.ts'
32+
33+
import { Arguments } from '../system/arguments/index.ts'
34+
import { Guard } from '../guard/index.ts'
35+
import { type IParser, type IMapping, Identity } from './parser.ts'
36+
37+
// ------------------------------------------------------------------
38+
// Type
39+
// ------------------------------------------------------------------
40+
export interface IUnsignedInteger<Output extends unknown = unknown> extends IParser<Output> {
41+
type: 'UnsignedInteger'
42+
}
43+
// ------------------------------------------------------------------
44+
// Factory
45+
// ------------------------------------------------------------------
46+
export function UnsignedInteger<Mapping extends IMapping<string>>(mapping: Mapping): IUnsignedInteger<ReturnType<Mapping>>
47+
export function UnsignedInteger(): IUnsignedInteger<string>
48+
export function UnsignedInteger(...args: unknown[]): never {
49+
const [mapping] = Arguments.Match<[IParser, IMapping]>(args, {
50+
1: (mapping) => [mapping],
51+
0: () => [Identity]
52+
})
53+
return { type: 'UnsignedInteger', mapping } as never
54+
}
55+
// ------------------------------------------------------------------
56+
// Guard
57+
// ------------------------------------------------------------------
58+
export function IsUnsignedInteger(value: unknown): value is IUnsignedInteger {
59+
return Guard.IsObject(value)
60+
&& Guard.HasPropertyKey(value, 'type')
61+
&& Guard.IsEqual(value.type, 'UnsignedInteger')
62+
}
63+
// ------------------------------------------------------------------
64+
// Parse
65+
// ------------------------------------------------------------------
66+
export function ParseUnsignedInteger(input: string): [] | [string, string] {
67+
return Token.UnsignedInteger(input)
68+
}

src/runtime/unsigned_number.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*--------------------------------------------------------------------------
2+
3+
ParseBox
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2024-2026 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 * as Token from '../token/index.ts'
32+
33+
import { Arguments } from '../system/arguments/index.ts'
34+
import { Guard } from '../guard/index.ts'
35+
import { type IParser, type IMapping, Identity } from './parser.ts'
36+
37+
// ------------------------------------------------------------------
38+
// Type
39+
// ------------------------------------------------------------------
40+
export interface IUnsignedNumber<Output extends unknown = unknown> extends IParser<Output> {
41+
type: 'UnsignedNumber'
42+
}
43+
// ------------------------------------------------------------------
44+
// Factory
45+
// ------------------------------------------------------------------
46+
export function UnsignedNumber<Mapping extends IMapping<string>>(mapping: Mapping): IUnsignedNumber<ReturnType<Mapping>>
47+
export function UnsignedNumber(): IUnsignedNumber<string>
48+
export function UnsignedNumber(...args: unknown[]): never {
49+
const [mapping] = Arguments.Match<[IParser, IMapping]>(args, {
50+
1: (mapping) => [mapping],
51+
0: () => [Identity]
52+
})
53+
return { type: 'UnsignedNumber', mapping } as never
54+
}
55+
// ------------------------------------------------------------------
56+
// Guard
57+
// ------------------------------------------------------------------
58+
export function IsUnsignedNumber(value: unknown): value is IUnsignedNumber {
59+
return Guard.IsObject(value)
60+
&& Guard.HasPropertyKey(value, 'type')
61+
&& Guard.IsEqual(value.type, 'UnsignedNumber')
62+
}
63+
// ------------------------------------------------------------------
64+
// Parse
65+
// ------------------------------------------------------------------
66+
export function ParseUnsignedNumber(input: string): [] | [string, string] {
67+
return Token.UnsignedNumber(input)
68+
}

src/static/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,7 @@ export type { Rest } from './rest.ts'
3939
export type { String } from './string.ts'
4040
export type { Tuple } from './tuple.ts'
4141
export type { Union } from './union.ts'
42+
export type { UnsignedInteger } from './unsigned_integer.ts'
43+
export type { UnsignedNumber } from './unsigned_number.ts'
4244
export type { Until_1 } from './until_1.ts'
4345
export type { Until } from './until.ts'

src/static/parse.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import type { ParseRest, Rest } from './rest.ts'
3939
import type { ParseString, String } from './string.ts'
4040
import type { ParseTuple, Tuple } from './tuple.ts'
4141
import type { ParseUnion, Union } from './union.ts'
42+
import type { ParseUnsignedInteger, UnsignedInteger } from './unsigned_integer.ts'
43+
import type { ParseUnsignedNumber, UnsignedNumber } from './unsigned_number.ts'
4244
import type { ParseUntil_1, Until_1 } from './until_1.ts'
4345
import type { ParseUntil, Until } from './until.ts'
4446

@@ -58,10 +60,12 @@ type ParseInput<Input extends string, Parser extends IParser> = (
5860
Parser extends Rest ? ParseRest<Input> :
5961
Parser extends String<infer Quotes extends string[]> ? ParseString<Quotes, Input> :
6062
Parser extends Tuple<infer Parsers extends IParser[]> ? ParseTuple<Parsers, Input> :
61-
Parser extends Union<infer Parsers extends IParser[]> ? ParseUnion<Parsers, Input> :
63+
Parser extends Union<infer Parsers extends IParser[]> ? ParseUnion<Parsers, Input> :
64+
Parser extends UnsignedInteger ? ParseUnsignedInteger<Input> :
65+
Parser extends UnsignedNumber ? ParseUnsignedNumber<Input> :
6266
Parser extends Until<infer End extends string[]> ? ParseUntil<End, Input> :
63-
Parser extends Until_1<infer End extends string[]> ? ParseUntil_1<End, Input>
64-
: []
67+
Parser extends Until_1<infer End extends string[]> ? ParseUntil_1<End, Input> :
68+
[]
6569
)
6670
// ------------------------------------------------------------------
6771
// ParseMapping

0 commit comments

Comments
 (0)