squiggle/packages/squiggle-lang/src/rescript/ReducerProject/ReducerProject_ParseIncludes.res
2022-10-05 05:17:30 +04:00

18 lines
655 B
Plaintext

@module("./ReducerProject_IncludeParser.js")
external parse__: string => array<array<string>> = "parse"
let parseIncludes = (expr: string): result<array<(string, string)>, SqError.t> =>
try {
let answer = parse__(expr)
// let logEntry = answer->Js.Array2.joinWith(",")
// `parseIncludes: ${logEntry} for expr: ${expr}`->Js.log
Belt.Array.map(answer, item => (item[0], item[1]))->Ok
} catch {
| Js.Exn.Error(obj) =>
RESyntaxError(Belt.Option.getExn(Js.Exn.message(obj)))
->SqError.fromMessageWithFrameStack(
Reducer_FrameStack.makeSingleFrameStack(Reducer_Peggy_Parse.syntaxErrorToLocation(obj)),
)
->Error
}