Documentation ¶
Overview ¶
Package parse implements the VDL parser, converting source files into a parse tree. The ParseFile function is the main entry point.
Index ¶
- func ExtractExprPackagePaths(expr ConstExpr) []string
- func ExtractTypePackagePaths(typ Type) []string
- func InferPackageName(files []*File, errs *vdlutil.Errors) (pkgName string)
- func QuoteStripDoc(doc string) string
- type Config
- type ConstBinaryOp
- type ConstCompositeLit
- type ConstDef
- type ConstExpr
- type ConstIndexed
- type ConstLit
- type ConstNamed
- type ConstTypeConv
- type ConstTypeObject
- type ConstUnaryOp
- type ErrorDef
- type Field
- type File
- type Import
- type Interface
- type KVLit
- type LangFmt
- type Method
- type NamePos
- type Opts
- type Pos
- type StringPos
- type Type
- type TypeArray
- type TypeDef
- type TypeEnum
- type TypeList
- type TypeMap
- type TypeNamed
- type TypeOptional
- type TypeSet
- type TypeStruct
- type TypeUnion
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractExprPackagePaths ¶
ExtractExprPackagePaths returns any package paths that appear in named constants in expr. i.e. "a/b/c".Foo => "a/b/c".
func ExtractTypePackagePaths ¶
func InferPackageName ¶
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 ¶
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.
Types ¶
type Config ¶
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 ¶
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.
func (*Config) AddImports ¶
AddImports adds the path imports that don't already exist to c.
type ConstBinaryOp ¶
ConstBinaryOp represents all binary operations.
func (*ConstBinaryOp) Pos ¶
func (c *ConstBinaryOp) Pos() Pos
func (*ConstBinaryOp) String ¶
func (c *ConstBinaryOp) String() string
type ConstCompositeLit ¶
ConstCompositeLit represents composite literals in const expressions.
func (*ConstCompositeLit) Pos ¶
func (c *ConstCompositeLit) Pos() Pos
func (*ConstCompositeLit) String ¶
func (c *ConstCompositeLit) String() string
type ConstExpr ¶
ConstExpr is the interface for all nodes in an expression.
func ParseExprs ¶
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.
type ConstIndexed ¶
type ConstIndexed struct { Expr *ConstNamed IndexExpr ConstExpr P Pos }
ConstIndexed represents an index operation on a composite type.
func (*ConstIndexed) Pos ¶
func (c *ConstIndexed) Pos() Pos
func (*ConstIndexed) String ¶
func (c *ConstIndexed) String() string
type ConstLit ¶
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.
type ConstNamed ¶
ConstNamed represents named references to other consts.
func (*ConstNamed) Pos ¶
func (c *ConstNamed) Pos() Pos
func (*ConstNamed) String ¶
func (c *ConstNamed) String() string
type ConstTypeConv ¶
ConstTypeConv represents explicit type conversions.
func (*ConstTypeConv) Pos ¶
func (c *ConstTypeConv) Pos() Pos
func (*ConstTypeConv) String ¶
func (c *ConstTypeConv) String() string
type ConstTypeObject ¶
ConstTypeObject represents typeobject; a type used as a value.
func (*ConstTypeObject) Pos ¶
func (c *ConstTypeObject) Pos() Pos
func (*ConstTypeObject) String ¶
func (c *ConstTypeObject) String() string
type ConstUnaryOp ¶
ConstUnaryOp represents all unary operations.
func (*ConstUnaryOp) Pos ¶
func (c *ConstUnaryOp) Pos() Pos
func (*ConstUnaryOp) String ¶
func (c *ConstUnaryOp) String() string
type ErrorDef ¶
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.
type File ¶
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.
type Import ¶
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"
type Interface ¶
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.
type LangFmt ¶
type LangFmt struct { Lang StringPos // IETF language tag Fmt StringPos // i18n format string in the given language }
LangFmt represents a language / format string pair.
type Method ¶
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.
type NamePos ¶
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.
type Opts ¶
type Opts struct {
ImportsOnly bool // Only parse imports; skip everything else.
}
Opts specifies vdl parsing options.
type Pos ¶
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.
type Type ¶
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 TypeDef ¶
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.
type TypeNamed ¶
TypeNamed captures named references to other types. Both built-in primitives and user-defined named types use this representation.
type TypeOptional ¶
TypeOptional represents optional types.
func (*TypeOptional) Kind ¶
func (t *TypeOptional) Kind() string
func (*TypeOptional) Pos ¶
func (t *TypeOptional) Pos() Pos
func (*TypeOptional) String ¶
func (t *TypeOptional) String() string
type TypeStruct ¶
TypeStruct represents struct types.
func (*TypeStruct) Kind ¶
func (t *TypeStruct) Kind() string
func (*TypeStruct) Pos ¶
func (t *TypeStruct) Pos() Pos
func (*TypeStruct) String ¶
func (t *TypeStruct) String() string