本文整理匯總了TypeScript中parsimmon.string函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript string函數的具體用法?TypeScript string怎麽用?TypeScript string使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了string函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: lazy
const anyBlock: Parser<string> = lazy(() =>
seq(
string('{'), // Let's not eat whitespace around the braces.
alt(
anyBlock,
regex(/[^{}]+/)
).many().map(ss => ss.join('')),
string('}')
).map(ss => ss.join(''))
示例2: function
Parameter: function(r) {
return parsimmon
.alt(
parsimmon.regexp(/[a-zA-Z0-9_.*-]+/),
r.Expression.wrap(
parsimmon.string("{").skip(parsimmon.optWhitespace),
parsimmon.string("}")
)
)
.atLeast(1)
.map(x => ["PARAM", x.length > 1 ? ["||"].concat(x) : x[0]])
.skip(parsimmon.optWhitespace)
.desc("parameter");
},
示例3: nodeMap
const param = P.lazy(() => nodeMap(
S.Param,
P.string('{param')
.then(spaced(identifierName)),
P.alt(
spaced(attribute.many()).skip(rbrace).then(bodyFor('param')),
spaced(colon).then(expression(closingBrace)))
));
示例4: token
let ts = (s: string) => token(P.string(s));
示例5: lexemeS
function lexemeS(s: string): Parser<string> { return lexeme(string(s)); }
示例6: seq
interface FunctionDeclaration {
functionName: string;
functionArguments: FunctionArgument[];
functionReturn: TypeSignature;
}
const exportFunctionDeclaration: Parser<FunctionDeclaration> =
seq(
lexemeS('export')
.then(lexemeS('function'))
.then(identifier.desc('function name')),
lparen
.then(sepBy(functionArgument, lexemeS(',')))
.skip(rparen),
colon
.then(typeSignature)
.skip(string(';')) // Let's not eat whitespace here.
).map(([functionName, functionArguments, functionReturn]: [string, FunctionArgument[], TypeSignature]) => ({
functionName,
functionArguments,
functionReturn
}));
assertParse(
exportFunctionDeclaration,
'export function remove(menuItemId: string, callback?: () => void): void;',
{
functionName: 'remove',
functionArguments: [
{
argumentName: 'menuItemId',
argumentType: 'string'