parse

module
v0.0.0-...-40e84bd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2025 License: Apache-2.0

README

Parse

Parse is a functional parsing library written in Go. It enables the building of complex parsers from small, simple and (most importantly) unit testable functions that process the input.

The core of the library is a partial rewrite of Adrian Hesketh's library with reduced verbosity, bug fixes and then extended as required for Notedown.

Packages

  • core contains all the base parsers for parsing documents.
  • time contains all parsers related to time, dates and durations.
  • test contains helper functions for unit testing your own parsers.

The packages are designed to be composable via dot import. Dot imports are generally discouraged in Golang except in the case of reducing verbosity for DSL-like APIs which is typical here.


import (
    . "github.com/liamawhite/parse/core"
    // . "github.com/liamawhite/parse/time" any other packages you may need
)

var BlankLine = Times(2, NewLine) // \n\n

Implementing Your Own Parsers

To implement a parser implement the Parser[T] type alias, a function that takes an Input and returns (T, bool, error). Each parser should attempt to parse the Input and roll back if it is unable to find what it is looking for.

You can find examples in the time package. Full documentation is available here.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL