Package parser contains the interface for using parsers for all supported Lojban dialects.



View Source
const SpaceChars = ".\t\n\r?!\x20"

SpaceChars is the string of all whitespace characters.


This section is empty.


func AddElidedTerminators

func AddElidedTerminators(n *peg.Node)

AddElidedTerminators sets the Text of an elided terminator node to the terminator name in all caps. This flags any functions removing empty Nodes to keep the elided terminator Node, as its Text is no longer empty.

func CollapseLists

func CollapseLists(n *peg.Node)

CollapseLists collapses chains of single-kid nodes.

func Locations

func Locations(text string, n *peg.Fail) map[*peg.Fail]Loc

Locations returns a mapping from nodes to their Locs.

func Parse

func Parse(dialect string, text string) (*peg.Node, error)

Parse parses text using a given Lojban dialect. On success, the parseTree is returned. On failure, both the word-level and the raw, morphological errors are returned.

func Register

func Register(d Dialect, makeParser func(string) Parser)

Register registers a dialect.

func RemoveMorphology

func RemoveMorphology(n *peg.Node)

RemoveMorphology removes all nodes beneath whole words.

func RemoveSpace

func RemoveSpace(n *peg.Node)

RemoveSpace removes whitespace-only nodes.


type Dialect

type Dialect struct {
	// Name is the name of the dialect.
	Name string

	// Version is the version of the dialect's grammar.
	Version string

	// Descr is a map from language codes
	// to text describing the dialect
	// in the corresponding language.
	Descr map[string]string

	// OfficialURL is the official URL for the parser's homepage.
	OfficialURL string

	// GrammarURL is the URL of the grammar file.
	GrammarURL string

A Dialect describes a dialect of the Lojban language.

func Dialects

func Dialects() []Dialect

Dialects returns all registered dialects in lexical order by name.

type Error

type Error struct {
	FilePath string
	Want     []string

A Error represents an error at some location in the input text.

func (Error) Error

func (err Error) Error() string

type Loc

type Loc struct {
	Byte   int
	Rune   int
	Line   int
	Column int

A Loc is a location in the input text.

func Location

func Location(text string, byte int) Loc

Location returns the Loc at the corresponding byte offset in the text.

type Parser

type Parser interface {
	// Parse parses the text and returns
	// the maximum error position seen during the parse
	// and whether the parse succeeded.
	Parse() (int, bool)

	// ErrorTree returns the parse error tree for a failed parse.
	// The tree contains all errors at or beyond minErrorPos.
	ErrorTree(minErrorPos int) *peg.Fail

	// ParseTree returns the parse tree for a successful parse.
	ParseTree() *peg.Node

Parser is a low-level interface to a Lojban parser.


Path Synopsis
alldialects Package alldialects can be imported to register all supported Lojban dialects.
camxes Package camxes is the camxes implementation of the official Lojban grammar.
camxes-beta Package camxes is the camxes implementation of the official Lojban grammar.
ilmentufa Package ilmentufa is the ilmentufa dialect of Lojban.
maftufa Package maftufa is the maftufa dialect of Lojban grammar.
zantufa Package zantufa is the zantufa dialect of Lojban.