This commit is contained in:
xdrm-brackets 2018-11-12 12:08:54 +01:00
parent 194b5647ee
commit 14f68cbf8e
4 changed files with 29 additions and 6 deletions

View File

@ -8,10 +8,21 @@ import (
"strings"
)
// ErrNullReceiver is raised when a null receiver is provided
var ErrNullReceiver = fmt.Errorf("receiver must not be null")
// ErrInvalidReceiver is raised when an invalid receiver is provided
var ErrInvalidReceiver = fmt.Errorf("receiver must be compatible with *[]*Line")
// ErrUnexpectedSectionClose is raised when reading a section close '}' without an
// open section
var ErrUnexpectedSectionClose = fmt.Errorf("unexpected section close")
// ErrUnclosedSection is raised when there is unclosed sections reaching the end
// of the file
var ErrUnclosedSection = fmt.Errorf("unclosed section")
// ErrInvalidSyntax is raised when a line cannot be understood
var ErrInvalidSyntax = fmt.Errorf("invalid syntax")
// decoder implements parser.Decoder
@ -62,7 +73,7 @@ func (d *decoder) Decode(v interface{}) error {
// 3. get indentation
var firstChar int
for firstChar = 0; in_array(" \t", notrim[firstChar]); firstChar++ {
for firstChar = 0; inArray(" \t", notrim[firstChar]); firstChar++ {
}
l.Indent = notrim[0:firstChar]
@ -154,7 +165,7 @@ func (d *decoder) Decode(v interface{}) error {
}
func in_array(haystack string, needle byte) bool {
func inArray(haystack string, needle byte) bool {
for i, l := 0, len(haystack); i < l; i++ {
if haystack[i] == needle {
return true

View File

@ -137,7 +137,7 @@ func TestNestedSections(t *testing.T) {
}
// check each component individually
var current []*Line = receiver.Lines
current := receiver.Lines
for s, sec := range test.SectionChain {
// check that section exists in <current>

View File

@ -4,18 +4,27 @@ import (
"io"
)
// LineType enumerates available line types
type LineType byte
const (
NONE LineType = iota
COMMENT // # comment
COLONCOMMENT // ; comment
// NONE is the default line type (invalid syntax)
NONE LineType = iota
// COMMENT represents a #-comment
COMMENT
// COLONCOMMENT represents a ;-comment
COLONCOMMENT
// ASSIGNMENT line
ASSIGNMENT
// INCLUDE line
INCLUDE
// SECTION start
SECTION
// SECTIONEND line '}'
SECTIONEND
)
// Line represents a meaningful line
type Line struct {
// Number of the line in the input file
Number int
@ -42,6 +51,7 @@ type nginx struct {
Lines []*Line
}
// NewDecoder implements parser.T
func (n *nginx) NewDecoder(r io.Reader) *decoder {
return &decoder{reader: r}
}

View File

@ -4,8 +4,10 @@ import (
osexec "os/exec"
)
// Default executor
type Default struct{}
// Command implements exec.Executor
func (d *Default) Command(cmd string, args ...string) Command {
return osexec.Command(cmd, args...)
}