grammar

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package grammar imlements the grammar parser for the BadWolf query language. The parser is impemented as a reusable recursive decent parser for a left LL(k) left factorized grammar. BQL is an LL(1) grammar however the parser is designed to be reusable and help separate the grammar from the parsing mechanics to improve maintainablity and flexibility of grammar changes by keeping those the code separation clearly delineated.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clause

type Clause struct {
	Elements         []Element
	ProcessStart     semantic.ClauseHook
	ProcessEnd       semantic.ClauseHook
	ProcessedElement semantic.ElementHook
}

Clause contains on clause of the derivation rule.

type Element

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

Element are the main components that define a derivation rule.

func NewSymbol

func NewSymbol(s semantic.Symbol) Element

NewSymbol creates a new element from a symbol.

func NewTokenType

func NewTokenType(t lexer.TokenType) Element

NewTokenType creates a new element from a token.

func (Element) Symbol

func (e Element) Symbol() semantic.Symbol

Symbol returns the symbol box for the given element.

func (Element) Token

func (e Element) Token() lexer.TokenType

Token returns the value of the token box for the given element.

type Grammar

type Grammar map[semantic.Symbol][]*Clause

Grammar contains the left factory LLk grammar to be parsed. All provided grammars *must* have the "START" symbol to initialte the parsing of input text.

func BQL

func BQL() *Grammar

BQL LL1 grammar.

func SemanticBQL

func SemanticBQL() *Grammar

SemanticBQL contains the BQL grammar with hooks injected.

type LLk

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

LLk provide the basic lookahead mechanisms required to implement a recursive descent LLk parser.

func NewLLk

func NewLLk(input string, k int) *LLk

NewLLk creates a LLk structure for the given string to parse and the indicated k lookahead.

func (*LLk) CanAccept

func (l *LLk) CanAccept(tt lexer.TokenType) bool

CanAccept returns true if the provided token matches the current on being processed, false otherwise.

func (*LLk) Consume

func (l *LLk) Consume(tt lexer.TokenType) bool

Consume will consue the current token and move to the next one if it matches the provided token, false otherwise.

func (*LLk) Current

func (l *LLk) Current() *lexer.Token

Current returns the current token being processed.

func (*LLk) Peek

func (l *LLk) Peek(k int) (*lexer.Token, error)

Peek returns the token for the k look ahead. It will return nil and failed fail with an error if the provided k is bigger than the declared look ahead on creation.

type Parser

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

Parser implements a LLk recursive decend parser for left factorized grammars.

func NewParser

func NewParser(grammar *Grammar) (*Parser, error)

NewParser creates a new recursive decend parser for a left factorized grammar.

func (*Parser) Parse

func (p *Parser) Parse(llk *LLk, st *semantic.Statement) error

Parse attempts to run the parser for the given input.

Jump to

Keyboard shortcuts

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