本文整理匯總了TypeScript中parsimmon.lazy函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript lazy函數的具體用法?TypeScript lazy怎麽用?TypeScript lazy使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了lazy函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
function orAny<T>(parser: P.Parser<T>): P.Parser<T> {
const newParser: P.Parser<T> = P.lazy(() =>
parser.or(P.any.then(newParser))
);
return newParser;
}
示例2: bodyFor
function bodyFor(name: string, ...inter: Array<String>): P.Parser<S.Body> {
const bodyParser: P.Parser<S.Body> = P.lazy(() =>
html.then(P.alt(
closeCmd(name).result([]),
P.alt(...inter.map(openCmd))
.result([])
.then(bodyParser),
P.seqMap(
P.alt(
literal,
call,
letStatement,
otherCmd('if', 'elseif', 'else'),
otherCmd('foreach', 'ifempty'),
otherCmd('msg', 'fallbackmsg'),
otherCmd('switch'),
interpolation('{', '}')),
bodyParser,
reverseJoin)))
);
return bodyParser;
}
示例3: token
function commaSep<T>(parser: P.Parser<T>) {
return P.sepBy(parser, comma);
}
function semiColonSep<T>(parser: P.Parser<T>) {
return P.sepBy(parser, semiColon);
}
var stringLiteral =
token(P.regexp(/"((?:\\.|.)*?)"/, 1))
.desc('string');
const id = token(P.regexp(/[a-z][a-zA-Z0-9.]*/)).desc("id");
const ctor = token(P.regexp(/[A-Z][a-zA-Z0-9]*/)).desc("ctor").map((s) => new lang.Constant(s));
const exp: P.Parser<lang.Expression> = P.lazy(() =>
whitespace.then(P.alt(
id.map((s) => new lang.VariableDeref(s)), ctor
)));
const comparisonOp =
P.alt(isEq.result(lang.ComparisonOperator.EQ), notEq.result(lang.ComparisonOperator.NEQ));
const comparison = P.seqMap(exp, comparisonOp, exp, (e1, compOp, e2) => new lang.Condition(e1, compOp, e2))
export const comparisons = commaSep(comparison);
const update = P.seq(id.skip(setEq), ctor).map(([id, c]) => new lang.Update(id, c));
const action = P.seq(id.skip(lpar), commaSep(id).skip(rpar)).map(([id, names]) => new lang.Action(id, names));
const arule = P.seq(action.skip(then).skip(lbrace),
semiColonSep(update).skip(rbrace),
P.alt(ampersand.skip(lbrace).then(stringLiteral).skip(rbrace).map((s) => new lang.PrintSideEffect(s)), P.succeed(undefined))
示例4: lazy
functionReturn: TypeSignature;
}
type TypeSignature = string | FunctionTypeSignature;
interface FunctionArgument {
argumentName: string;
argumentType: TypeSignature;
}
const functionType: Parser<FunctionTypeSignature> =
lazy('function type', () =>
seq(
lparen
.then(sepBy(functionArgument, lexemeS(',')))
.skip(rparen)
.skip(lexemeS('=>')),
typeSignature
).map(([functionArguments, functionReturn]: [FunctionArgument[], TypeSignature]) => ({
functionArguments,
functionReturn
}))
);
const typeSignature: Parser<TypeSignature> =
identifier.or(functionType);
const functionArgument: Parser<FunctionArgument> =
seq(
identifier,
colon.then(typeSignature)
).map(([argumentName, argumentType]: [string, TypeSignature]) => ({
argumentName,
示例5: joined
const attributeName = joined(P.letter, P.string('-'));
const html = P.noneOf('{}').many().desc("Html Char");
const identifierName = P.seqMap(
P.alt(P.letter, underscore),
P.alt(P.letter, underscore, P.digit).many(),
(start, rest) => start + rest.join('')
);
const literal = nodeMap(
S.Literal,
openCmd('literal').then(withAny(closeCmd('literal')))
);
const namespace: P.Parser<Array<string>> = P.lazy(() => P.alt(
P.seqMap(identifierName, dot.then(namespace), reverseJoin),
identifierName.map(name => [name])
));
const templateName = optional(dot)
.then(namespace)
.map(toTemplateName);
const namespaceCmd = P.string('{namespace')
.skip(P.whitespace)
.then(namespace.map(names => names.join('.')))
.skip(rbrace);
const stringLiteral = nodeMap(
S.StringLiteral,
squote.then(withAny(squote))
);