ast

package
v0.0.0-...-4e6bda9 Latest Latest
Warning

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

Go to latest
Published: May 20, 2018 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ast parses and formats sys files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(desc *Description) []byte

func FormatWriter

func FormatWriter(w io.Writer, desc *Description)

func LoggingHandler

func LoggingHandler(pos Pos, msg string)

func Walk

func Walk(desc *Description, cb func(n Node))

Walk calls callback cb for every node in AST.

func WalkNode

func WalkNode(n0 Node, cb func(n Node))

Types

type Call

type Call struct {
	Pos      Pos
	Name     *Ident
	CallName string
	NR       uint64
	Args     []*Field
	Ret      *Type
}

func (*Call) Info

func (n *Call) Info() (Pos, string, string)

type Comment

type Comment struct {
	Pos  Pos
	Text string
}

func (*Comment) Info

func (n *Comment) Info() (Pos, string, string)

type Define

type Define struct {
	Pos   Pos
	Name  *Ident
	Value *Int
}

func (*Define) Info

func (n *Define) Info() (Pos, string, string)

type Description

type Description struct {
	Nodes []Node
}

Description contains top-level nodes of a parsed sys description.

func Clone

func Clone(desc *Description) *Description

func Parse

func Parse(data []byte, filename string, errorHandler ErrorHandler) *Description

Parse parses sys description into AST and returns top-level nodes. If any errors are encountered, returns nil.

func ParseGlob

func ParseGlob(glob string, errorHandler ErrorHandler) *Description

type ErrorHandler

type ErrorHandler func(pos Pos, msg string)

type ErrorMatcher

type ErrorMatcher struct {
	Data []byte
	// contains filtered or unexported fields
}

func NewErrorMatcher

func NewErrorMatcher(t *testing.T, file string) *ErrorMatcher

func (*ErrorMatcher) Check

func (em *ErrorMatcher) Check(t *testing.T)

func (*ErrorMatcher) Count

func (em *ErrorMatcher) Count() int

func (*ErrorMatcher) DumpErrors

func (em *ErrorMatcher) DumpErrors(t *testing.T)

func (*ErrorMatcher) ErrorHandler

func (em *ErrorMatcher) ErrorHandler(pos Pos, msg string)

type Field

type Field struct {
	Pos      Pos
	Name     *Ident
	Type     *Type
	NewBlock bool // separated from previous fields by a new line
	Comments []*Comment
}

func (*Field) Info

func (n *Field) Info() (Pos, string, string)

type Ident

type Ident struct {
	Pos  Pos
	Name string
}

func (*Ident) Info

func (n *Ident) Info() (Pos, string, string)

type Incdir

type Incdir struct {
	Pos Pos
	Dir *String
}

func (*Incdir) Info

func (n *Incdir) Info() (Pos, string, string)

type Include

type Include struct {
	Pos  Pos
	File *String
}

func (*Include) Info

func (n *Include) Info() (Pos, string, string)

type Int

type Int struct {
	Pos Pos
	// Only one of Value, Ident, CExpr is filled.
	Value    uint64
	ValueHex bool // says if value was in hex (for formatting)
	Ident    string
	CExpr    string
}

func (*Int) Info

func (n *Int) Info() (Pos, string, string)

type IntFlags

type IntFlags struct {
	Pos    Pos
	Name   *Ident
	Values []*Int
}

func (*IntFlags) Info

func (n *IntFlags) Info() (Pos, string, string)

type NewLine

type NewLine struct {
	Pos Pos
}

func (*NewLine) Info

func (n *NewLine) Info() (Pos, string, string)

type Node

type Node interface {
	Info() (pos Pos, typ string, name string)
}

Node is AST node interface.

type Pos

type Pos struct {
	File string
	Off  int // byte offset, starting at 0
	Line int // line number, starting at 1
	Col  int // column number, starting at 1 (byte count)
}

Pos represents source info for AST nodes.

func (Pos) String

func (pos Pos) String() string

type Resource

type Resource struct {
	Pos    Pos
	Name   *Ident
	Base   *Type
	Values []*Int
}

func (*Resource) Info

func (n *Resource) Info() (Pos, string, string)

type StrFlags

type StrFlags struct {
	Pos    Pos
	Name   *Ident
	Values []*String
}

func (*StrFlags) Info

func (n *StrFlags) Info() (Pos, string, string)

type String

type String struct {
	Pos   Pos
	Value string
}

func (*String) Info

func (n *String) Info() (Pos, string, string)

type Struct

type Struct struct {
	Pos      Pos
	Name     *Ident
	Fields   []*Field
	Attrs    []*Ident
	Comments []*Comment
	IsUnion  bool
}

func (*Struct) Info

func (n *Struct) Info() (Pos, string, string)

type Type

type Type struct {
	Pos Pos
	// Only one of Value, Ident, String is filled.
	Value    uint64
	ValueHex bool
	Ident    string
	String   string
	// Part after COLON (for ranges and bitfields).
	HasColon  bool
	Pos2      Pos
	Value2    uint64
	Value2Hex bool
	Ident2    string
	Args      []*Type
}

func (*Type) Info

func (n *Type) Info() (Pos, string, string)

Jump to

Keyboard shortcuts

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