make

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 4 Imported by: 0

README

Go Make

Makefile parsing and utilities in Go

Usage

Reading

The make.Parser is the primary way to read Makefiles.

f := os.Open("Makefile")
p := make.NewParser(f, nil)

m, err := p.ParseFile()

fmt.Println(m.Rules)

The more primitive make.Scanner and make.ScanTokens used by make.Parser can be used individually.

Using make.ScanTokens with a bufio.Scanner

f := os.Open("Makefile")
s := bufio.NewScanner(f)
s.Split(make.ScanTokens)

for s.Scan() {
  s.Bytes() // The current token byte slice i.e. []byte(":=")
  s.Text() // The current token as a string i.e. ":="
}

Using make.Scanner

f := os.Open("Makefile")
s := make.NewScanner(f, nil)

for pos, tok, lit := s.Scan(); tok != token.EOF; {
  fmt.Println(pos) // The position of tok
  fmt.Println(tok) // The current token.Token i.e. token.SIMPLE_ASSIGN
  fmt.Println(lit) // Literal tokens as a string i.e. "identifier"
}

if err := s.Err(); err != nil {
  fmt.Println(err)
}
Writing

Use make.Fprint to write ast nodes.

var file *ast.File

err := make.Fprint(os.Stdout, file)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Fprint     = printer.Fprint
	NewParser  = parser.New
	NewScanner = scanner.New
	NewWriter  = writer.New
	ScanTokens = scanner.ScanTokens
)

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
ast
internal
Package token defines constants representing the lexical tokens of a Makefile.
Package token defines constants representing the lexical tokens of a Makefile.

Jump to

Keyboard shortcuts

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