• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript tparse.lazy函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中tparse.lazy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript lazy函数的具体用法?TypeScript lazy怎么用?TypeScript lazy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了lazy函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: lazy

import {Parser, choose, sequence, lazy} from "tparse";
import {parseOperator, parseBinaryExpression} from "./operator";
import {parseAssignment} from "./assignment";
import {parseAssignable} from "./assignable";
import {parseTypeExpression} from "./typeExpression";
import {parseIdentifier} from "./identifier";
import {keyword} from "./common";

export
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
  )
);

export
const parseTypeAlias: Parser<ExpressionAST> =
  choose(
    sequence(
      keyword("type"),
      parseIdentifier,
      keyword("=").thenTake(parseTypeExpression)
    )
开发者ID:seanchas116,项目名称:macaron,代码行数:31,代码来源:newVariable.ts


示例2: lazy

import {lazy} from "tparse";
import {typeBinaryOperators} from "../operators";
import {parseIdentifier} from "./identifier";
import {parsePostfixWith} from "./postfix";
import {parseBinaryExpressionWith} from "./operator";
import {parseGenericsCall} from "./genericsCall";
import {parseMemberAccess} from "./memberAccess";

const parseTypePostfix = lazy(() =>
  parsePostfixWith(parseIdentifier, [
    parseGenericsCall,
    parseMemberAccess
  ])
);

const parseTypeBinaryExpression = parseBinaryExpressionWith(parseTypePostfix, typeBinaryOperators);

export
const parseTypeExpression = parseTypeBinaryExpression;
开发者ID:seanchas116,项目名称:macaron,代码行数:19,代码来源:typeExpression.ts


示例3: parseUnaryExpressionWith

  return operands[0];
}

export
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))
  );
}

export
function parseBinaryExpressionWith(subParser: Parser<ExpressionAST>, operators: string[][]) {
  return sequence(
    subParser,
    sequence(parseOperator(flattenSort(operators)), subParser).repeat()
  )
    .map(([first, rest]) => buildBinaryExpression(operators, first, rest));
}

export
var parseUnaryExpression = lazy(() => parseUnaryExpressionWith(parseControlExpression, unaryOperators));

export
var parseBinaryExpression = lazy(() => parseBinaryExpressionWith(parseUnaryExpression, binaryOperators));
开发者ID:seanchas116,项目名称:macaron,代码行数:30,代码来源:operator.ts


示例4: lazy

import {ExpressionAST} from "../AST";
import {choose, lazy} from "tparse";
import {keyword} from "./common";
import {parseExpression} from "./expression";
import {parseIdentifier} from "./identifier";
import {parseNumberLiteral} from "./number";
import {parseStringLiteral} from "./string";
import {parseFunction} from "./function";
import {parseClass, parseInterface} from "./class";

var parseLiteral = lazy(() =>
  choose<ExpressionAST>(
    parseNumberLiteral,
    parseStringLiteral,
    parseFunction,
    parseClass,
    parseInterface
  )
);

var parseParen = lazy(() =>
  keyword("(").thenTake(parseExpression).thenSkip(keyword(")"))
)

export
var parseValue = lazy(() =>
  choose(
    parseParen,
    parseLiteral,
    parseIdentifier
  )
开发者ID:seanchas116,项目名称:macaron,代码行数:31,代码来源:value.ts


示例5: lazy

import {
  ExpressionAST,
  FunctionCallAST
} from "../AST";

import {Parser, choose, sequence, lazy} from "tparse";
import {keyword} from "./common";
import {parseArgumentList} from "./functionCall";
import {parseValue} from "./value";
import {parsePostfixWithoutFunctionCall} from "./postfix";

export
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,代码行数:28,代码来源:new.ts


示例6: lazy

import {
  AssignableAST,
  IdentifierAssignableAST
} from "../AST";

import {Parser, sequence, lazy} from "tparse";
import {parseIdentifier} from "./identifier";
import {parseTypeExpression} from "./typeExpression";

var parseIdentifierAssignable: Parser<AssignableAST> = lazy(() =>
  sequence(
    parseIdentifier,
    parseTypeExpression.mayBe()
  )
    .withRange()
    .map(([[name, type], range]) => new IdentifierAssignableAST(range, name, type))
);

export
var parseAssignable = parseIdentifierAssignable;
开发者ID:seanchas116,项目名称:macaron,代码行数:20,代码来源:assignable.ts


示例7: lazy

import {
  ExpressionAST,
  FunctionCallAST,
} from "../AST";

import {Parser, lazy} from "tparse";
import {keyword} from "./common";
import {parseLines} from "./block";

export
var parseArgumentList = lazy(() =>
  keyword("(").thenTake(parseLines).thenSkip(keyword(")"))
);

export
var parseFunctionCall: Parser<(value: ExpressionAST) => ExpressionAST> = lazy(() =>
  parseArgumentList.map(args =>
    (value: ExpressionAST) => new FunctionCallAST(value.range, value, args, false)
  )
);
开发者ID:seanchas116,项目名称:macaron,代码行数:20,代码来源:functionCall.ts


示例8: lazy

  ExpressionAST,
  IfAST
} from "../AST";

import {Parser, choose, sequence, lazy} from "tparse";
import {keyword} from "./common";
import {parseExpression} from "./expression";
import {parseBlock} from "./block";
import {parsePostfix} from "./postfix";

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 || []))
  )
);

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


示例9: parsePostfixWith

import {parseGenericsCall} from "./genericsCall";
import {parseMemberAccess} from "./memberAccess";

export
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)
    );
}

export
var parsePostfix = lazy(() =>
  parsePostfixWith(parseNew, [
    parseFunctionCall,
    parseGenericsCall,
    parseMemberAccess
  ])
);

export
var parsePostfixWithoutFunctionCall = lazy(() =>
  parsePostfixWith(parseNew, [
    parseGenericsCall,
    parseMemberAccess
  ])
);
开发者ID:seanchas116,项目名称:macaron,代码行数:30,代码来源:postfix.ts


示例10: regExp

import {
  IdentifierAST,
} from "../AST";

import {
  sequence,
  regExp,
  lazy
} from "tparse";

import {
  _,
} from "./common";

// TODO: allow more characters
const parseIdentifierHead = regExp(/[a-zA-Z$_]/);
const parseIdentifierTail = regExp(/[a-zA-Z$_0-9]/);

export
var parseIdentifier = lazy(() =>
  sequence(parseIdentifierHead, parseIdentifierTail.repeat())
    .text()
    .withRange()
    .thenSkip(_)
    .map(([text, range]) => new IdentifierAST(range, text))
);
开发者ID:seanchas116,项目名称:macaron,代码行数:26,代码来源:identifier.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript tparse.sequence函数代码示例发布时间:2022-05-25
下一篇:
TypeScript tparse.choose函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap