本文整理汇总了TypeScript中parsimmon.seq函数的典型用法代码示例。如果您正苦于以下问题:TypeScript seq函数的具体用法?TypeScript seq怎么用?TypeScript seq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了seq函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: lazy
const anyBlock: Parser<string> = lazy(() =>
seq(
string('{'), // Let's not eat whitespace around the braces.
alt(
anyBlock,
regex(/[^{}]+/)
).many().map(ss => ss.join('')),
string('}')
).map(ss => ss.join(''))
示例2: nodeMap
function nodeMap(mapper: any, ...parsers: Array<any>) {
return P.seq(...parsers)
.mark()
.map(({start, value, end}) => {
return mapper({
start,
end
}, ...value);
});
}
示例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: token
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 =
P.seq(P.index, lbrace.then(comparisons).skip(rbrace).skip(question))
.chain(([index, conds]) =>
P.index.chain((i) => i.column === index.column + TabSize ? rule : P.fail("no more")).atLeast(1).map((rules) => new lang.PRule(conds, rules)));
示例5: lexemeS
.then(sepBy(functionArgument, lexemeS(',')))
.skip(rparen)
.skip(lexemeS('=>')),
typeSignature
).map(([functionArguments, functionReturn]: [FunctionArgument[], TypeSignature]) => ({
functionArguments,
functionReturn
}))
);
const typeSignature: Parser<TypeSignature> =
identifier.or(functionType);
const functionArgument: Parser<FunctionArgument> =
seq(
identifier,
colon.then(typeSignature)
).map(([argumentName, argumentType]: [string, TypeSignature]) => ({
argumentName,
argumentType
}));
assertParse(functionArgument, 'details: AccessibilityFeaturesCallbackArg', {
argumentName: 'details',
argumentType: 'AccessibilityFeaturesCallbackArg'
});
assertNotParse(functionArgument, 'details AccessibilityFeaturesCallbackArg');
assertParse(functionType, '(details: AccessibilityFeaturesCallbackArg) => void');
assertNotParse(functionType, '(details: AccessibilityFeaturesCallbackArg => void');
assertParse(functionType, '() => void', {
示例6: unary
function unary(operatorsParser, nextParser): parsimmon.Parser<{}> {
return parsimmon.seq(operatorsParser, nextParser).or(nextParser);
}