Skip to content

Commit c360d84

Browse files
committed
updates
1 parent c2e4b39 commit c360d84

File tree

6 files changed

+105
-9
lines changed

6 files changed

+105
-9
lines changed

example/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import { Token } from '@sinclair/parsebox'
44

5-
65
const R = Token.String(`'hello'`)
76
console.log(R)
87

src/token/bigint.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*--------------------------------------------------------------------------
2+
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 { type TTrim, Trim } from './internal/trim.ts'
32+
import { type TTake, Take } from './internal/take.ts'
33+
34+
import { type TDigit, Digit } from './internal/char.ts'
35+
import { type TZero, Zero } from './internal/char.ts'
36+
37+
/** Matches if next is a BigInt literal with trailing `n` */
38+
export type TBigInt<Input extends string> = (
39+
TTake<TTrim<Input>, []>
40+
)
41+
/** Matches if next is a BigInt literal with trailing `n` */
42+
export function BigInt<Input extends string>
43+
(input: Input): TBigInt<Input> {
44+
return Take(Trim(input), []) as never
45+
}
46+

src/token/ident.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ import { type TUnreachable, Unreachable } from './internal/unreachable.ts'
3232
import { type TTrim, Trim } from './internal/trim.ts'
3333
import { type TTake, Take, IsTakeTrue } from './internal/take.ts'
3434

35-
import * as Char from './internal/char.ts'
35+
import { type TAlpha, Alpha } from './internal/char.ts'
36+
import { type TDigit, Digit } from './internal/char.ts'
37+
import { type TUnderScore, UnderScore } from './internal/char.ts'
38+
import { type TDollarSign, DollarSign } from './internal/char.ts'
3639

3740
// ------------------------------------------------------------------
3841
// First
3942
// ------------------------------------------------------------------
40-
type TFirst = [...Char.TAlpha, Char.TUnderscore, Char.TDollarSign]
41-
const First = [...Char.Alpha, Char.Underscore, Char.DollarSign]
43+
type TFirst = [...TAlpha, TUnderScore, TDollarSign]
44+
const First = [...Alpha, UnderScore, DollarSign]
4245

4346
type TTakeFirst<Input extends string> = (
4447
TTake<Input, TFirst> extends [infer First extends string, infer Right extends string]
@@ -56,8 +59,8 @@ function TakeFirst<Input extends string>(input: Input): TTakeFirst<Input> {
5659
// ------------------------------------------------------------------
5760
// Remaining
5861
// ------------------------------------------------------------------
59-
type TRemaining = [...TFirst, ...Char.TDigit]
60-
const Remaining = [...First, ...Char.Digit]
62+
type TRemaining = [...TFirst, ...TDigit]
63+
const Remaining = [...First, ...Digit]
6164

6265
type TTakeRemaining<Input extends string, Result extends string = ''> = (
6366
TTake<Input, TRemaining> extends [infer Next extends string, infer Right extends string]

src/token/integer.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*--------------------------------------------------------------------------
2+
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 { type TTrim, Trim } from './internal/trim.ts'
32+
import { type TTake, Take } from './internal/take.ts'
33+
34+
import { type TDigit, Digit } from './internal/char.ts'
35+
import { type TZero, Zero } from './internal/char.ts'
36+
37+
/** Matches if next is a BigInt literal with trailing `n` */
38+
export type TInteger<Input extends string> = (
39+
TTake<TTrim<Input>, []>
40+
)
41+
/** Matches if next is a BigInt literal with trailing `n` */
42+
export function Integer<Input extends string>
43+
(input: Input): TInteger<Input> {
44+
return Take(Trim(input), []) as never
45+
}
46+

src/token/internal/char.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const Digit = [Zero, ...NonZero] as const
5858
// ------------------------------------------------------------------
5959
export const WhiteSpace = ' '
6060
export const NewLine = '\n'
61-
export const Underscore = '_'
61+
export const UnderScore = '_'
6262
export const Dot = '.'
6363
export const DollarSign = '$'
6464
export const SingleQuote = "'"
@@ -67,7 +67,7 @@ export const BackTick = '`'
6767

6868
export type TWhiteSpace = typeof WhiteSpace
6969
export type TNewLine = typeof NewLine
70-
export type TUnderscore = typeof Underscore
70+
export type TUnderScore = typeof UnderScore
7171
export type TDot = typeof Dot
7272
export type TDollarSign = typeof DollarSign
7373
export type TSingleQuote = typeof SingleQuote

src/token/token.ts

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

29+
export * from './bigint.ts'
2930
export * from './const.ts'
3031
export * from './ident.ts'
31-
export * from './string.ts'
32+
export * from './integer.ts'
3233
export * from './span.ts'
34+
export * from './string.ts'
3335
export * from './until.ts'

0 commit comments

Comments
 (0)