Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comment ¶
type Comment struct {
Target string
Value string
Default bool
// contains filtered or unexported fields
}
Comment node.
type Include ¶
type Include struct {
Value string
// contains filtered or unexported fields
}
Include node.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is a quick-n-dirty Makefile "parser", not really, just comments and a few directives, but you'll forgive me.
func (*Parser) Parse ¶
Parse the given input reader. TODO(bwplotka): Streaming version would be nice.
Example (WithComments) ¶
contents := `
include github.com/tj/foo
# Stuff here:
#
# :)
#
# Start the dev server.
start:
@gopherjs -m -v serve --http :3000 github.com/tj/docs/client
.PHONY: start
# Start the API server.
api:
@go run server/cmd/api/api.go
.PHONY: api
# Display dependency graph.
deps:
@godepgraph github.com/tj/docs/client | dot -Tsvg | browser
.PHONY: deps
# Display size of dependencies.
#
# - foo
# - bar
# - baz
#
size:
@gopherjs build client/*.go -m -o /tmp/out.js
@du -h /tmp/out.js
@gopher-count /tmp/out.js | sort -nr
.PHONY: size
.PHONY: dummy
# Just a comment.
# Just another comment.
dummy:
@ls
`
nodes, err := Parse(strings.NewReader(contents))
if err != nil {
panic(err)
}
for _, node := range nodes {
fmt.Printf("%#v\n", node)
}
Output: makefile.Include{node:makefile.node{lines:[]int{1}}, Value:"github.com/tj/foo"} makefile.Comment{node:makefile.node{lines:[]int{7}}, Target:"start", Value:"Stuff here:\n\n :)\n\nStart the dev server.", Default:false} makefile.Comment{node:makefile.node{lines:[]int{8, 11}}, Target:"api", Value:"Start the API server.", Default:false} makefile.Comment{node:makefile.node{lines:[]int{15}}, Target:"deps", Value:"Display dependency graph.", Default:false} makefile.Comment{node:makefile.node{lines:[]int{24}}, Target:"size", Value:"Display size of dependencies.\n\n- foo\n- bar\n- baz", Default:false} makefile.Comment{node:makefile.node{lines:[]int{32}}, Target:"dummy", Value:"Just a comment.\nJust another comment.", Default:false}
Example (WithoutComments) ¶
contents := `
include github.com/tj/foo
include github.com/tj/bar
include github.com/tj/something/here
start:
@gopherjs -m -v serve --http :3000 github.com/tj/docs/client
.PHONY: start
api:
@go run server/cmd/api/api.go
.PHONY: api
deps:
@godepgraph github.com/tj/docs/client | dot -Tsvg | browser
.PHONY: deps
`
nodes, err := Parse(strings.NewReader(contents))
if err != nil {
panic(err)
}
for _, node := range nodes {
fmt.Printf("%#v\n", node)
}
Output: makefile.Include{node:makefile.node{lines:[]int{1}}, Value:"github.com/tj/foo"} makefile.Include{node:makefile.node{lines:[]int{2}}, Value:"github.com/tj/bar"} makefile.Include{node:makefile.node{lines:[]int{3}}, Value:"github.com/tj/something/here"}
Click to show internal directories.
Click to hide internal directories.