本文整理汇总了TypeScript中parsimmon.seqMap函数的典型用法代码示例。如果您正苦于以下问题:TypeScript seqMap函数的具体用法?TypeScript seqMap怎么用?TypeScript seqMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了seqMap函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
Comparison: function(r) {
return parsimmon.alt(
parsimmon.seqMap(r.ValueExpression, r.IsNullOperator, (p, o) => [o, p]),
parsimmon.seqMap(
r.ValueExpression,
r.ComparisonOperator,
r.ValueExpression,
(p, o, v) => [o, p, v]
),
parsimmon.seqMap(
r.ValueExpression,
r.LikeOperator,
r.ValueExpression.skip(
parsimmon
.regexp(/escape/i)
.result("ESCAPE")
.skip(parsimmon.whitespace)
.desc("ESCAPE")
),
r.ValueExpression,
(a, b, c, d) => [b, a, c, d]
),
parsimmon.seqMap(
r.ValueExpression,
r.LikeOperator,
r.ValueExpression,
(a, b, c) => [b, a, c]
)
);
},
示例2:
const newParser: P.Parser<string> = P.lazy(() =>
P.alt(
consumeEnd ? parser.result('') : P.lookahead(parser),
P.seqMap(
P.any,
newParser,
(s, next) => s + next))
示例3: binaryLeft
function binaryLeft(operatorsParser, nextParser): parsimmon.Parser<{}> {
return parsimmon.seqMap(
nextParser,
parsimmon.seq(operatorsParser, nextParser).many(),
(first, rest) =>
rest.reduce((acc, ch) => {
const [op, another] = ch;
if (Array.isArray(acc) && op === acc[0]) return acc.concat([another]);
if (Array.isArray(another) && op === another[0])
return [op, acc].concat(another.slice(1));
return [op, acc, another];
}, first)
);
}
示例4: closeCmd
const bodyParser: P.Parser<S.Body> = P.lazy(() =>
html.then(P.alt(
closeCmd(name).result([]),
P.alt(...inter.map(openCmd))
.result([])
.then(bodyParser),
P.seqMap(
P.alt(
literal,
call,
letStatement,
otherCmd('if', 'elseif', 'else'),
otherCmd('foreach', 'ifempty'),
otherCmd('msg', 'fallbackmsg'),
otherCmd('switch'),
interpolation('{', '}')),
bodyParser,
reverseJoin)))
示例5: token
var stringLiteral =
token(P.regexp(/"((?:\\.|.)*?)"/, 1))
.desc('string');
const id = token(P.regexp(/[a-z][a-zA-Z0-9.]*/)).desc("id");
const ctor = token(P.regexp(/[A-Z][a-zA-Z0-9]*/)).desc("ctor").map((s) => new lang.Constant(s));
const exp: P.Parser<lang.Expression> = P.lazy(() =>
whitespace.then(P.alt(
id.map((s) => new lang.VariableDeref(s)), ctor
)));
const comparisonOp =
P.alt(isEq.result(lang.ComparisonOperator.EQ), notEq.result(lang.ComparisonOperator.NEQ));
const comparison = P.seqMap(exp, comparisonOp, exp, (e1, compOp, e2) => new lang.Condition(e1, compOp, e2))
export const comparisons = commaSep(comparison);
const update = P.seq(id.skip(setEq), ctor).map(([id, c]) => new lang.Update(id, c));
const action = P.seq(id.skip(lpar), commaSep(id).skip(rpar)).map(([id, names]) => new lang.Action(id, names));
const arule = P.seq(action.skip(then).skip(lbrace),
semiColonSep(update).skip(rbrace),
P.alt(ampersand.skip(lbrace).then(stringLiteral).skip(rbrace).map((s) => new lang.PrintSideEffect(s)), P.succeed(undefined))
).map(([action, updates, sideEffect]) => new lang.ARule(action, updates, sideEffect));
const TabSize = 4;
const prule =
示例6: regex
export interface Declarelation {
label: string;
text: string;
}
export interface Node extends Declarelation {
start: Position;
end: Position;
}
let lsec = regex(/.*\[/);
let rsec = regex(/\].*/);
let sectionText = regex(/[^#\]]+/).map(text => {return {label: 'section', text: text}; }).mark();
let rank = regex(/#*/);
let section = seqMap(lsec, sectionText, rsec, (...params) => params[1]);
let equal = regex(/=+/);
let lapi = string('{');
let rapi = string('}');
let api = regex(/[^}]+/).map(text => {return {label: 'api', text: text}; }).mark();
let directionText = regex(/.*/).map(text => {return {label: 'direction', text: text}; }).mark();
let lt = string('>').skip(optWhitespace);
let directionWithoutApi = seqMap(equal, lt, directionText, (...params) => params[2]);
let directionWithApi = seqMap(equal, lapi, api, rapi, equal, lt, directionText, (...params) => [params[2], params[6]]);
let direction = alt(directionWithoutApi, directionWithApi);
let text = regex(/.*/).mark().map(text => {
return {label: 'text', text: text};
});
示例7: expression
const functionArgs: P.Parser<Array<S.Expression>> = P.lazy(() => P.alt(
rparen.result([]),
expression(rparen).map(result => [result]),
P.seqMap(expression(comma), functionArgs, reverseJoin),
));
示例8: joined
const lparen = P.string('(');
const newLine = P.string('\n');
const qmark = P.string('?');
const rbrace = P.string('}');
const rbracket = P.string(']');
const rparen = P.string(')');
const space = P.string(' ');
const squote = P.string('\'');
const underscore = P.string('_');
const attributeName = joined(P.letter, P.string('-'));
const html = P.noneOf('{}').many().desc("Html Char");
const identifierName = P.seqMap(
P.alt(P.letter, underscore),
P.alt(P.letter, underscore, P.digit).many(),
(start, rest) => start + rest.join('')
);
const literal = nodeMap(
S.Literal,
openCmd('literal').then(withAny(closeCmd('literal')))
);
const namespace: P.Parser<Array<string>> = P.lazy(() => P.alt(
P.seqMap(identifierName, dot.then(namespace), reverseJoin),
identifierName.map(name => [name])
));
const templateName = optional(dot)
.then(namespace)