-
Notifications
You must be signed in to change notification settings - Fork 10
Parser
hkt-toolbelt / Parser
Ƭ _$choice<PX
, STATE
, MATCH_RESULT
, NEW_STATE
>: NEW_STATE
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" ] } |
Ƭ _$letter<STATE
, SLICED_INPUT
, MATCH_RESULT
>: MATCH_RESULT
extends never
? never
: { index
: _$increment
<STATE
["index"
]> ; input
: STATE
["input"
] ; result
: MATCH_RESULT
}
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
|
Ƭ _$letters<STATE
, SLICED_INPUT
, MATCH
, NEW_INDEX
, NEW_STATE
>: NEW_STATE
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 } |
Ƭ _$letters2<S
, MATCH
>: 0
extends 1
? never
: S
extends `${infer Head}${infer Tail}` ? Head
extends __$letter
? _$letters2
<Tail
, `${MATCH}${Head}`> : MATCH
: MATCH
Name | Type |
---|---|
S |
extends string
|
MATCH |
extends string = ""
|
Ƭ _$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
>
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" ]] |
Ƭ _$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
>>> }
Name | Type |
---|---|
STATE |
extends _$state
|
P |
extends Parser
|
K |
extends Kind
|
NEW_STATE |
extends _$state = $ <P , _$cast <STATE , _$inputOf <P >>> |
Ƭ _$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
>
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
|
Ƭ _$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"
] }
Name | Type |
---|---|
STATE |
extends _$state
|
P |
extends Parser
|
RESULT |
never |
NEXT_STATE |
extends _$state = $ <P , _$cast <STATE , _$inputOf <P >>> |
Ƭ _$run<P
, X
>: $
<P
, _$cast
<{ index
: 0
; input
: X
; result
: never
}, _$inputOf
<P
>>>["result"
]
Name | Type |
---|---|
P |
extends Parser
|
X |
extends string
|
Ƭ _$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
>
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
|
Ƭ _$state: Object
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. |
Ƭ _$string<STATE
, TARGET
, SLICED_INPUT
, MATCH_RESULT
, NEW_INDEX
, NEW_STATE
>: NEW_STATE
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 } |
Ƭ __$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"