Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save melbourne2991/07224c22ccf071a1df2e920970cfce95 to your computer and use it in GitHub Desktop.
Save melbourne2991/07224c22ccf071a1df2e920970cfce95 to your computer and use it in GitHub Desktop.
map union record types from js
type ofCst;
type unknownCstElement;
type cstChildrenDict = Js.Dict.t(list(unknownCstElement));
type cstNode = {
name: string,
children: cstChildrenDict,
};
type token;
type cstElement =
| Token(token)
| Node(cstNode);
type lexErrors;
type parseErrors;
type parseResult = {
cst: cstNode,
lexErrors,
parseErrors,
};
let mapUnknownCst = (unknownCstElement: unknownCstElement) =>
if (Js.typeof(Obj.magic(unknownCstElement)##tokenType) != "undefined") {
Token(Obj.magic(unknownCstElement): token);
} else {
Node(Obj.magic(unknownCstElement): cstNode);
};
[@bs.module "./parser/index.js"]
external parse: string => parseResult = "parse";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment