@optique/core 0.9.0-dev.178 → 0.9.0-dev.183
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constructs.cjs +28 -12
- package/dist/constructs.js +28 -12
- package/dist/modifiers.d.cts +2 -2
- package/dist/modifiers.d.ts +2 -2
- package/package.json +1 -1
package/dist/constructs.cjs
CHANGED
|
@@ -666,6 +666,7 @@ function merge(...args) {
|
|
|
666
666
|
usage: parsers.flatMap((p) => p.usage),
|
|
667
667
|
initialState,
|
|
668
668
|
parse(context) {
|
|
669
|
+
let zeroConsumedSuccess = null;
|
|
669
670
|
for (let i = 0; i < parsers.length; i++) {
|
|
670
671
|
const parser = parsers[i];
|
|
671
672
|
let parserState;
|
|
@@ -682,27 +683,42 @@ function merge(...args) {
|
|
|
682
683
|
});
|
|
683
684
|
if (result.success) {
|
|
684
685
|
let newState;
|
|
685
|
-
if (parser.initialState === void 0)
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
686
|
+
if (parser.initialState === void 0) {
|
|
687
|
+
const key = `__parser_${i}`;
|
|
688
|
+
if (result.consumed.length > 0 || result.next.state !== void 0) newState = {
|
|
689
|
+
...context.state,
|
|
690
|
+
[key]: result.next.state
|
|
691
|
+
};
|
|
692
|
+
else newState = { ...context.state };
|
|
693
|
+
} else newState = {
|
|
690
694
|
...context.state,
|
|
691
695
|
...result.next.state
|
|
692
696
|
};
|
|
693
|
-
|
|
697
|
+
const newContext = {
|
|
698
|
+
...context,
|
|
699
|
+
buffer: result.next.buffer,
|
|
700
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
701
|
+
state: newState
|
|
702
|
+
};
|
|
703
|
+
if (result.consumed.length > 0) return {
|
|
694
704
|
success: true,
|
|
695
|
-
next:
|
|
696
|
-
...context,
|
|
697
|
-
buffer: result.next.buffer,
|
|
698
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
699
|
-
state: newState
|
|
700
|
-
},
|
|
705
|
+
next: newContext,
|
|
701
706
|
consumed: result.consumed
|
|
702
707
|
};
|
|
708
|
+
context = newContext;
|
|
709
|
+
if (zeroConsumedSuccess === null) zeroConsumedSuccess = {
|
|
710
|
+
context: newContext,
|
|
711
|
+
consumed: []
|
|
712
|
+
};
|
|
713
|
+
else zeroConsumedSuccess.context = newContext;
|
|
703
714
|
} else if (result.consumed < 1) continue;
|
|
704
715
|
else return result;
|
|
705
716
|
}
|
|
717
|
+
if (zeroConsumedSuccess !== null) return {
|
|
718
|
+
success: true,
|
|
719
|
+
next: zeroConsumedSuccess.context,
|
|
720
|
+
consumed: zeroConsumedSuccess.consumed
|
|
721
|
+
};
|
|
706
722
|
return {
|
|
707
723
|
success: false,
|
|
708
724
|
consumed: 0,
|
package/dist/constructs.js
CHANGED
|
@@ -666,6 +666,7 @@ function merge(...args) {
|
|
|
666
666
|
usage: parsers.flatMap((p) => p.usage),
|
|
667
667
|
initialState,
|
|
668
668
|
parse(context) {
|
|
669
|
+
let zeroConsumedSuccess = null;
|
|
669
670
|
for (let i = 0; i < parsers.length; i++) {
|
|
670
671
|
const parser = parsers[i];
|
|
671
672
|
let parserState;
|
|
@@ -682,27 +683,42 @@ function merge(...args) {
|
|
|
682
683
|
});
|
|
683
684
|
if (result.success) {
|
|
684
685
|
let newState;
|
|
685
|
-
if (parser.initialState === void 0)
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
686
|
+
if (parser.initialState === void 0) {
|
|
687
|
+
const key = `__parser_${i}`;
|
|
688
|
+
if (result.consumed.length > 0 || result.next.state !== void 0) newState = {
|
|
689
|
+
...context.state,
|
|
690
|
+
[key]: result.next.state
|
|
691
|
+
};
|
|
692
|
+
else newState = { ...context.state };
|
|
693
|
+
} else newState = {
|
|
690
694
|
...context.state,
|
|
691
695
|
...result.next.state
|
|
692
696
|
};
|
|
693
|
-
|
|
697
|
+
const newContext = {
|
|
698
|
+
...context,
|
|
699
|
+
buffer: result.next.buffer,
|
|
700
|
+
optionsTerminated: result.next.optionsTerminated,
|
|
701
|
+
state: newState
|
|
702
|
+
};
|
|
703
|
+
if (result.consumed.length > 0) return {
|
|
694
704
|
success: true,
|
|
695
|
-
next:
|
|
696
|
-
...context,
|
|
697
|
-
buffer: result.next.buffer,
|
|
698
|
-
optionsTerminated: result.next.optionsTerminated,
|
|
699
|
-
state: newState
|
|
700
|
-
},
|
|
705
|
+
next: newContext,
|
|
701
706
|
consumed: result.consumed
|
|
702
707
|
};
|
|
708
|
+
context = newContext;
|
|
709
|
+
if (zeroConsumedSuccess === null) zeroConsumedSuccess = {
|
|
710
|
+
context: newContext,
|
|
711
|
+
consumed: []
|
|
712
|
+
};
|
|
713
|
+
else zeroConsumedSuccess.context = newContext;
|
|
703
714
|
} else if (result.consumed < 1) continue;
|
|
704
715
|
else return result;
|
|
705
716
|
}
|
|
717
|
+
if (zeroConsumedSuccess !== null) return {
|
|
718
|
+
success: true,
|
|
719
|
+
next: zeroConsumedSuccess.context,
|
|
720
|
+
consumed: zeroConsumedSuccess.consumed
|
|
721
|
+
};
|
|
706
722
|
return {
|
|
707
723
|
success: false,
|
|
708
724
|
consumed: 0,
|
package/dist/modifiers.d.cts
CHANGED
|
@@ -81,7 +81,7 @@ declare class WithDefaultError extends Error {
|
|
|
81
81
|
* or the default value if the wrapped parser fails to match
|
|
82
82
|
* (union type {@link TValue} | {@link TDefault}).
|
|
83
83
|
*/
|
|
84
|
-
declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
|
|
84
|
+
declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
|
|
85
85
|
/**
|
|
86
86
|
* Creates a parser that makes another parser use a default value when it fails
|
|
87
87
|
* to match or consume input. This is similar to {@link optional}, but instead
|
|
@@ -100,7 +100,7 @@ declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<T
|
|
|
100
100
|
* (union type {@link TValue} | {@link TDefault}).
|
|
101
101
|
* @since 0.5.0
|
|
102
102
|
*/
|
|
103
|
-
declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
|
|
103
|
+
declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
|
|
104
104
|
/**
|
|
105
105
|
* Creates a parser that transforms the result value of another parser using
|
|
106
106
|
* a mapping function. This enables value transformation while preserving
|
package/dist/modifiers.d.ts
CHANGED
|
@@ -81,7 +81,7 @@ declare class WithDefaultError extends Error {
|
|
|
81
81
|
* or the default value if the wrapped parser fails to match
|
|
82
82
|
* (union type {@link TValue} | {@link TDefault}).
|
|
83
83
|
*/
|
|
84
|
-
declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
|
|
84
|
+
declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault)): Parser<TValue | TDefault, [TState] | undefined>;
|
|
85
85
|
/**
|
|
86
86
|
* Creates a parser that makes another parser use a default value when it fails
|
|
87
87
|
* to match or consume input. This is similar to {@link optional}, but instead
|
|
@@ -100,7 +100,7 @@ declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<T
|
|
|
100
100
|
* (union type {@link TValue} | {@link TDefault}).
|
|
101
101
|
* @since 0.5.0
|
|
102
102
|
*/
|
|
103
|
-
declare function withDefault<TValue, TState, TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
|
|
103
|
+
declare function withDefault<TValue, TState, const TDefault = TValue>(parser: Parser<TValue, TState>, defaultValue: TDefault | (() => TDefault), options?: WithDefaultOptions): Parser<TValue | TDefault, [TState] | undefined>;
|
|
104
104
|
/**
|
|
105
105
|
* Creates a parser that transforms the result value of another parser using
|
|
106
106
|
* a mapping function. This enables value transformation while preserving
|