@prelude/parser
TypeScript icon, indicating that this package has built-in type declarations

7.1.0 • Public • Published

Maintainability Rating Security Rating Bugs Vulnerabilities Duplicated Lines (%) Reliability Rating Quality Gate Status Technical Debt Coverage Lines of Code Code Smells


Parser combinators module

Usage

npm i -E @prelude/parser
import * as P from '@prelude/parser'

Rules

Top level rules

  • char-range
  • char-ranges
  • either
  • enclosed
  • exhaustive
  • literal
  • map
  • maybe
  • pair
  • right
  • sep0 (alias: separated0)
  • sep1 (alias: separated1)
  • sep2 (alias: separated2)
  • seq (alias: sequence)
  • star
  • times
  • trim
  • union
  • utf8
  • ws0
  • ws1

Top level helpers

  • Input
  • Invalid
  • join
  • ParserResult
  • Rfc8259

rfc5234 – Augmented BNF for Syntax Specifications: ABNF

  • alpha
  • bit
  • char

rfc8259 – The JavaScript Object Notation (JSON) Data Interchange Format

  • false
  • null
  • trim
  • true
  • ws

Parser module

  • dquote: Parser<string>

  • dquote2: Parser<string>

  • lf: Parser<string>

  • cr: Parser<string>

  • nl: Parser<string>

  • textdata: Parser<string>

  • comma: Parser<string>

  • nonEscaped: Parser<string>

  • escaped: Parser<string>

  • field: Parser<string>

  • record: Parser<string[]>

  • file: Parser<string[][]>

  • parse: (inputString: string) => string[][]

  • false: Parser<boolean>

  • null: Parser<any>

  • parse: (inputString: string) => unknown

  • true: Parser<boolean>

  • valueSeparator: Parser<string>

  • charRange: (ranges: string) => Parser<string>

    Returns parser matching provided character ranges.

    Example charRange('09azAZ') – equivalent to /[0-9a-zA-Z]/ regexp.

  • Csv

  • either: <A, B>(a: Parser<A>, b: Parser<B>) => Parser<A | B>

  • exhaustive: <A>(a: Parser<A>) => (inputString: string) => A

    Returns top level string to result parser asserting all input has been parsed.

    Throws If parser fails or input is not fully exhausted.

  • exhaustiveEmpty: (input: any) => Fail | Ok<any>

    Returns parser that matches empty string exhaustively.

  • join: (a: Parser<string[]>, glue?: string) => Parser<string>

    Joins string (or undefined) result array into single string result.

  • Json

  • literal: (expected: string) => Parser<string>

  • map: <A, B>(a: Parser<A>, f: (_: A) => B) => Parser<B>

  • maybe: <A>(a: Parser<A>) => Parser<A>

  • pair: <A, B>(a: Parser<A>, b: Parser<B>) => Parser<[A, B]>

  • Rfc4180

  • Rfc8259

  • right: <B>(a: Parser<unknown>, b: Parser<B>) => Parser<B>

    Returns b after successful a and b sequence match.

  • sep0: <A>(s: Parser<unknown>, a: Parser<A>) => Parser<A[]>

  • sep1: <A>(s: Parser<unknown>, a: Parser<A>) => Parser<A[]>

  • sep2: <A>(s: Parser<unknown>, a: Parser<A>) => Parser<A[]>

  • seq: <T extends Parser<unknown>[]>(...as: T) => Parser<{ [K in keyof T]: Parsed<T[K]>; }>

  • sorrounded: <A>(lhs: Parser<unknown>, rhs: Parser<unknown>, a: Parser<A>) => Parser<A>

    Returns a parser sorrounded by lhs and rhs.

  • sorrounded1: <A>(s: Parser<unknown>, a: Parser<A>) => Parser<A>

    Returns a parser sorrounded by s at the beginning and at the end.

  • star: <A>(a: Parser<A>, min?: number) => Parser<A[]>

    Returns parser matching at least min (default 0) times a parser.

  • times: <A>(n: number, a: Parser<A>) => Parser<A[]>

  • trim: <A>(a: Parser<A>) => Parser<A>

  • union: <T extends Parser<unknown>[]>(...as: T) => T[number]

  • utf8: (chars: string) => Parser<string>

    Returns parser matching one of provided chars.

  • whileChar: (chars: string, min?: number) => Parser<string>

    Matches any char listed in chars at least min (default 0) times.

  • ws0: Parser<string>

  • ws1: Parser<string>

License

MIT License

Copyright 2021 Mirek Rusin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Package Sidebar

Install

npm i @prelude/parser

Weekly Downloads

11,527

Version

7.1.0

License

MIT

Unpacked Size

1.61 MB

Total Files

855

Last publish

Collaborators

  • mirek