MCPcopy
hub / github.com/Effect-TS/effect / go

Function go

packages/effect/src/ParseResult.ts:778–1486  ·  view source on GitHub ↗
(ast: AST.AST, isDecoding: boolean)

Source from the content-addressed store, hash-verified

776 Option.getOrUndefined(AST.getBatchingAnnotation(ast))
777
778const go = (ast: AST.AST, isDecoding: boolean): Parser => {
779 switch (ast._tag) {
780 case "Refinement": {
781 if (isDecoding) {
782 const from = goMemo(ast.from, true)
783 return (i, options) => {
784 options = options ?? AST.defaultParseOption
785 const allErrors = options?.errors === "all"
786 const result = flatMap(
787 orElse(from(i, options), (ef) => {
788 const issue = new Refinement(ast, i, "From", ef)
789 if (allErrors && AST.hasStableFilter(ast) && isComposite(ef)) {
790 return Option.match(
791 ast.filter(i, options, ast),
792 {
793 onNone: () => Either.left<ParseIssue>(issue),
794 onSome: (ep) => Either.left(new Composite(ast, i, [issue, new Refinement(ast, i, "Predicate", ep)]))
795 }
796 )
797 }
798 return Either.left(issue)
799 }),
800 (a) =>
801 Option.match(
802 ast.filter(a, options, ast),
803 {
804 onNone: () => Either.right(a),
805 onSome: (ep) => Either.left(new Refinement(ast, i, "Predicate", ep))
806 }
807 )
808 )
809 return handleForbidden(result, ast, i, options)
810 }
811 } else {
812 const from = goMemo(AST.typeAST(ast), true)
813 const to = goMemo(dropRightRefinement(ast.from), false)
814 return (i, options) => handleForbidden(flatMap(from(i, options), (a) => to(a, options)), ast, i, options)
815 }
816 }
817 case "Transformation": {
818 const transform = getFinalTransformation(ast.transformation, isDecoding)
819 const from = isDecoding ? goMemo(ast.from, true) : goMemo(ast.to, false)
820 const to = isDecoding ? goMemo(ast.to, true) : goMemo(ast.from, false)
821 return (i, options) =>
822 handleForbidden(
823 flatMap(
824 mapError(
825 from(i, options),
826 (e) => new Transformation(ast, i, isDecoding ? "Encoded" : "Type", e)
827 ),
828 (a) =>
829 flatMap(
830 mapError(
831 transform(a, options ?? AST.defaultParseOption, ast, i),
832 (e) => new Transformation(ast, i, "Transformation", e)
833 ),
834 (i2) =>
835 mapError(

Callers 1

goMemoFunction · 0.70

Calls 15

goMemoFunction · 0.85
orElseFunction · 0.85
isCompositeFunction · 0.85
handleForbiddenFunction · 0.85
dropRightRefinementFunction · 0.85
getFinalTransformationFunction · 0.85
fromRefinementFunction · 0.85
getConcurrencyFunction · 0.85
getBatchingFunction · 0.85
parserFunction · 0.85
sortByIndexFunction · 0.85
computeResultFunction · 0.85

Tested by

no test coverage detected