UNPKG

@thi.ng/parse

Version:

Purely functional parser combinators & AST generation for generic inputs

21 lines (20 loc) 512 B
import { xform } from "../combinators/xform.js"; import { xfJoin } from "./join.js"; const xfInt = (radix = 10) => (scope) => { scope.result = parseInt(xfJoin(scope).result, radix); return scope; }; const int = (parser) => xform(parser, xfInt(10)); const hexInt = (parser) => xform(parser, xfInt(16)); const xfFloat = (scope) => { scope.result = parseFloat(xfJoin(scope).result); return scope; }; const float = (parser) => xform(parser, xfFloat); export { float, hexInt, int, xfFloat, xfInt };