ast

package
v0.0.0-...-d374ac5 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 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 PostRecursive

func PostRecursive(cb func(Node)) func(Node)

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)

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)

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)

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/PostRecursive helpers 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)

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)

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)

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)

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)

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)

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)

type Node

type Node interface {
	Info() (pos Pos, typ string, name string)
	// Clone makes a deep copy of the node.
	Clone() Node
	// contains filtered or unexported methods
}

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)

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)

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)

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)

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)

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)

Jump to

Keyboard shortcuts

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