本文整理汇总了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)
)
示例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;
示例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));
示例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
)
示例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
)
);
示例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;
示例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)
)
);
示例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
)
)
);
示例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
])
);
示例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))
);