本文整理汇总了TypeScript中tparse.sequence函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sequence函数的具体用法?TypeScript sequence怎么用?TypeScript sequence使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sequence函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: parseBinaryExpressionWith
function parseBinaryExpressionWith(subParser: Parser<ExpressionAST>, operators: string[][]) {
return sequence(
subParser,
sequence(parseOperator(flattenSort(operators)), subParser).repeat()
)
.map(([first, rest]) => buildBinaryExpression(operators, first, rest));
}
示例2: lazy
var parseIdentifierAssignable: Parser<AssignableAST> = lazy(() =>
sequence(
parseIdentifier,
parseTypeExpression.mayBe()
)
.withRange()
.map(([[name, type], range]) => new IdentifierAssignableAST(range, name, type))
示例3: sequence
function separated<T>(parser: Parser<T>) {
return sequence(
__.thenTake(parser.mayBe()),
___.thenTake(parser).repeat().thenSkip(__)
)
.map(([first, rest]) => first ? [first].concat(rest) : []);
}
示例4: parsePostfixWith
function parsePostfixWith(subParser: Parser<ExpressionAST>, postfixParsers: Parser<(value: ExpressionAST) => ExpressionAST>[]) {
return sequence(
subParser,
choose(...postfixParsers).repeat()
)
.map(([value, postfixes]) =>
postfixes.reduce((current, postfix) => postfix(current), value)
);
}
示例5: lazy
var parseUnnamedFunction = lazy(() =>
sequence(
parseParameterList,
keyword("=>").thenTake(parseBlock)
)
.withRange()
.map(([[parameters, expressions], range]) =>
new FunctionAST(range, new IdentifierAST(range, ""), [], parameters, null, expressions)
)
示例6: lazy
var parseIfExpression: Parser<ExpressionAST> = lazy(() =>
keyword("if").thenTake(
sequence(
parseExpression,
parseBlock,
parseElse.mayBe()
)
.withRange()
.map(([[cond, ifTrue, ifFalse], range]) => new IfAST(range, cond, ifTrue, ifFalse || []))
)
示例7: lazy
var parseMethodDeclaration = lazy(() =>
sequence(
parseIdentifier,
parseParameterList,
parseTypeExpression
)
.withRange()
.map(([[name, params, returnType], range]) =>
new FunctionAST(range, name, [], params, returnType, null)
)
示例8: parseUnaryExpressionWith
function parseUnaryExpressionWith(subParser: Parser<ExpressionAST>, operators: string[][]) {
return choose(
subParser,
sequence(
parseOperator(flattenSort(operators)),
subParser
)
.withRange()
.map(([[operator, operand], range]) => new UnaryAST(range, operator, operand))
);
}