typescript-parsec
Advanced tools
Comparing version 0.3.3 to 0.3.4
export * from './Lexer'; | ||
export * from './Parsers/ParserInterface'; | ||
export * from './Parsers/TokenParser'; | ||
export * from './Parsers/MonadicSequencialParser'; | ||
export * from './Parsers/SequencialParser'; | ||
@@ -13,3 +14,2 @@ export * from './Parsers/AlternativeParser'; | ||
export * from './Parsers/Rule'; | ||
export * from './Parsers/LazyParser'; | ||
export * from './Parsers/ParserModule'; | ||
export * from './ParserModule'; |
@@ -18,2 +18,3 @@ "use strict"; | ||
__exportStar(require("./Parsers/TokenParser"), exports); | ||
__exportStar(require("./Parsers/MonadicSequencialParser"), exports); | ||
__exportStar(require("./Parsers/SequencialParser"), exports); | ||
@@ -28,4 +29,3 @@ __exportStar(require("./Parsers/AlternativeParser"), exports); | ||
__exportStar(require("./Parsers/Rule"), exports); | ||
__exportStar(require("./Parsers/LazyParser"), exports); | ||
__exportStar(require("./Parsers/ParserModule"), exports); | ||
__exportStar(require("./ParserModule"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -23,15 +23,20 @@ import { Token, TokenPosition } from './../Lexer'; | ||
*/ | ||
export declare type ParserOutput<TKind, TResult> = { | ||
export interface SucceededParserOutput<TKind, TResult> { | ||
candidates: ParseResult<TKind, TResult>[]; | ||
successful: true; | ||
error: ParseError | undefined; | ||
} | { | ||
} | ||
export interface FailedParserOutput { | ||
successful: false; | ||
error: ParseError; | ||
}; | ||
} | ||
export declare type ParserOutput<TKind, TResult> = SucceededParserOutput<TKind, TResult> | FailedParserOutput; | ||
export interface Parser<TKind, TResult> { | ||
parse(token: Token<TKind> | undefined): ParserOutput<TKind, TResult>; | ||
} | ||
export interface FailedParser { | ||
parse(token: Token<unknown> | undefined): FailedParserOutput; | ||
} | ||
export declare function betterError(e1: ParseError | undefined, e2: ParseError | undefined): ParseError | undefined; | ||
export declare function resultOrError<TKind, TResult>(result: ParseResult<TKind, TResult>[], error: ParseError | undefined, successful: boolean): ParserOutput<TKind, TResult>; | ||
export declare function unableToConsumeToken<TKind>(token: Token<TKind> | undefined): ParseError; |
@@ -8,3 +8,4 @@ import { Parser } from './ParserInterface'; | ||
export declare function list_sc<TKind, TResult, TSeparator>(p: Parser<TKind, TResult>, s: Parser<TKind, TSeparator>): Parser<TKind, TResult[]>; | ||
export declare function list_n<TKind, TResult, TSeparator>(p: Parser<TKind, TResult>, s: Parser<TKind, TSeparator>, count: number): Parser<TKind, TResult[]>; | ||
export declare function lrec<TKind, TResult, TFirst extends TResult, TSecond>(p: Parser<TKind, TFirst>, q: Parser<TKind, TSecond>, callback: (a: TResult, b: TSecond) => TResult): Parser<TKind, TResult>; | ||
export declare function lrec_sc<TKind, TResult, TFirst extends TResult, TSecond>(p: Parser<TKind, TFirst>, q: Parser<TKind, TSecond>, callback: (a: TResult, b: TSecond) => TResult): Parser<TKind, TResult>; |
"use strict"; | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
var __spreadArrays = (this && this.__spreadArrays) || function () { | ||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; | ||
for (var r = Array(s), k = 0, i = 0; i < il; i++) | ||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) | ||
r[k] = a[j]; | ||
return r; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.lrec_sc = exports.lrec = exports.list_sc = exports.list = exports.rep_n = exports.repr = exports.rep_sc = exports.rep = void 0; | ||
exports.lrec_sc = exports.lrec = exports.list_n = exports.list_sc = exports.list = exports.rep_n = exports.repr = exports.rep_sc = exports.rep = void 0; | ||
var ApplyParser_1 = require("./ApplyParser"); | ||
var ParserInterface_1 = require("./ParserInterface"); | ||
var SequencialParser_1 = require("./SequencialParser"); | ||
var TokenParser_1 = require("./TokenParser"); | ||
function rep(p) { | ||
@@ -127,13 +135,26 @@ var reprParser = repr(p); | ||
exports.rep_n = rep_n; | ||
function applyList(value) { | ||
return [value[0]].concat(value[1].map(function (pair) { return pair[1]; })); | ||
function applyList(_a) { | ||
var first = _a[0], tail = _a[1]; | ||
return __spreadArrays([first], tail); | ||
} | ||
function list(p, s) { | ||
return ApplyParser_1.apply(SequencialParser_1.seq(p, rep(SequencialParser_1.seq(s, p))), applyList); | ||
return ApplyParser_1.apply(SequencialParser_1.seq(p, rep(ApplyParser_1.kright(s, p))), applyList); | ||
} | ||
exports.list = list; | ||
function list_sc(p, s) { | ||
return ApplyParser_1.apply(SequencialParser_1.seq(p, rep_sc(SequencialParser_1.seq(s, p))), applyList); | ||
return ApplyParser_1.apply(SequencialParser_1.seq(p, rep_sc(ApplyParser_1.kright(s, p))), applyList); | ||
} | ||
exports.list_sc = list_sc; | ||
function list_n(p, s, count) { | ||
if (count < 1) { | ||
return TokenParser_1.succ([]); | ||
} | ||
else if (count === 1) { | ||
return ApplyParser_1.apply(p, function (value) { return [value]; }); | ||
} | ||
else { | ||
return ApplyParser_1.apply(SequencialParser_1.seq(p, rep_n(ApplyParser_1.kright(s, p), count - 1)), applyList); | ||
} | ||
} | ||
exports.list_n = list_n; | ||
function applyLrec(callback) { | ||
@@ -140,0 +161,0 @@ return function (value) { |
import { Token } from '../Lexer'; | ||
import { Parser } from './ParserInterface'; | ||
import { FailedParser, Parser } from './ParserInterface'; | ||
export declare function nil<T>(): Parser<T, undefined>; | ||
export declare function succ<T, R>(value: R): Parser<T, R>; | ||
export declare function fail(errorMessage: string): FailedParser; | ||
export declare function str<T>(toMatch: string): Parser<T, Token<T>>; | ||
export declare function tok<T>(toMatch: T): Parser<T, Token<T>>; |
@@ -5,3 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.tok = exports.str = exports.nil = void 0; | ||
exports.tok = exports.str = exports.fail = exports.succ = exports.nil = void 0; | ||
var ParserInterface_1 = require("./ParserInterface"); | ||
@@ -24,2 +24,33 @@ function nil() { | ||
exports.nil = nil; | ||
function succ(value) { | ||
return { | ||
parse: function (token) { | ||
return { | ||
candidates: [{ | ||
firstToken: token, | ||
nextToken: token, | ||
result: value | ||
}], | ||
successful: true, | ||
error: undefined | ||
}; | ||
} | ||
}; | ||
} | ||
exports.succ = succ; | ||
function fail(errorMessage) { | ||
return { | ||
parse: function (token) { | ||
return { | ||
successful: false, | ||
error: { | ||
kind: 'Error', | ||
pos: token === null || token === void 0 ? void 0 : token.pos, | ||
message: errorMessage | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
exports.fail = fail; | ||
function str(toMatch) { | ||
@@ -26,0 +57,0 @@ return { |
{ | ||
"name": "typescript-parsec", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "TypeScript Parser Combinator", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
95620
53
1216