Categorygithub.com/vito/go-parse
modulepackage
0.0.0-20160925004003-ca8122a7499f
Repository: https://github.com/vito/go-parse.git
Documentation: pkg.go.dev

# README

Go Parse

A Parsec-like library for Go.

Structure:

A Vessel is what carries around the input and any user-specified state, as well as internal state such as the position in the input. It should know how to return and set those 3 values, as well as Get from the input, and push/pop (which just adjusts the position).

A Parser takes a Vessel and returns an Output and whether or not the parse was successful.

Parsers can typically be combined in many ways. For example Symbol is just String followed by Whitespace, Many takes a Parser and repeatedly applies it, matching 0 or more times (thus, the parse is always successful), and Any takes any number of Parsers and tries them all in order until one succeeds.

Example:

func main() {
    in := new(StringVessel);
    in.SetInput(`< (>)(
<
)(  >)  < >
>

    >`);

    ltgt := Any(Symbol("<"), Symbol(">"));

    parser := Many(Any(ltgt, Parens(ltgt)));
    out, parsed := parser(in);

    fmt.Printf("Matched: %#v\n", parsed);
    fmt.Printf("Matches: %v\n", out);
    fmt.Printf("Vessel: %+v\n", in);
}

Output:

go-parse $ go parsec
Matched: true
Matches: [< > < > < > > >]
Vessel: &{state:<nil> input:< (>)(
<
)(  >)  < >
>

    > position:{Name: Line:0 Column:0 Offset:29}}

# Packages

No description provided by the author

# Functions

Match all parsers, returning the final result.
Go through the parsers until one matches.
Try matching begin, match, and then end.
Match all parsers, collecting their outputs into a vector.
No description provided by the author
No description provided by the author
No description provided by the author
Match a parser and skip whitespace.
Match a parser 0 or more times.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Lexeme parser for `match' wrapped in parens.
Token that satisfies a condition.
Match a parser seperated by another parser 0 or more times.
No description provided by the author
Match a string and pop the string's length from the input.
Match a string and consume any following whitespace.
No description provided by the author
Try a parse and revert the state and position if it fails.
Skip whitespace and comments.

# Structs

Position in the input.
Specifications for the parser.
Basic string vessel for parsing over a string input.

# Interfaces

Input type used by vessels.
Output of Parsers.
Any value can be a vessel's state.
Container of the input, position, and any user/parser state.

# Type aliases

A Parser is a function that takes a vessel and returns any matches (Output) and whether or not the match was valid.