当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript tparse.choose函数代码示例

本文整理汇总了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
  )
开发者ID:seanchas116,项目名称:macaron,代码行数:12,代码来源:newVariable.ts

示例2: lazy

var parseElse = lazy(() =>
  keyword("else").thenTake(
    choose(
      parseIfExpression.map(e => [e]),
      parseBlock
    )
  )
开发者ID:seanchas116,项目名称:macaron,代码行数:7,代码来源:control.ts

示例3: lazy

var parseLiteral = lazy(() =>
  choose<ExpressionAST>(
    parseNumberLiteral,
    parseStringLiteral,
    parseFunction,
    parseClass,
    parseInterface
  )
开发者ID:seanchas116,项目名称:macaron,代码行数:8,代码来源:value.ts

示例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)
    );
}
开发者ID:seanchas116,项目名称:macaron,代码行数:9,代码来源:postfix.ts

示例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))
  );
}
开发者ID:seanchas116,项目名称:macaron,代码行数:11,代码来源:operator.ts

示例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
  )
开发者ID:seanchas116,项目名称:macaron,代码行数:11,代码来源:assignment.ts

示例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
  )
开发者ID:seanchas116,项目名称:macaron,代码行数:15,代码来源:new.ts

示例8: parseOperator

function parseOperator(operatorList: string[]) {
  return choose(...operatorList.map(op => keyword(op)))
    .withRange()
    .map(([op, range]) => new OperatorAST(range, op));
}
开发者ID:seanchas116,项目名称:macaron,代码行数:5,代码来源:operator.ts

示例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(_);
}
开发者ID:seanchas116,项目名称:macaron,代码行数:30,代码来源:common.ts


注:本文中的tparse.choose函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。