v1.0.0 Latest Latest

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

Go to latest
Published: Nov 24, 2015 License: Apache-2.0 Imports: 3 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Input

type Input interface {
	End(rollback bool)

	Get(int) (string, error)
	Next() (rune, error)

	Position() Position

type Output

type Output interface{}

Output of Parsers

type Parser

type Parser func(*State) (Output, bool, error)

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

func All

func All(parsers ...Parser) Parser

Match all parsers, returning the final result. If one fails, it stops. NOTE: Consumes input on failure. Wrap calls in Try(...) to avoid.

func Any

func Any(parsers ...Parser) Parser

Go through the parsers until one matches.

func Between

func Between(begin Parser, end Parser, match Parser) Parser

Try matching begin, match, and then end.

func Collect

func Collect(parsers ...Parser) Parser

Match all parsers, collecting their outputs into a vector. If one parser fails, the whole thing fails. NOTE: Consumes input on failure. Wrap calls in Try(...) to avoid.

func Ident

func Ident() Parser

func Identifier

func Identifier() Parser

func InComment

func InComment() Parser

func Lexeme

func Lexeme(match Parser) Parser

Match a parser and skip whitespace

func Many

func Many(match Parser) Parser

Match a parser 0 or more times.

func Many1

func Many1(match Parser) Parser

Match a parser 1 or more times.

func MultiLineComment

func MultiLineComment() Parser

func NoneOf

func NoneOf(cs string) Parser

func OneLineComment

func OneLineComment() Parser

func OneOf

func OneOf(cs string) Parser

func Parens

func Parens(match Parser) Parser

Lexeme parser for `match' wrapped in parens.

func Satisfy

func Satisfy(check func(c rune) bool) Parser

Token that satisfies a condition.

func SepBy

func SepBy(delim Parser, match Parser) Parser

Match a parser seperated by another parser 0 or more times. Trailing delimeters are valid.

func Skip

func Skip(match Parser) Parser

func String

func String(str string) Parser

Match a string and pop the string's length from the input. NOTE: Consumes input on failure. Wrap calls in Try(...) to avoid.

func Symbol

func Symbol(str string) Parser

Match a string and consume any following whitespace.

func Token

func Token() Parser

func Try

func Try(match Parser) Parser

Try a parse and revert the state and position if it fails.

func Whitespace

func Whitespace() Parser

Skip whitespace and comments

type Position

type Position struct {
	Name   string
	Line   int
	Column int
	Offset int

type Spec

type Spec struct {
	CommentStart   string
	CommentEnd     string
	CommentLine    Parser
	NestedComments bool
	IdentStart     Parser
	IdentLetter    Parser
	ReservedNames  []string

Specifications for the parser

type State

type State struct {
	Spec  Spec
	Input Input

type StringInput

type StringInput struct {
	// contains filtered or unexported fields

Basic string Input for parsing over a string input.

func NewStringInput

func NewStringInput(s string) *StringInput

func (*StringInput) Begin

func (s *StringInput) Begin()

func (*StringInput) End

func (s *StringInput) End(rollback bool)

func (*StringInput) Get

func (s *StringInput) Get(i int) (string, error)

func (*StringInput) Next

func (s *StringInput) Next() (rune, error)

func (*StringInput) Pop

func (s *StringInput) Pop(i int)

func (*StringInput) Position

func (s *StringInput) Position() Position

Jump to

Keyboard shortcuts

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