parser

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package parser implements all the parser functionality for Makefiles. This is supposed to be a parser with a very small feature set that just supports what is needed to do linting and checking and not actual full Makefile parsing. And it's handrolled because apparently GNU Make doesn't have a grammar (see http://www.mail-archive.com/help-make@gnu.org/msg02778.html)

Package parser implements all the parser functionality for Makefiles this specific file holds the functionality for the scanner. The implementation is a thin wrapper around bufio.Scanner with some extra niceties to make parsing Makefiles easier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Makefile

type Makefile struct {
	FileName  string
	Rules     RuleList
	Variables VariableList
}

Makefile provides a data structure to describe a parsed Makefile

func Parse

func Parse(filepath string) (ret Makefile, err error)

Parse is the main function to parse a Makefile from a file path string to a Makefile struct. This function should be kept fairly small and ideally most of the heavy lifting will live in the specific parsing functions below that know how to deal with individual lines.

type MakefileScanner

type MakefileScanner struct {
	Scanner    *bufio.Scanner
	LineNumber int
	FileHandle *os.File
	Finished   bool
}

MakefileScanner is a wrapping struct around bufio.Scanner which provides extra functionality like the current line number

func NewMakefileScanner

func NewMakefileScanner(filepath string) (*MakefileScanner, error)

NewMakefileScanner returns a MakefileScanner struct for parsing a Makefile

func (*MakefileScanner) Close

func (s *MakefileScanner) Close()

Close closes all open handles the scanner has

func (*MakefileScanner) Scan

func (s *MakefileScanner) Scan() bool

Scan is a thin wrapper around the bufio.Scanner Scan() function

func (*MakefileScanner) Text

func (s *MakefileScanner) Text() string

Text is a thin wrapper around bufio.Scanner Text()

type Rule

type Rule struct {
	Target       string
	Dependencies []string
	Body         []string
	FileName     string
	LineNumber   int
}

Rule represents a Make rule

type RuleList

type RuleList []Rule

RuleList represents a list of rules

type Variable

type Variable struct {
	Name            string
	SimplyExpanded  bool
	Assignment      string
	SpecialVariable bool
	FileName        string
	LineNumber      int
}

Variable represents a Make variable

type VariableList

type VariableList []Variable

VariableList represents a list of variables

Jump to

Keyboard shortcuts

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