當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。