ast

package
v0.0.0-...-a099a93 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2019 License: Apache-2.0 Imports: 12 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 FormatInt

func FormatInt(v uint64, format IntFmt) string

func FormatWriter

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

func LoggingHandler

func LoggingHandler(pos Pos, msg string)

func Recursive

func Recursive(cb func(Node)) func(Node)

func SerializeNode

func SerializeNode(n Node) string

Types

type Call

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

func (*Call) Clone

func (n *Call) Clone() Node

func (*Call) Info

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

func (*Call) Walk

func (n *Call) Walk(cb func(Node))

type Comment

type Comment struct {
	Pos  Pos
	Text string
}

func (*Comment) Clone

func (n *Comment) Clone() Node

func (*Comment) Info

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

func (*Comment) Walk

func (n *Comment) Walk(cb func(Node))

type Define

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

func (*Define) Clone

func (n *Define) Clone() Node

func (*Define) Info

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

func (*Define) Walk

func (n *Define) Walk(cb func(Node))

type Description

type Description struct {
	Nodes []Node
}

Description contains top-level nodes of a parsed sys 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

func (*Description) Clone

func (desc *Description) Clone() *Description

func (*Description) Filter

func (desc *Description) Filter(predicate func(Node) bool) *Description

func (*Description) Walk

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

Walk calls callback cb for every top-level node in description. Note: it's not recursive. Use Recursive helper for recursive walk.

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) Clone

func (n *Field) Clone() Node

func (*Field) Info

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

func (*Field) Walk

func (n *Field) Walk(cb func(Node))

type Ident

type Ident struct {
	Pos  Pos
	Name string
}

func (*Ident) Clone

func (n *Ident) Clone() Node

func (*Ident) Info

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

func (*Ident) Walk

func (n *Ident) Walk(cb func(Node))

type Incdir

type Incdir struct {
	Pos Pos
	Dir *String
}

func (*Incdir) Clone

func (n *Incdir) Clone() Node

func (*Incdir) Info

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

func (*Incdir) Walk

func (n *Incdir) Walk(cb func(Node))

type Include

type Include struct {
	Pos  Pos
	File *String
}

func (*Include) Clone

func (n *Include) Clone() Node

func (*Include) Info

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

func (*Include) Walk

func (n *Include) Walk(cb func(Node))

type Int

type Int struct {
	Pos Pos
	// Only one of Value, Ident, CExpr is filled.
	Value    uint64
	ValueFmt IntFmt
	Ident    string
	CExpr    string
}

func (*Int) Clone

func (n *Int) Clone() Node

func (*Int) Info

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

func (*Int) Walk

func (n *Int) Walk(cb func(Node))

type IntFlags

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

func (*IntFlags) Clone

func (n *IntFlags) Clone() Node

func (*IntFlags) Info

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

func (*IntFlags) Walk

func (n *IntFlags) Walk(cb func(Node))

type IntFmt

type IntFmt int
const (
	IntFmtDec IntFmt = iota
	IntFmtNeg
	IntFmtHex
	IntFmtChar
)

type NewLine

type NewLine struct {
	Pos Pos
}

func (*NewLine) Clone

func (n *NewLine) Clone() Node

func (*NewLine) Info

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

func (*NewLine) Walk

func (n *NewLine) Walk(cb func(Node))

type Node

type Node interface {
	Info() (pos Pos, typ string, name string)
	// Clone makes a deep copy of the node.
	Clone() Node
	// Walk calls callback cb for all child nodes of this node.
	// Note: it's not recursive. Use Recursive helper for recursive walk.
	Walk(cb func(Node))
}

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) Clone

func (n *Resource) Clone() Node

func (*Resource) Info

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

func (*Resource) Walk

func (n *Resource) Walk(cb func(Node))

type StrFlags

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

func (*StrFlags) Clone

func (n *StrFlags) Clone() Node

func (*StrFlags) Info

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

func (*StrFlags) Walk

func (n *StrFlags) Walk(cb func(Node))

type String

type String struct {
	Pos   Pos
	Value string
}

func (*String) Clone

func (n *String) Clone() Node

func (*String) Info

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

func (*String) Walk

func (n *String) Walk(cb func(Node))

type Struct

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

func (*Struct) Clone

func (n *Struct) Clone() Node

func (*Struct) Info

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

func (*Struct) Walk

func (n *Struct) Walk(cb func(Node))

type Type

type Type struct {
	Pos Pos
	// Only one of Value, Ident, String is filled.
	Value     uint64
	ValueFmt  IntFmt
	Ident     string
	String    string
	HasString bool
	// Parts after COLON (for ranges and bitfields).
	Colon []*Type
	// Sub-types in [].
	Args []*Type
}

func (*Type) Clone

func (n *Type) Clone() Node

func (*Type) Info

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

func (*Type) Walk

func (n *Type) Walk(cb func(Node))

type TypeDef

type TypeDef struct {
	Pos  Pos
	Name *Ident
	// Non-template type aliases have only Type filled.
	// Templates have Args and either Type or Struct filled.
	Args   []*Ident
	Type   *Type
	Struct *Struct
}

func (*TypeDef) Clone

func (n *TypeDef) Clone() Node

func (*TypeDef) Info

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

func (*TypeDef) Walk

func (n *TypeDef) Walk(cb func(Node))

Jump to

Keyboard shortcuts

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