parcom

package module
v0.0.0-...-4598240 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Unlicense Imports: 2 Imported by: 2

README

parcom

GitHub Action Codecov License

Parser combinator library

License

The Unlicense

Documentation

Overview

Package parcom provides parser combinators to parse CFG or position-aware grammars.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is an parsing error.

func NewError

func NewError(m string, s *State) Error

NewError creates an error.

func (Error) Column

func (e Error) Column() int

Column returns a column number.

func (Error) Error

func (e Error) Error() string

func (Error) Line

func (e Error) Line() int

Line returns a line number.

type Parser

type Parser func() (interface{}, error)

Parser is a parser function.

type PositionalState

type PositionalState struct {
	State
	// contains filtered or unexported fields
}

PositionalState is a position-aware parser state.

func NewPositionalState

func NewPositionalState(s string) *PositionalState

NewPositionalState creates a parser state.

func (*PositionalState) Block

func (s *PositionalState) Block(p Parser) Parser

Block parses a block of a given parser.

func (*PositionalState) Block1

func (s *PositionalState) Block1(p Parser) Parser

Block1 is the same as Block but blocks must have at least one element.

func (*PositionalState) ExhaustiveBlock

func (s *PositionalState) ExhaustiveBlock(p Parser) Parser

ExhaustiveBlock parses a block of a given parser exhaustively.

func (*PositionalState) HeteroBlock

func (s *PositionalState) HeteroBlock(ps ...Parser) Parser

HeteroBlock creates a parser to parse something all in the same column.

func (*PositionalState) Indent

func (s *PositionalState) Indent(p Parser) Parser

Indent creates a parser which parses an indent before running a given parser. It is equivalent to a given parser and parses no indent if no position is saved beforehand.

func (*PositionalState) SameColumn

func (s *PositionalState) SameColumn(p Parser) Parser

SameColumn creates a parser which parses something in the same column.

func (*PositionalState) SameLine

func (s *PositionalState) SameLine(p Parser) Parser

SameLine creates a parser which parses something in the same line.

func (*PositionalState) SameLineOrIndent

func (s *PositionalState) SameLineOrIndent(p Parser) Parser

SameLineOrIndent creates a parser which parses something in the same line or indented.

func (*PositionalState) WithBlock

func (s *PositionalState) WithBlock(p, pp Parser) Parser

WithBlock creates a parser which parses a block of the second parsers prefixed by the first parser. Blocks must have at least one element.

func (*PositionalState) WithBlock1

func (s *PositionalState) WithBlock1(p, pp Parser) Parser

WithBlock1 creates a parser which parses a block of the second parsers prefixed by the first parser. Blocks must have at least one element.

func (*PositionalState) WithPosition

func (s *PositionalState) WithPosition(p Parser) Parser

WithPosition creates a parser saving a current position.

type State

type State struct {
	// contains filtered or unexported fields
}

State is a parser state.

func NewState

func NewState(s string) *State

NewState creates a parser state.

func (*State) And

func (s *State) And(ps ...Parser) Parser

And creates a parser which combines given parsers sequentially.

func (*State) App

func (s *State) App(f func(interface{}) (interface{}, error), p Parser) Parser

App creates a parser which applies a function to results of a given parser.

func (*State) Char

func (s *State) Char(r rune) Parser

Char creates a parser to parse a character.

func (*State) Chars

func (s *State) Chars(cs string) Parser

Chars creates a parser to parse one of given characters.

func (State) Column

func (s State) Column() int

Column returns a position in a current line.

func (*State) Exhaust

func (s *State) Exhaust(p Parser) Parser

Exhaust creates a parser which fails when a source string is not exhausted after running a given parser.

func (*State) ExhaustiveMany

func (s *State) ExhaustiveMany(p Parser) Parser

ExhaustiveMany creates a parser of more than or equal to 0 repetition of a given parser which continues parsing until a source is exhausted.

func (*State) Lazy

func (s *State) Lazy(f func() Parser) Parser

Lazy creates a parser which runs a parser created by a given constructor. This combinator is useful to define recursive parsers.

func (State) Line

func (s State) Line() int

Line returns a current line number.

func (*State) Many

func (s *State) Many(p Parser) Parser

Many creates a parser of more than or equal to 0 repetition of a given parser.

func (*State) Many1

func (s *State) Many1(p Parser) Parser

Many1 creates a parser of more than 0 repetition of a given parser.

func (*State) Maybe

func (s *State) Maybe(p Parser) Parser

Maybe creates a parser which runs a given parser or parses nothing when it fails.

func (*State) None

func (s *State) None() Parser

None creates a parser which parses nothing and succeeds always.

func (*State) NotChar

func (s *State) NotChar(r rune) Parser

NotChar creates a parser to parse a character which is not the one of an argument.

func (*State) NotChars

func (s *State) NotChars(str string) Parser

NotChars creates a parser to parse a character not in a given string.

func (*State) Or

func (s *State) Or(ps ...Parser) Parser

Or creates a selectional parser from given parsers.

func (*State) Prefix

func (s *State) Prefix(p, q Parser) Parser

Prefix creates a parser with 2 parsers which returns the second one's result.

func (*State) Str

func (s *State) Str(str string) Parser

Str creates a parser to parse a string.

func (*State) Stringify

func (s *State) Stringify(p Parser) Parser

Stringify creates a parser which returns a string converted from a result of a given parser. The result of a given parser must be a rune, a string or a sequence of them in []interface{}.

func (*State) Suffix

func (s *State) Suffix(p, q Parser) Parser

Suffix creates a parser with 2 parsers which returns the first one's result.

func (State) Void

func (State) Void(p Parser) Parser

Void creates a parser whose result is always nil but parses something from a given parser.

func (*State) Wrap

func (s *State) Wrap(l, m, r Parser) Parser

Wrap wraps a parser with parsers which parse something before and after. Resulting parsers' parsing results are ones of the middle parsers.

Jump to

Keyboard shortcuts

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