How to use the parsimmon.regexp function in parsimmon

To help you get started, we’ve selected a few parsimmon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kantord / emuto / src / parsers / primitives / number.js View on Github external
// @flow

import P from 'parsimmon'
import type { NodeType } from '../../types'

export default P.regexp(
  /(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/
).map((value: string): NodeType => ({
  name: 'primitive',
  value
}))
github microsoft / dtslint / bin / rules / definitelytyped-header-parser.js View on Github external
function contributorsParser(strict) {
    // Need to remove '^' and '$' from the regex, parsimmon does not expect those.
    const contributor = strict
        ? pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/\/, 1), (name, username) => ({ name, url: "https://github.com/" + username }))
        : pm.seqMap(pm.regexp(/([^<]+) /, 1), pm.regexp(/<([^>]+)>/, 1), (name, url) => ({ name, url }));
    const contributors = pm.sepBy1(contributor, separator);
    if (!strict) {
        // Allow trailing whitespace.
        return pm.seqMap(contributors, pm.regexp(/ */), a => a);
    }
    return contributors;
}
// TODO: Should we do something with the URL?
github kantord / emuto / src / parsers / inputProp.js View on Github external
// @flow

import P from 'parsimmon'
import type { InputPropNodeType } from '../types'

export default P.regexp(/\.[$A-Z_][0-9A-Z_$]*/i)
  .map((value: string): InputPropNodeType => ({
    name: 'inputProp',
    value
  }))
  .desc('inputProp')
github kantord / emuto / src / parsers / math / math.js View on Github external
import P from 'parsimmon'

import BinaryOperatorParser from '../abstract/binaryOperator'
import UnaryOperatorParser from './unaryOperator'

import type { ParserType } from '../../types'

const processBoolean2 = (x: string): string => x + '='
const processBoolean3 = (x: string): string =>
  x === 'or' ? '||' : x === 'and' ? '&&' : x

const operatorPrecedenceTable = [
  ['unary', UnaryOperatorParser],
  ['multiplicative', P.regexp(/[*/%]/)],
  ['additive', P.regexp(/[+-]/)],
  ['boolean1', P.regexp(/[<>]=?/)],
  ['boolean2', P.regexp(/[=!]=/).map(processBoolean2)],
  ['boolean3', P.regexp(/(\|\||&&|or|and)/).map(processBoolean3)]
]

export default operatorPrecedenceTable
  .slice(1)
  .reduce(
    (
      ParentParser: ParserType,
      [parserDecription, Parser]: [string, ParserType]
    ): ParserType =>
      BinaryOperatorParser(ParentParser, Parser, parserDecription),
    operatorPrecedenceTable[0][1]
  )
github hydux / hydux-mutator / src / parser.ts View on Github external
param: r =>
    P.regexp(/"((?:\\.|.)*?)"/, 1)
      .map(value => ({
        type: 'string',
        value: interpretEscapes(value)
      }))
      .or(P.regexp(/'((?:\\.|.)*?)'/, 1).map(value => ({
        type: 'string',
        value: interpretEscapes(value)
      })))
      .or(P.regexp(/\d+/).map(value => ({
        type: 'number',
        value: Number(value)
      })))
      .or(r.letters.map(value => ({
        type: 'variable',
        value,
      }))),
github keean / zenscript / src / parse.js View on Github external
const typeVariable = (token(P.regexp(/[A-Z]+[A-Z0-9]*/)).map((n) => {
   let t = var_map.get(n)
   if (t === undefined) {
      t = new AST.TypeVariable(n)
      var_map.set(n, t)
   }   
   return t
})).desc('type-variable')

let texp
const tl2 = P.sepBy(P.lazy(() => {return texp}), comma).desc('type-list')
const typeList = token(P.string('[')).then(tl2).skip(token(P.string(']')))

const typeConstructor = P.seqMap(
   token(P.regexp(/^(?=.*[a-z])[A-Z][a-zA-Z0-9]+/)).desc('type-constructor'),
   typeList.or(P.succeed([])),
   (n, ps) => {return new AST.TypeConstructor(n, ps)}
)

const typeSubExpression = P.seqMap(
   typeList.map((ts) => {return new AST.TypeConstructor('Product', ts)}).
      or(typeConstructor).or(typeVariable).or(inParenthesis(P.lazy(() => {return texp}))),
   optional(token(P.string('as')).then(typeVariable)),
   (texp, mu) => {
      if (mu !== undefined) {
         if (!unify.types(texp, mu)) {
            throw 'unification error when parsing recursive type'
         }
      }
      return texp
   }
github hydux / hydux-mutator / lib / parser.js View on Github external
param: function (r) {
        return P.regexp(/"((?:\\.|.)*?)"/, 1)
            .map(function (value) { return ({
            type: 'string',
            value: interpretEscapes(value)
        }); })
            .or(P.regexp(/'((?:\\.|.)*?)'/, 1).map(function (value) { return ({
            type: 'string',
            value: interpretEscapes(value)
        }); }))
            .or(P.regexp(/\d+/).map(function (value) { return ({
            type: 'number',
            value: Number(value)
        }); }))
            .or(r.letters.map(function (value) { return ({
            type: 'variable',
            value: value,
        }); }));
    },
    field: function (r) { return r._
github hydux / hydux-mutator / lib / parser.js View on Github external
param: function (r) {
        return P.regexp(/"((?:\\.|.)*?)"/, 1)
            .map(function (value) { return ({
            type: 'string',
            value: interpretEscapes(value)
        }); })
            .or(P.regexp(/'((?:\\.|.)*?)'/, 1).map(function (value) { return ({
            type: 'string',
            value: interpretEscapes(value)
        }); }))
            .or(P.regexp(/\d+/).map(function (value) { return ({
            type: 'number',
            value: Number(value)
        }); }))
            .or(r.letters.map(function (value) { return ({
            type: 'variable',
            value: value,
        }); }));
    },
    field: function (r) { return r._