Skip to content
Michael Poteat edited this page Feb 27, 2023 · 3 revisions

hkt-toolbelt / Parser

Namespace: Parser

Interfaces

Type Aliases

_$choice

Ƭ _$choice<PX, STATE, MATCH_RESULT, NEW_STATE>: NEW_STATE

Type parameters

Name Type
PX extends Parser[]
STATE extends _$state
MATCH_RESULT extends _$state = _$cast<$<$<Pipe, [$<Map, $<Apply, STATE>>, $<Find, $<NotEquals, never>>]>, PX>, _$state>
NEW_STATE extends _$state = MATCH_RESULT extends never ? never : { index: MATCH_RESULT["index"] ; input: STATE["input"] ; result: MATCH_RESULT["result"] }

Defined in

parser/choice.ts:3


_$letter

Ƭ _$letter<STATE, SLICED_INPUT, MATCH_RESULT>: MATCH_RESULT extends never ? never : { index: _$increment<STATE["index"]> ; input: STATE["input"] ; result: MATCH_RESULT }

Type parameters

Name Type
STATE extends _$state
SLICED_INPUT extends string = _$slice<STATE["input"], STATE["index"]>
MATCH_RESULT extends string = SLICED_INPUT extends `${infer L}${string}` ? L extends __$letter ? L : never : never

Defined in

parser/letter.ts:57


_$letters

Ƭ _$letters<STATE, SLICED_INPUT, MATCH, NEW_INDEX, NEW_STATE>: NEW_STATE

Type parameters

Name Type
STATE extends _$state
SLICED_INPUT extends string = _$slice<STATE["input"], STATE["index"]>
MATCH extends string = _$letters2<SLICED_INPUT>
NEW_INDEX extends Number = _$add<STATE["index"], _$length<MATCH>>
NEW_STATE extends _$state = MATCH extends "" ? never : { index: NEW_INDEX ; input: STATE["input"] ; result: MATCH }

Defined in

parser/letters.ts:14


_$letters2

Ƭ _$letters2<S, MATCH>: 0 extends 1 ? never : S extends `${infer Head}${infer Tail}` ? Head extends __$letter ? _$letters2<Tail, `${MATCH}${Head}`> : MATCH : MATCH

Type parameters

Name Type
S extends string
MATCH extends string = ""

Defined in

parser/letters.ts:3


_$many1

Ƭ _$many1<STATE, P, RESULTS, NEXT_STATE, NEXT_RESULTS>: 0 extends 1 ? never : _$equals<NEXT_STATE, never> extends true ? RESULTS extends [] ? never : { index: STATE["index"] ; input: STATE["input"] ; result: RESULTS } : _$many1<NEXT_STATE, P, NEXT_RESULTS>

Type parameters

Name Type
STATE extends _$state
P extends Parser
RESULTS extends unknown[] = []
NEXT_STATE extends _$state = $<P, _$cast<STATE, _$inputOf<P>>>
NEXT_RESULTS extends unknown[] = [...RESULTS, NEXT_STATE["result"]]

Defined in

parser/many1.ts:3


_$map

Ƭ _$map<STATE, P, K, NEW_STATE>: NEW_STATE extends never ? never : { index: NEW_STATE["index"] ; input: NEW_STATE["input"] ; result: $<K, _$cast<NEW_STATE["result"], _$inputOf<K>>> }

Type parameters

Name Type
STATE extends _$state
P extends Parser
K extends Kind
NEW_STATE extends _$state = $<P, _$cast<STATE, _$inputOf<P>>>

Defined in

parser/map.ts:3


_$objectSequence

Ƭ _$objectSequence<STATE, PX, RESULTS, ACTIVE_PX, NEXT_PX, NEXT_STATE, NEXT_RESULTS, IS_DONE>: IS_DONE extends true ? NEXT_STATE extends never ? never : { index: NEXT_STATE["index"] ; input: STATE["input"] ; result: NEXT_RESULTS } : _$objectSequence<NEXT_STATE, NEXT_PX, NEXT_RESULTS>

Type parameters

