parser

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2019 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

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

Index

Constants

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

SpaceChars is the string of all whitespace characters.

Variables

This section is empty.

Functions

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.

Types

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 {
	Loc
	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.

Directories

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

Jump to

Keyboard shortcuts

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