當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。