Name Type
STATE extends _$state
PX extends ([string, Parser] | Parser)[]
RESULTS extends Record<string, unknown> = {}
ACTIVE_PX extends [string, Parser] | Parser = _$first<PX>
NEXT_PX extends ([string, Parser] | Parser)[] = _$cast<_$shift<PX>, ([string, Parser] | Parser)[]>
NEXT_STATE extends _$state = ACTIVE_PX extends [string, Parser] ? $<ACTIVE_PX[1], _$cast<STATE, _$inputOf<ACTIVE_PX[1]>>> : ACTIVE_PX extends Parser ? $<ACTIVE_PX, _$cast<STATE, _$inputOf<ACTIVE_PX>>> : never
NEXT_RESULTS extends Record<string, unknown> = ACTIVE_PX extends [string, Parser] ? _$merge<RESULTS, { [K in ACTIVE_PX[0]]: NEXT_STATE["result"] }> : RESULTS
IS_DONE extends boolean = NEXT_PX extends [] ? true : NEXT_STATE extends never ? false : false

Defined in

parser/object-sequence.ts:3


_$optional

Ƭ _$optional<STATE, P, RESULT, NEXT_STATE>: _$equals<NEXT_STATE, never> extends true ? { index: STATE["index"] ; input: STATE["input"] ; result: RESULT } : { index: NEXT_STATE["index"] ; input: STATE["input"] ; result: NEXT_STATE["result"] }

Type parameters

Name Type
STATE extends _$state
P extends Parser
RESULT never
NEXT_STATE extends _$state = $<P, _$cast<STATE, _$inputOf<P>>>

Defined in

parser/optional.ts:3


_$run

Ƭ _$run<P, X>: $<P, _$cast<{ index: 0 ; input: X ; result: never }, _$inputOf<P>>>["result"]

Type parameters

Name Type
P extends Parser
X extends string

Defined in

parser/run.ts:3


_$sequence

Ƭ _$sequence<STATE, PX, RESULTS, ACTIVE_PX, NEXT_PX, NEXT_STATE, NEXT_RESULTS, IS_DONE>: IS_DONE extends true ? NEXT_STATE extends never ? never : { index: NEXT_STATE["index"] ; input: STATE["input"] ; result: NEXT_RESULTS } : _$sequence<NEXT_STATE, NEXT_PX, NEXT_RESULTS>

Type parameters

Name Type
STATE extends _$state
PX extends Parser[]
RESULTS extends unknown[] = []
ACTIVE_PX extends Parser = _$first<PX>
NEXT_PX extends Parser[] = _$cast<_$shift<PX>, Parser[]>
NEXT_STATE extends _$state = $<ACTIVE_PX, _$cast<STATE, _$inputOf<ACTIVE_PX>>>
NEXT_RESULTS extends unknown[] = [...RESULTS, NEXT_STATE["result"]]
IS_DONE extends boolean = NEXT_PX extends [] ? true : NEXT_STATE extends never ? false : false

Defined in

parser/sequence.ts:3


_$state

Ƭ _$state: Object

Type declaration

Name Type Description
index Number The current index in the input string to begin matching.
input string The string to match on.
result unknown The result of the match.

Defined in

parser/state.ts:3


_$string

Ƭ _$string<STATE, TARGET, SLICED_INPUT, MATCH_RESULT, NEW_INDEX, NEW_STATE>: NEW_STATE

Type parameters

Name Type
STATE extends _$state
TARGET extends string
SLICED_INPUT extends string = _$slice<STATE["input"], STATE["index"]>
MATCH_RESULT extends string = SLICED_INPUT extends `${TARGET}${string}` ? TARGET : never
NEW_INDEX extends number = _$add<STATE["index"], _$length<MATCH_RESULT>>
NEW_STATE extends _$state = MATCH_RESULT extends never ? never : { index: NEW_INDEX ; input: STATE["input"] ; result: MATCH_RESULT }

Defined in

parser/string.ts:3


__$letter

Ƭ __$letter: "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"

Defined in

parser/letter.ts:3

Clone this wiki locally