error value

This commit is contained in:
Umur Ozkul 2022-08-19 18:04:24 +02:00
parent e9c55fe802
commit 975b1ffda8
4 changed files with 17 additions and 6 deletions

View File

@ -1 +1,11 @@
open ForTS__Types
@genType
let toString = (e: reducerErrorValue): string => Reducer_ErrorValue.errorToString(e)
@genType
let getLocation = (e: reducerErrorValue): option<syntaxErrorLocation> =>
switch e {
| RESyntaxError(_, optionalLocation) => optionalLocation
| _ => None
}

View File

@ -1,4 +1,6 @@
@genType.opaque type result_<'a, 'e> = result<'a, 'e> @genType.opaque type result_<'a, 'e> = result<'a, 'e>
@genType.opaque type reducerErrorValue = Reducer_ErrorValue.errorValue
@genType type syntaxErrorLocation = Reducer_ErrorValue.syntaxErrorLocation
/* /*
The reason this is not ExpressionValue is that ExpressionValue is becoming a parametric type The reason this is not ExpressionValue is that ExpressionValue is becoming a parametric type
@ -13,7 +15,6 @@ type squiggleValue_Declaration = ReducerInterface_InternalExpressionValue.lambda
@genType.opaque type squiggleValue_Lambda = ReducerInterface_InternalExpressionValue.lambdaValue @genType.opaque type squiggleValue_Lambda = ReducerInterface_InternalExpressionValue.lambdaValue
@genType.opaque type squiggleValue_Record = ReducerInterface_InternalExpressionValue.map @genType.opaque type squiggleValue_Record = ReducerInterface_InternalExpressionValue.map
@genType.opaque type squiggleValue_Type = ReducerInterface_InternalExpressionValue.map @genType.opaque type squiggleValue_Type = ReducerInterface_InternalExpressionValue.map
@genType.opaque type reducerErrorValue = Reducer_ErrorValue.errorValue
@genType.opaque type reducerProject = ReducerProject_T.t @genType.opaque type reducerProject = ReducerProject_T.t

View File

@ -1,6 +1,6 @@
//FIXME: Move this under ForTS //TODO: Do not export here but in ForTS__Types
@gentype.import("peggy") @genType.as("LocationRange") @gentype.import("peggy") @genType.as("LocationRange")
type location type syntaxErrorLocation
type errorValue = type errorValue =
| REArityError(option<string>, int, int) | REArityError(option<string>, int, int)
@ -17,7 +17,7 @@ type errorValue =
| REOperationError(Operation.operationError) | REOperationError(Operation.operationError)
| RERecordPropertyNotFound(string, string) | RERecordPropertyNotFound(string, string)
| RESymbolNotFound(string) | RESymbolNotFound(string)
| RESyntaxError(string, option<location>) | RESyntaxError(string, option<syntaxErrorLocation>)
| RETodo(string) // To do | RETodo(string) // To do
| REUnitNotFound(string) | REUnitNotFound(string)

View File

@ -5,10 +5,10 @@ type node = {"type": string}
@module("./Reducer_Peggy_GeneratedParser.js") external parse__: string => node = "parse" @module("./Reducer_Peggy_GeneratedParser.js") external parse__: string => node = "parse"
type withLocation = {"location": Reducer_ErrorValue.location} type withLocation = {"location": Reducer_ErrorValue.syntaxErrorLocation}
external castWithLocation: Js.Exn.t => withLocation = "%identity" external castWithLocation: Js.Exn.t => withLocation = "%identity"
let syntaxErrorToLocation = (error: Js.Exn.t): Reducer_ErrorValue.location => let syntaxErrorToLocation = (error: Js.Exn.t): Reducer_ErrorValue.syntaxErrorLocation =>
castWithLocation(error)["location"] castWithLocation(error)["location"]
let parse = (expr: string): result<node, errorValue> => let parse = (expr: string): result<node, errorValue> =>