parser

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2018 License: Apache-2.0, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package parser implements a parser for yacc source files.

Note: Rule.Body element's type

int		Eg. 65 represents literal 'A'

string		Eg. "Start" represents rule component Start

*Action		Mid rule action or rule semantic action

Index

Constants

View Source
const (
	// ActionValueGo is used for a Go code fragment
	ActionValueGo = iota
	// ActionValueDlrDlr is used for $$.
	ActionValueDlrDlr
	// ActionValueDlrTagDlr is used for $<tag>$.
	ActionValueDlrTagDlr
	// ActionValueDlrNum is used for $num.
	ActionValueDlrNum
	// ActionValueDlrTagNum is used for $<tag>num.
	ActionValueDlrTagNum
)
View Source
const (
	COMMENT        = 57346
	C_IDENTIFIER   = 57347
	ERROR_VERBOSE  = 57348
	IDENTIFIER     = 57349
	LCURL          = 57350
	LEFT           = 57351
	MARK           = 57352
	NONASSOC       = 57353
	NUMBER         = 57354
	PREC           = 57355
	PRECEDENCE     = 57356
	RCURL          = 57357
	RIGHT          = 57358
	START          = 57359
	STRING_LITERAL = 57360
	TOKEN          = 57361
	TYPE           = 57362
	UNION          = 57363
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Values []*ActionValue // For backward compatibility.
	Token  *Token
	Token2 *Token
}

Action represents data reduced by production:

Action:
        '{' '}'

func (*Action) Pos

func (n *Action) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Action) String

func (n *Action) String() string

String implements fmt.Stringer.

type ActionValue

type ActionValue struct {
	Num  int       // The number in $num.
	Pos  token.Pos // Position of the start of the ActionValue.
	Src  string    // Source for this value.
	Tag  string    // The tag in $<tag>$ or $<tag>num.
	Type int       // One of ActionValue{Go,DlrDlr,DlrTagDlr,DlrNum,DlrTagNum} constants.
}

ActionValue is an item of Action.Value

type Definition

type Definition struct {
	Nlist        []*Name // For backward compatibility.
	Value        string
	Case         int
	NameList     *NameList
	ReservedWord *ReservedWord
	Tag          *Tag
	Token        *Token
	Token2       *Token
}

Definition represents data reduced by productions:

Definition:
        START IDENTIFIER
|       UNION                      // Case 1
|       LCURL RCURL                // Case 2
|       ReservedWord Tag NameList  // Case 3
|       ReservedWord Tag           // Case 4
|       ERROR_VERBOSE              // Case 5

func (*Definition) Pos

func (n *Definition) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Definition) String

func (n *Definition) String() string

String implements fmt.Stringer.

type DefinitionList

type DefinitionList struct {
	Definition     *Definition
	DefinitionList *DefinitionList
}

DefinitionList represents data reduced by productions:

DefinitionList:
        /* empty */
|       DefinitionList Definition  // Case 1

func (*DefinitionList) Pos

func (n *DefinitionList) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*DefinitionList) String

func (n *DefinitionList) String() string

String implements fmt.Stringer.

type LiteralStringOpt

type LiteralStringOpt struct {
	Token *Token
}

LiteralStringOpt represents data reduced by productions:

LiteralStringOpt:
        /* empty */
|       STRING_LITERAL  // Case 1

func (*LiteralStringOpt) Pos

func (n *LiteralStringOpt) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*LiteralStringOpt) String

func (n *LiteralStringOpt) String() string

String implements fmt.Stringer.

type Name

type Name struct {
	Identifier       interface{} // For backward compatibility.
	Number           int         // For backward compatibility.
	Case             int
	LiteralStringOpt *LiteralStringOpt
	Token            *Token
	Token2           *Token
}

Name represents data reduced by productions:

Name:
        IDENTIFIER LiteralStringOpt
|       IDENTIFIER NUMBER LiteralStringOpt  // Case 1

func (*Name) Pos

func (n *Name) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Name) String

func (n *Name) String() string

String implements fmt.Stringer.

type NameList

type NameList struct {
	Case     int
	Name     *Name
	NameList *NameList
	Token    *Token
}

NameList represents data reduced by productions:

NameList:
        Name
|       NameList Name      // Case 1
|       NameList ',' Name  // Case 2

func (*NameList) Pos

func (n *NameList) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*NameList) String

func (n *NameList) String() string

String implements fmt.Stringer.

type Node

type Node interface {
	Pos() token.Pos
}

Node represents an AST node.

type Precedence

