v.io: v.io/x/ref/lib/vdl/parse Index | Files

package parse

import "v.io/x/ref/lib/vdl/parse"

Package parse implements the VDL parser, converting source files into a parse tree. The ParseFile function is the main entry point.

Index

Package Files

const.go grammar.y.go parse.go result.go type.go

func ExtractExprPackagePaths Uses

func ExtractExprPackagePaths(expr ConstExpr) []string

ExtractExprPackagePaths returns any package paths that appear in named constants in expr. i.e. "a/b/c".Foo => "a/b/c".

func ExtractTypePackagePaths Uses

func ExtractTypePackagePaths(typ Type) []string

func InferPackageName Uses

func InferPackageName(files []*File, errs *vdlutil.Errors) (pkgName string)

InferPackageName returns the package name from a group of files. Every file must specify the same package name, otherwise an error is reported in errs.

func QuoteStripDoc Uses

func QuoteStripDoc(doc string) string

QuoteStripDoc takes a Doc string, which includes comment markers /**/ and double-slash, and returns a raw-quoted string.

TODO(toddw): This should remove comment markers. This is non-trivial, since we should handle removing leading whitespace "rectangles", and might want to retain inline /**/ or adjacent /**/ on the same line. For now we just leave them in the output.

type Config Uses

type Config struct {
    FileName  string      // Config file name, e.g. "a/b/foo.config"
    Doc       string      // Top-level config file documentation
    ConfigDef NamePos     // Name, position and docs of the "config" clause
    Imports   []*Import   // Imports listed in this file.
    Config    ConstExpr   // Const expression exported from this config.
    ConstDefs []*ConstDef // Consts defined in this file.
}

Config represents a parsed config file. Config files use a similar syntax as vdl files, with similar concepts.

func ParseConfig Uses

func ParseConfig(fileName string, src io.Reader, opts Opts, errs *vdlutil.Errors) *Config

ParseConfig takes a file name, the contents of the config file src, and the accumulated errors, and parses the config into a parse.Config containing the parse tree. Returns nil if any errors are encountered, with errs containing more information. Otherwise returns the parsed Config. nolint:golint // API change required.

func (*Config) AddImports Uses

func (c *Config) AddImports(path ...string)

AddImports adds the path imports that don't already exist to c.

func (*Config) HasImport Uses

func (c *Config) HasImport(path string) bool

HasImport returns true iff path exists in c.Imports.

type ConstBinaryOp Uses

type ConstBinaryOp struct {
    Op    string
    Lexpr ConstExpr
    Rexpr ConstExpr
    P     Pos
}

ConstBinaryOp represents all binary operations.

func (*ConstBinaryOp) Pos Uses

func (c *ConstBinaryOp) Pos() Pos

func (*ConstBinaryOp) String Uses

func (c *ConstBinaryOp) String() string

type ConstCompositeLit Uses

type ConstCompositeLit struct {
    Type   Type
    KVList []KVLit
    P      Pos
}

ConstCompositeLit represents composite literals in const expressions.

func (*ConstCompositeLit) Pos Uses

func (c *ConstCompositeLit) Pos() Pos

func (*ConstCompositeLit) String Uses

func (c *ConstCompositeLit) String() string

type ConstDef Uses

type ConstDef struct {
    NamePos
    Expr ConstExpr
}

ConstDef represents a user-defined named const.

func (*ConstDef) String Uses

func (c *ConstDef) String() string

type ConstExpr Uses

type ConstExpr interface {
    String() string
    Pos() Pos
}

ConstExpr is the interface for all nodes in an expression.

func ParseExprs Uses

func ParseExprs(data string, errs *vdlutil.Errors) []ConstExpr

ParseExprs parses data into a slice of parsed const expressions. The input data is specified in VDL syntax, with commas separating multiple expressions. There must be at least one expression specified in data. Errors are returned in errs. nolint:golint // API change required.

type ConstIndexed Uses

type ConstIndexed struct {
    Expr      *ConstNamed
    IndexExpr ConstExpr
    P         Pos
}

ConstIndexed represents an index operation on a composite type.

func (*ConstIndexed) Pos Uses

func (c *ConstIndexed) Pos() Pos

func (*ConstIndexed) String Uses

func (c *ConstIndexed) String() string

type ConstLit Uses

type ConstLit struct {
    Lit interface{}
    P   Pos
}

ConstLit represents scalar literals in const expressions. The supported types for Lit are:

string     - Represents all string constants.
*big.Int   - Represents all integer constants.
*big.Rat   - Represents all rational constants.

func (*ConstLit) Pos Uses

func (c *ConstLit) Pos() Pos

func (*ConstLit) String Uses

func (c *ConstLit) String() string

type ConstNamed Uses

type ConstNamed struct {
    Name string
    P    Pos
}

