本文整理匯總了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);
}