Skip to content

Commit 9599c21

Browse files
committed
Revision 0.9.6
1 parent 31c6c9b commit 9599c21

File tree

8 files changed

+369
-272
lines changed

8 files changed

+369
-272
lines changed

example/typebox/compiled/module.ts

Lines changed: 315 additions & 262 deletions
Large diffs are not rendered by default.

src/compile/common/comment.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ THE SOFTWARE.
3030
// deno-lint-ignore-file no-unused-vars
3131

3232
import { Runtime } from '../../runtime/index.ts'
33+
import { Unreachable } from './unreachable.ts'
3334
import { Escape } from './escape.ts'
3435

3536
function FromContext(parser: Runtime.IContext): string {
@@ -78,7 +79,7 @@ function FromParser(parser: Runtime.IParser): string {
7879
Runtime.IsRef(parser) ? FromRef(parser) :
7980
Runtime.IsIdent(parser) ? FromIdent(parser) :
8081
Runtime.IsNumber(parser) ? FromNumber(parser) :
81-
'<unreachable>'
82+
Unreachable(parser)
8283
)
8384
}
8485
export function CompileComment(name: string, parser: Runtime.IParser): string {

src/compile/common/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29-
export * from "./comment.ts"
30-
export * from "./escape.ts"
31-
export * from "./infer.ts"
29+
export * from './comment.ts'
30+
export * from './escape.ts'
31+
export * from './infer.ts'
32+
export * from './unreachable.ts'

src/compile/common/infer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ THE SOFTWARE.
3030
// deno-lint-ignore-file no-unused-vars
3131

3232
import { Runtime } from '../../runtime/index.ts'
33+
import { Unreachable } from './unreachable.ts'
3334

3435
function InferUnion(parsers: Runtime.IParser[]): string {
3536
return [...new Set(parsers.map((parser) => Infer(parser)))].join(' | ')
@@ -65,6 +66,6 @@ export function Infer(parser: Runtime.IParser): string {
6566
Runtime.IsString(parser) ? `string` :
6667
Runtime.IsIdent(parser) ? `string` :
6768
Runtime.IsNumber(parser) ? `string` :
68-
'<unreachable>'
69+
Unreachable(parser)
6970
)
7071
}

src/compile/common/unreachable.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/parsebox
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2024-2025 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
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 { Runtime } from '../../runtime/index.ts'
32+
33+
export class UnreachableError extends Error {
34+
constructor(public parser: Runtime.IParser) {
35+
super('unreachable')
36+
}
37+
}
38+
39+
export function Unreachable(parser: Runtime.IParser): never {
40+
throw new UnreachableError(parser)
41+
}

src/compile/func/func.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ THE SOFTWARE.
3030
// deno-lint-ignore-file no-unused-vars
3131

3232
import { Runtime } from '../../runtime/index.ts'
33-
import { Infer, Escape } from '../common/index.ts'
33+
import { Infer, Escape, Unreachable } from '../common/index.ts'
3434
import { Options } from '../options.ts'
3535

3636
// ------------------------------------------------------------------
@@ -130,7 +130,7 @@ function FromParser(options: Options, name: string, parser: Runtime.IParser): st
130130
Runtime.IsRef(parser) ? FromRef(options, name, parser.ref) :
131131
Runtime.IsIdent(parser) ? FromIdent(options, name) :
132132
Runtime.IsNumber(parser) ? FromNumber(options, name) :
133-
'<unreachable>'
133+
Unreachable(parser)
134134
)
135135
}
136136
// ------------------------------------------------------------------

src/compile/type/type.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ THE SOFTWARE.
3030
// deno-lint-ignore-file no-unused-vars
3131

3232
import { Runtime } from '../../runtime/index.ts'
33-
import { Infer, Escape } from '../common/index.ts'
33+
import { Infer, Escape, Unreachable } from '../common/index.ts'
3434
import { Options } from '../options.ts'
3535
import { Name } from './name.ts'
3636

@@ -132,7 +132,7 @@ function FromParser(options: Options, name: string, parser: Runtime.IParser): st
132132
Runtime.IsRef(parser) ? FromRef(options, name, parser.ref) :
133133
Runtime.IsIdent(parser) ? FromIdent(options, name) :
134134
Runtime.IsNumber(parser) ? FromNumber(options, name) :
135-
'<unreachable>'
135+
Unreachable(parser)
136136
)
137137
}
138138
// ------------------------------------------------------------------

tasks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Task.run('build', () => Task.build('src', {
3434
packageJson: {
3535
name: '@sinclair/parsebox',
3636
description: 'Parser Combinators in the TypeScript Type System',
37-
version: '0.9.5',
37+
version: '0.9.6',
3838
keywords: ['typescript', 'parser', 'combinator'],
3939
license: 'MIT',
4040
author: 'sinclairzx81',

0 commit comments

Comments
 (0)