type Precedence struct {
	Identifier interface{} // Name string or literal int.
	Action     *Action
	Case       int
	Precedence *Precedence
	Token      *Token
	Token2     *Token
}

Precedence represents data reduced by productions:

Precedence:
        /* empty */
|       PREC IDENTIFIER         // Case 1
|       PREC IDENTIFIER Action  // Case 2
|       Precedence ';'          // Case 3

func (*Precedence) Pos

func (n *Precedence) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Precedence) String

func (n *Precedence) String() string

String implements fmt.Stringer.

type ReservedWord

type ReservedWord struct {
	Case  int
	Token *Token
}

ReservedWord represents data reduced by productions:

ReservedWord:
        TOKEN
|       LEFT        // Case 1
|       RIGHT       // Case 2
|       NONASSOC    // Case 3
|       TYPE        // Case 4
|       PRECEDENCE  // Case 5

func (*ReservedWord) Pos

func (n *ReservedWord) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*ReservedWord) String

func (n *ReservedWord) String() string

String implements fmt.Stringer.

type Rule

type Rule struct {
	Body         []interface{} // For backward compatibility.
	Name         *Token
	Case         int
	Precedence   *Precedence
	RuleItemList *RuleItemList
	Token        *Token
}

Rule represents data reduced by productions:

Rule:
        C_IDENTIFIER RuleItemList Precedence
|       '|' RuleItemList Precedence           // Case 1

func (*Rule) Pos

func (n *Rule) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Rule) String

func (n *Rule) String() string

String implements fmt.Stringer.

type RuleItemList

type RuleItemList struct {
	Action       *Action
	Case         int
	RuleItemList *RuleItemList
	Token        *Token
}

RuleItemList represents data reduced by productions:

RuleItemList:
        /* empty */
|       RuleItemList IDENTIFIER      // Case 1
|       RuleItemList Action          // Case 2
|       RuleItemList STRING_LITERAL  // Case 3

func (*RuleItemList) Pos

func (n *RuleItemList) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*RuleItemList) String

func (n *RuleItemList) String() string

String implements fmt.Stringer.

type RuleList

type RuleList struct {
	Case         int
	Precedence   *Precedence
	Rule         *Rule
	RuleItemList *RuleItemList
	RuleList     *RuleList
	Token        *Token
}

RuleList represents data reduced by productions:

RuleList:
        C_IDENTIFIER RuleItemList Precedence
|       RuleList Rule                         // Case 1

func (*RuleList) Pos

func (n *RuleList) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*RuleList) String

func (n *RuleList) String() string

String implements fmt.Stringer.

type Specification

type Specification struct {
	Defs           []*Definition // For backward compatibility.
	Rules          []*Rule       // For backward compatibility.
	DefinitionList *DefinitionList
	RuleList       *RuleList
	Tail           *Tail
	Token          *Token
}

Specification represents data reduced by production:

Specification:
        DefinitionList "%%" RuleList Tail

func Parse

func Parse(fset *token.FileSet, fname string, src []byte) (s *Specification, err error)

Parse parses src as a single yacc source file fname and returns the corresponding Specification. If the source couldn't be read, the returned Specification is nil and the error indicates all of the specific failures.

func (*Specification) Pos

func (n *Specification) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Specification) String

func (n *Specification) String() string

String implements fmt.Stringer.

type Tag

type Tag struct {
	Token  *Token
	Token2 *Token
	Token3 *Token
}

Tag represents data reduced by productions:

Tag:
        /* empty */
|       '<' IDENTIFIER '>'  // Case 1

func (*Tag) Pos

func (n *Tag) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Tag) String

func (n *Tag) String() string

String implements fmt.Stringer.

type Tail

type Tail struct {
	Value string
	Token *Token
}

Tail represents data reduced by productions:

Tail:
        "%%"
|       /* empty */  // Case 1

func (*Tail) Pos

func (n *Tail) Pos() token.Pos

Pos reports the position of the first component of n or zero if it's empty.

func (*Tail) String

func (n *Tail) String() string

String implements fmt.Stringer.

type Token

type Token struct {
	Comments []string
	Val      string
	File     *token.File
	lex.Char
}

Token captures a lexem with position, value and comments, if any.

func (*Token) Pos

func (t *Token) Pos() token.Pos

Pos retruns the token.Pos for t.

func (*Token) Position

func (t *Token) Position() token.Position

Position returns the token.Position for t

func (*Token) String

func (t *Token) String() string

Strings implements fmt.Stringer.

Jump to

Keyboard shortcuts

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