ast

package
v0.0.0-...-cbd58c3 Latest Latest
Warning

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

Go to latest
Published: May 14, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Pos lexer.Position

	ArgumentList     *ArgumentList     `@@`
	QuotedArgument   *QuotedArgument   `| @@`
	UnquotedArgument *UnquotedArgument `| @@`
	BracketArgument  *BracketArgument  `| @@`
}

Argument is a union-production for each of the CMake argument kinds. See: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#command-arguments

func (*Argument) Eval

func (a *Argument) Eval(vars Bindings) []string

Eval returns a slice of argument values after resolving variable references from vars.

type ArgumentList

type ArgumentList struct {
	Values []Argument `"(" @@? ((( Space | Newline )+ @@? ) | @@ )* ")"`
}

ArgumentList is a parentheses-enclosed separated list of arguments. It broadly corresponds to the arguments and separated_argument productions from: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#command-invocations

func (*ArgumentList) Eval

func (a *ArgumentList) Eval(vars Bindings) []string

Eval uses the provided bindings to resolve any variable references and returns a slice corresponding to the argument values.

type Bindings

type Bindings interface {
	Get(string) string      // Returns the named CMake variable or the empty string.
	GetCache(string) string // Returns the named CMake variable from the cache.
	GetEnv(string) string   // Returns the named Environment variable.
}

Bindings provides the AST with variable bindings in the current scope. All interface functions are expected to return either the value currently bound to the provided name or an empty string.

type BracketArgument

type BracketArgument struct {
	Text string `@BracketContent`
}

BracketArgument is a [=*[<text>]=*]-enclosed argument corresponding to: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#bracket-argument

func (*BracketArgument) Eval

func (a *BracketArgument) Eval(vars Bindings) []string

Eval returns a slice of values for the text of the argument.

type CMakeFile

type CMakeFile struct {
	Commands []CommandInvocation `( ( Space | Newline )* @@ ( Space | Newline )* )*`
}

CMakeFile represents the root of a CMakeLists.txt AST and corresponds to: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#source-files

type CommandInvocation

type CommandInvocation struct {
	Pos lexer.Position

	Name      string       `Space* @Identifier  Space*`
	Arguments ArgumentList `@@`
}

CommandInvocation is a top-level CMake command. https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#command-invocations

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses CMake-style files following (most of) the grammar defined at https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html

func NewParser

func NewParser() *Parser

NewParser constructs a new parser for CMakeLists-style files.

func (*Parser) Parse

func (p *Parser) Parse(r io.Reader) (*CMakeFile, error)

Parse reads a CMakeLists.txt file from r and parses it into an AST.

func (*Parser) ParseBytes

func (p *Parser) ParseBytes(b []byte) (*CMakeFile, error)

ParseBytes reads a CMakeLists.txt file from byte slice b and parses it into an AST.

func (*Parser) ParseString

func (p *Parser) ParseString(s string) (*CMakeFile, error)

ParseString reads a CMakeLists.txt file from string s and parses it into an AST.

func (*Parser) String

func (p *Parser) String() string

String returns a string corresponding to the CMakeLists grammar.

type QuotedArgument

type QuotedArgument struct {
	Elements []QuotedElement `"\"" ( @@ )* "\""`
}

QuotedArgument is a simple quoted string, corresponding to: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#quoted-argument

func (*QuotedArgument) Eval

func (a *QuotedArgument) Eval(vars Bindings) []string

Eval returns a slice of argument values after resolving variable references from vars. Semi-colon delimited lists are not separated.

type QuotedElement

type QuotedElement struct {
	Ref  *VariableReference `@@`
	Text string             `| @( Quoted | EscapeSequence | VarClose )+`
}

QuotedElement is either a string of quoted text or a variable reference.

func (*QuotedElement) Eval

func (e *QuotedElement) Eval(vars Bindings) []string

Eval returns a slice of values after resolving variable references using vars.

type UnquotedArgument

type UnquotedArgument struct {
	Elements []UnquotedElement `@@ ( @@ )*`
}

UnquotedArgument is CMake's standed unquoted command argument: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#unquoted-argument Note: The unquoted_legacy production mentioned above is *not* supported.

func (*UnquotedArgument) Eval

func (a *UnquotedArgument) Eval(vars Bindings) []string

Eval returns a slice of argument values after resolving variable references from vars. Semi-colon delimited lists are separated.

type UnquotedElement

type UnquotedElement struct {
	Ref  *VariableReference `@@`
	Text string             `| @( Identifier | Unquoted | EscapeSequence | VarClose )+`
}

UnquotedElement is either a run of unquoted text or a variable reference.

func (*UnquotedElement) Eval

func (e *UnquotedElement) Eval(vars Bindings) []string

Eval returns a slice of values after evaluating escape sequences and splitting on semicolons.

type VarDomain

type VarDomain int

VarDomain represents one of CMake's variable scopes.

const (
	DomainDefault VarDomain = iota // The default (anonymous) domain.
	DomainCache                    // CACHE variable references.
	DomainEnv                      // ENV variable references.
	DomainMake                     // Make variables.
)

Constants defining the recognized valid variable domains.

func (*VarDomain) Capture

func (d *VarDomain) Capture(values []string) error

Capture translates a sequence of values into the appropriate variable domain.

func (VarDomain) String

func (d VarDomain) String() string

String implements fmt.Stringer for VarDomain and returns a user-readable string for the domain.

type VariableElement

type VariableElement struct {
	Text string             `@( Identifier | Unquoted | Quoted )?`
	Ref  *VariableReference `( @@ )?`
}

VariableElement is either a run of text corresponding the a variable name or a nested VariableReference.

func (*VariableElement) Eval

func (v *VariableElement) Eval(vars Bindings) []string

Eval recursively resolves variable references using vars and returns the result.

type VariableReference

type VariableReference struct {
	Pos lexer.Position

	Domain   VarDomain         `@VarOpen`
	Elements []VariableElement `@@ ( @@ )* "}"`
}

VariableReference is a possibly-nested CMake ${}-enclosed variable reference: https://cmake.org/cmake/help/v3.0/manual/cmake-language.7.html#variable-references In order to capture the nature of these, they are embedded in the grammar rather than being handled during evaluation.

func (*VariableReference) Eval

func (v *VariableReference) Eval(vars Bindings) []string

Eval recursively resolves variable references using vars and returns the result.

Jump to

Keyboard shortcuts

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