parser

package
v0.0.0-...-7323597 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2017 License: MIT Imports: 3 Imported by: 3

Documentation

Overview

A Parser library and framework. Left-recursive rules are not supported without special care.

A Parser library and framework. Left-recursive rules are not supported without special care.

Index

Constants

View Source
const (
	RESULT_OK = uint(iota)
	RESULT_FAILED
	RESULT_FAILED_CUT
)
View Source
const (
	LEFT_RECURSIVE = uint(1 << iota)
)
View Source
const NONE = uint(0)

Variables

This section is empty.

Functions

func FastMatch

func FastMatch(t *scanlist.Element, rs ...rune) (bool, *scanlist.Element)

func Match

func Match(f func(rune) string, t *scanlist.Element, rs ...rune) (error, *scanlist.Element)

func Textify

func Textify(r rune) string

Textifies a Token-ID

Types

type ArrayPlus

type ArrayPlus struct {
	Inner ParseRule
}

(Inner)+ => ARRAY

func (ArrayPlus) Parse

func (s ArrayPlus) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

type ArraySeq

type ArraySeq []ParseRule

func (ArraySeq) Parse

func (s ArraySeq) Parse(p *Parser, tokens *scanlist.Element, left interface{}) (opr ParserResult)

type ArrayStar

type ArrayStar struct {
	Inner ParseRule
}

(Inner)* => ARRAY

func (ArrayStar) Parse

func (s ArrayStar) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

type Delegate

type Delegate string

func (Delegate) Parse

func (d Delegate) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

type LPlus

type LPlus struct {
	Inner ParseRule
}

(Inner)+

func (LPlus) Parse

func (s LPlus) Parse(p *Parser, tokens *scanlist.Element, left interface{}) (opr ParserResult)

type LSeq

type LSeq []ParseRule

func (LSeq) Parse

func (s LSeq) Parse(p *Parser, tokens *scanlist.Element, left interface{}) (opr ParserResult)

type LStar

type LStar struct {
	Inner ParseRule
}

(Inner)*

func (LStar) Parse

func (s LStar) Parse(p *Parser, tokens *scanlist.Element, left interface{}) (opr ParserResult)

type OR

type OR []ParseRule

func (OR) Parse

func (o OR) Parse(p *Parser, tokens *scanlist.Element, left interface{}) (opr ParserResult)

type ParseRule

type ParseRule interface {
	// left = the Left-Recursive element, if any, else nil
	Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult
}

type Parser

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

func (*Parser) Construct

func (p *Parser) Construct() *Parser

func (*Parser) Define

func (p *Parser) Define(n string, left bool, r ParseRule)

func (*Parser) DefineBefore

func (p *Parser) DefineBefore(n string, left bool, r ParseRule)

Like .Define(), but does prepend rather than append!

func (*Parser) Match

func (p *Parser) Match(n string, tokens *scanlist.Element) ParserResult

func (*Parser) MatchNoLeftRecursion

func (p *Parser) MatchNoLeftRecursion(n string, tokens *scanlist.Element) ParserResult

func (*Parser) String

func (p *Parser) String() string

func (*Parser) TouchRule

func (p *Parser) TouchRule(n string)

type ParserResult

type ParserResult struct {
	Result uint
	Next   *scanlist.Element // next token on success; undefined on failure.
	Data   interface{}       // The syntax-tree on success; the error message on failure.
	Pos    scanner.Position
}

func ResultFail

func ResultFail(reason string, pos scanner.Position) ParserResult

func ResultFailCut

func ResultFailCut(reason string, pos scanner.Position) ParserResult

func ResultOk

func ResultOk(next *scanlist.Element, tree interface{}) ParserResult

func (ParserResult) Cut

func (p ParserResult) Cut() bool

p.Result==RESULT_FAILED_CUT

func (ParserResult) Ok

func (p ParserResult) Ok() bool

p.Result==RESULT_OK

func (ParserResult) TryNextRule

func (p ParserResult) TryNextRule() bool

p.Result==RESULT_FAILED

type Pfunc

type Pfunc func(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

func (Pfunc) Parse

func (pf Pfunc) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

type RequireText

type RequireText struct {
	Text string
}

func (RequireText) Parse

func (r RequireText) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

type Required

type Required struct {
	Token rune
	Errf  func(rune) string
}

func (Required) Parse

func (r Required) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

type TokenFinishedOptional

type TokenFinishedOptional struct {
	Inner ParseRule
	Token rune
}

(Token|Inner Token) => Inner or nil

func (TokenFinishedOptional) Parse

func (s TokenFinishedOptional) Parse(p *Parser, tokens *scanlist.Element, left interface{}) ParserResult

Jump to

Keyboard shortcuts

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