当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript parsimmon.seq函数代码示例

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


在下文中一共展示了seq函数的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(''))
开发者ID:osnr,项目名称:pchrome,代码行数:9,代码来源:generate.ts

示例2: nodeMap

function nodeMap(mapper: any, ...parsers: Array<any>) {
  return P.seq(...parsers)
    .mark()
    .map(({start, value, end}) => {
      return mapper({
        start,
        end
      }, ...value);
    });
}
开发者ID:timse,项目名称:soyparser,代码行数:10,代码来源:parser.ts

示例3: binaryLeft

function binaryLeft(operatorsParser, nextParser): parsimmon.Parser<{}> {
  return parsimmon.seqMap(
    nextParser,
    parsimmon.seq(operatorsParser, nextParser).many(),
    (first, rest) =>
      rest.reduce((acc, ch) => {
        const [op, another] = ch;
        if (Array.isArray(acc) && op === acc[0]) return acc.concat([another]);
        if (Array.isArray(another) && op === another[0])
          return [op, acc].concat(another.slice(1));
        return [op, acc, another];
      }, first)
  );
}
开发者ID:zaidka,项目名称:genieacs,代码行数:14,代码来源:expression-parser.ts

示例4: token

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))
                    ).map(([action, updates, sideEffect]) => new lang.ARule(action, updates, sideEffect));

const TabSize = 4;

const prule =
    P.seq(P.index, lbrace.then(comparisons).skip(rbrace).skip(question))
        .chain(([index, conds]) =>
            P.index.chain((i) => i.column === index.column + TabSize ? rule : P.fail("no more")).atLeast(1).map((rules) => new lang.PRule(conds, rules)));
开发者ID:zoren,项目名称:verified-monkey-island,代码行数:29,代码来源:parser.ts

示例5: lexemeS

        .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,
    argumentType
  }));

assertParse(functionArgument, 'details: AccessibilityFeaturesCallbackArg', {
  argumentName: 'details',
  argumentType: 'AccessibilityFeaturesCallbackArg'
});
assertNotParse(functionArgument, 'details AccessibilityFeaturesCallbackArg');

assertParse(functionType, '(details: AccessibilityFeaturesCallbackArg) => void');
assertNotParse(functionType, '(details: AccessibilityFeaturesCallbackArg => void');

assertParse(functionType, '() => void', {
开发者ID:osnr,项目名称:pchrome,代码行数:32,代码来源:generate.ts

示例6: unary

 function unary(operatorsParser, nextParser): parsimmon.Parser<{}> {
   return parsimmon.seq(operatorsParser, nextParser).or(nextParser);
 }
开发者ID:zaidka,项目名称:genieacs,代码行数:3,代码来源:expression-parser.ts


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