ConstNamed represents named references to other consts.

func (*ConstNamed) Pos Uses

func (c *ConstNamed) Pos() Pos

func (*ConstNamed) String Uses

func (c *ConstNamed) String() string

type ConstTypeConv Uses

type ConstTypeConv struct {
    Type Type
    Expr ConstExpr
    P    Pos
}

ConstTypeConv represents explicit type conversions.

func (*ConstTypeConv) Pos Uses

func (c *ConstTypeConv) Pos() Pos

func (*ConstTypeConv) String Uses

func (c *ConstTypeConv) String() string

type ConstTypeObject Uses

type ConstTypeObject struct {
    Type Type
    P    Pos
}

ConstTypeObject represents typeobject; a type used as a value.

func (*ConstTypeObject) Pos Uses

func (c *ConstTypeObject) Pos() Pos

func (*ConstTypeObject) String Uses

func (c *ConstTypeObject) String() string

type ConstUnaryOp Uses

type ConstUnaryOp struct {
    Op   string
    Expr ConstExpr
    P    Pos
}

ConstUnaryOp represents all unary operations.

func (*ConstUnaryOp) Pos Uses

func (c *ConstUnaryOp) Pos() Pos

func (*ConstUnaryOp) String Uses

func (c *ConstUnaryOp) String() string

type ErrorDef Uses

type ErrorDef struct {
    NamePos             // error name, pos and doc
    Params  []*Field    // list of positional parameters
    Actions []StringPos // list of action code identifiers
    Formats []LangFmt   // list of language / format pairs
}

ErrorDef represents an error definition.

func (*ErrorDef) String Uses

func (x *ErrorDef) String() string

type Field Uses

type Field struct {
    NamePos      // field name, pos and doc
    Type    Type // field type, never nil
}

Field represents fields in structs as well as method arguments.

func (*Field) String Uses

func (x *Field) String() string

type File Uses

type File struct {
    BaseName   string       // Base name of the vdl file, e.g. "foo.vdl"
    Doc        string       // Top-level file documentation
    PackageDef NamePos      // Name, position and docs of the "package" clause
    Imports    []*Import    // Imports listed in this file
    ErrorDefs  []*ErrorDef  // Errors defined in this file
    TypeDefs   []*TypeDef   // Types defined in this file
    ConstDefs  []*ConstDef  // Consts defined in this file
    Interfaces []*Interface // Interfaces defined in this file
}

File represents a parsed vdl file.

func ParseFile Uses

func ParseFile(fileName string, src io.Reader, opts Opts, errs *vdlutil.Errors) *File

ParseFile takes a file name, the contents of the vdl file src, and the accumulated errors, and parses the vdl into a parse.File containing the parse tree. Returns nil if any errors are encountered, with errs containing more information. Otherwise returns the parsed File. nolint:golint // API change required.

func (*File) String Uses

func (x *File) String() string

type Import Uses

type Import struct {
    NamePos        // e.g. foo (from above), or typically empty
    Path    string // e.g. "some/package/path" (from above)
}

Import represents an import definition, which is used to import other packages into an vdl file. An example of the syntax in the vdl file:

import foo "some/package/path"

func (*Import) LocalName Uses

func (i *Import) LocalName() string

LocalName returns the name used locally within the File to refer to the imported package.

func (*Import) String Uses

func (i *Import) String() string

type Interface Uses

type Interface struct {
    NamePos            // interface name, pos and doc
    Embeds  []*NamePos // names of embedded interfaces
    Methods []*Method  // list of methods
}

Interface represents a set of embedded interfaces and methods.

func (*Interface) String Uses

func (x *Interface) String() string

type KVLit Uses

type KVLit struct {
    Key   ConstExpr
    Value ConstExpr
}

KVLit represents a key/value literal in composite literals.

type LangFmt Uses

type LangFmt struct {
    Lang StringPos // IETF language tag
    Fmt  StringPos // i18n format string in the given language
}

LangFmt represents a language / format string pair.

func (LangFmt) Pos Uses

func (x LangFmt) Pos() Pos

Pos returns the position of the LangFmt.

type Method Uses

type Method struct {
    NamePos               // method name, pos and doc
    InArgs    []*Field    // list of positional in-args
    OutArgs   []*Field    // list of positional out-args
    InStream  Type        // in-stream type, may be nil
    OutStream Type        // out-stream type, may be nil
    Tags      []ConstExpr // list of method tags
}

Method represents a method in an interface.

func (*Method) String Uses

func (x *Method) String() string

type NamePos Uses

type NamePos struct {
    Name      string
    Pos       Pos    // position of first character in name
    Doc       string // docs that occur before the item
    DocSuffix string // docs that occur on the same line after the item
}

NamePos represents a name, its associated position and documentation.

