本文整理汇总了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;
}
开发者ID:timse,项目名称:soyparser,代码行数:7,代码来源:parser.ts
示例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;
}
开发者ID:timse,项目名称:soyparser,代码行数:23,代码来源:parser.ts
示例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))
开发者ID:zoren,项目名称:verified-monkey-island,代码行数:32,代码来源:parser.ts
示例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,
开发者ID:osnr,项目名称:pchrome,代码行数:32,代码来源:generate.ts
示例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))
);
开发者ID:timse,项目名称:soyparser,代码行数:32,代码来源:parser.ts
注:本文中的parsimmon.lazy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论