本文整理汇总了TypeScript中tparse.choose函数的典型用法代码示例。如果您正苦于以下问题:TypeScript choose函数的具体用法?TypeScript choose怎么用?TypeScript choose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了choose函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: lazy
var parseNewVariable: Parser<ExpressionAST> = lazy(() =>
choose(
sequence(
choose(keyword("let"), keyword("var")),
parseAssignable,
parseTypeExpression.mayBe(),
keyword("=").thenTake(parseNewVariable)
)
.withRange()
.map(([[declaration, left, type, right], range]) => new NewVariableAST(range, declaration, type, left, right)),
parseAssignment
)
示例2: lazy
var parseElse = lazy(() =>
keyword("else").thenTake(
choose(
parseIfExpression.map(e => [e]),
parseBlock
)
)
示例3: lazy
var parseLiteral = lazy(() =>
choose<ExpressionAST>(
parseNumberLiteral,
parseStringLiteral,
parseFunction,
parseClass,
parseInterface
)
示例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: 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))
);
}
示例6: lazy
var parseAssignment: Parser<ExpressionAST> = lazy(() =>
choose(
sequence(
parseAssignable,
parseAssignmentOperator,
parseAssignment
)
.withRange()
.map(([[left, op, right], range]) => new AssignmentAST(range, left, op, right)),
parseBinaryExpression
)
示例7: lazy
var parseNew: Parser<ExpressionAST> = lazy(() =>
choose(
keyword("new").thenTake(
sequence(
parsePostfixWithoutFunctionCall,
parseArgumentList
)
)
.withRange()
.map(([[klass, args], range]) =>
new FunctionCallAST(range, klass, args, true)
)
,
parseValue
)
示例8: parseOperator
function parseOperator(operatorList: string[]) {
return choose(...operatorList.map(op => keyword(op)))
.withRange()
.map(([op, range]) => new OperatorAST(range, op));
}
示例9: regExp
} from "tparse";
export
const whitespace = regExp(/[\t\v\f ]/);
export
const separator = regExp(/[\n,]/);
export
const nonSeparator = regExp(/[^\n,]/);
export
const comment = sequence(string("//"), nonSeparator.repeat());
export
const empty = choose<any>(whitespace, comment);
export
const _ = empty.repeat();
export
const __ = choose(empty, separator).repeat();
export
const ___ = sequence(_, separator, sequence(_, separator).repeat(), _);
export
function keyword(text: string) {
return string(text).thenSkip(_);
}