func (*NamePos) String Uses

func (x *NamePos) String() string

type Opts Uses

type Opts struct {
    ImportsOnly bool // Only parse imports; skip everything else.
}

Opts specifies vdl parsing options.

type Pos Uses

type Pos struct {
    Line int // Line number, starting at 1
    Col  int // Column number (character count), starting at 1
}

Pos captures positional information during parsing.

func (Pos) IsValid Uses

func (p Pos) IsValid() bool

Returns true iff this Pos has been initialized. The zero Pos is invalid.

func (Pos) String Uses

func (p Pos) String() string

type StringPos Uses

type StringPos struct {
    String string
    Pos    Pos
}

StringPos holds a string and a Pos.

type Type Uses

type Type interface {
    // String returns a human-readable description of the type.
    String() string
    // Kind returns a short human-readable string describing the kind of type.
    Kind() string
    // Pos returns the position of the first character in the type.
    Pos() Pos
}

Type is an interface representing symbolic occurrences of types in VDL files.

type TypeArray Uses

type TypeArray struct {
    Len  int
    Elem Type
    P    Pos
}

TypeArray represents array types.

func (*TypeArray) Kind Uses

func (t *TypeArray) Kind() string

func (*TypeArray) Pos Uses

func (t *TypeArray) Pos() Pos

func (*TypeArray) String Uses

func (t *TypeArray) String() string

type TypeDef Uses

type TypeDef struct {
    NamePos      // name assigned by the user, pos and doc
    Type    Type // the underlying type of the type definition.
}

TypeDef represents a user-defined named type.

func (*TypeDef) String Uses

func (t *TypeDef) String() string

type TypeEnum Uses

type TypeEnum struct {
    Labels []NamePos
    P      Pos
}

TypeEnum represents enum types.

func (*TypeEnum) Kind Uses

func (t *TypeEnum) Kind() string

func (*TypeEnum) Pos Uses

func (t *TypeEnum) Pos() Pos

func (*TypeEnum) String Uses

func (t *TypeEnum) String() string

type TypeList Uses

type TypeList struct {
    Elem Type
    P    Pos
}

TypeList represents list types.

func (*TypeList) Kind Uses

func (t *TypeList) Kind() string

func (*TypeList) Pos Uses

func (t *TypeList) Pos() Pos

func (*TypeList) String Uses

func (t *TypeList) String() string

type TypeMap Uses

type TypeMap struct {
    Key  Type
    Elem Type
    P    Pos
}

TypeMap represents map types.

func (*TypeMap) Kind Uses

func (t *TypeMap) Kind() string

func (*TypeMap) Pos Uses

func (t *TypeMap) Pos() Pos

func (*TypeMap) String Uses

func (t *TypeMap) String() string

type TypeNamed Uses

type TypeNamed struct {
    Name string
    P    Pos
}

TypeNamed captures named references to other types. Both built-in primitives and user-defined named types use this representation.

func (*TypeNamed) Kind Uses

func (t *TypeNamed) Kind() string

func (*TypeNamed) Pos Uses

func (t *TypeNamed) Pos() Pos

func (*TypeNamed) String Uses

func (t *TypeNamed) String() string

type TypeOptional Uses

type TypeOptional struct {
    Base Type
    P    Pos
}

TypeOptional represents optional types.

func (*TypeOptional) Kind Uses

func (t *TypeOptional) Kind() string

func (*TypeOptional) Pos Uses

func (t *TypeOptional) Pos() Pos

func (*TypeOptional) String Uses

func (t *TypeOptional) String() string

type TypeSet Uses

type TypeSet struct {
    Key Type
    P   Pos
}

TypeSet represents set types.

func (*TypeSet) Kind Uses

func (t *TypeSet) Kind() string

func (*TypeSet) Pos Uses

func (t *TypeSet) Pos() Pos

func (*TypeSet) String Uses

func (t *TypeSet) String() string

type TypeStruct Uses

type TypeStruct struct {
    Fields []*Field
    P      Pos
}

TypeStruct represents struct types.

func (*TypeStruct) Kind Uses

func (t *TypeStruct) Kind() string

func (*TypeStruct) Pos Uses

func (t *TypeStruct) Pos() Pos

func (*TypeStruct) String Uses

func (t *TypeStruct) String() string

type TypeUnion Uses

type TypeUnion struct {
    Fields []*Field
    P      Pos
}

TypeUnion represents union types.

func (*TypeUnion) Kind Uses

func (t *TypeUnion) Kind() string

func (*TypeUnion) Pos Uses

func (t *TypeUnion) Pos() Pos

func (*TypeUnion) String Uses

func (t *TypeUnion) String() string

Package parse imports 9 packages (graph) and is imported by 7 packages. Updated 2020-10-22. Refresh now. Tools for package owners.