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.
const.go grammar.y.go parse.go result.go type.go
ExtractExprPackagePaths returns any package paths that appear in named constants in expr. i.e. "a/b/c".Foo => "a/b/c".
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.
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 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.
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.
AddImports adds the path imports that don't already exist to c.
HasImport returns true iff path exists in c.Imports.
ConstBinaryOp represents all binary operations.
func (c *ConstBinaryOp) Pos() Pos
func (c *ConstBinaryOp) String() string
ConstCompositeLit represents composite literals in const expressions.
func (c *ConstCompositeLit) Pos() Pos
func (c *ConstCompositeLit) String() string
ConstDef represents a user-defined named const.
ConstExpr is the interface for all nodes in an expression.
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 struct { Expr *ConstNamed IndexExpr ConstExpr P Pos }
ConstIndexed represents an index operation on a composite type.
func (c *ConstIndexed) Pos() Pos
func (c *ConstIndexed) String() string
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.
ConstNamed represents named references to other consts.
func (c *ConstNamed) Pos() Pos
func (c *ConstNamed) String() string
ConstTypeConv represents explicit type conversions.
func (c *ConstTypeConv) Pos() Pos
func (c *ConstTypeConv) String() string
ConstTypeObject represents typeobject; a type used as a value.
func (c *ConstTypeObject) Pos() Pos
func (c *ConstTypeObject) String() string
ConstUnaryOp represents all unary operations.
func (c *ConstUnaryOp) Pos() Pos
func (c *ConstUnaryOp) String() string
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.
Field represents fields in structs as well as method arguments.
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.
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.
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"
LocalName returns the name used locally within the File to refer to the imported package.
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.
KVLit represents a key/value literal in composite literals.
type LangFmt struct { Lang StringPos // IETF language tag Fmt StringPos // i18n format string in the given language }
LangFmt represents a language / format string pair.
Pos returns the position of the LangFmt.
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 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.
Opts specifies vdl parsing options.
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.
Returns true iff this Pos has been initialized. The zero Pos is invalid.
StringPos holds a string and a Pos.
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.
TypeArray represents array types.
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.
TypeEnum represents enum types.
TypeList represents list types.
TypeMap represents map types.
TypeNamed captures named references to other types. Both built-in primitives and user-defined named types use this representation.
TypeOptional represents optional types.
func (t *TypeOptional) Kind() string
func (t *TypeOptional) Pos() Pos
func (t *TypeOptional) String() string
TypeSet represents set types.
TypeStruct represents struct types.
func (t *TypeStruct) Kind() string
func (t *TypeStruct) Pos() Pos
func (t *TypeStruct) String() string
TypeUnion represents union types.
Package parse imports 9 packages (graph) and is imported by 7 packages. Updated 2021-01-28. Refresh now. Tools for package owners.