diff options
author | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-06-26 21:32:50 +0900 |
---|---|---|
committer | Fumitoshi Ukai <fumitoshi.ukai@gmail.com> | 2015-06-26 23:08:01 +0900 |
commit | 65c7233c02ba0f62c38ef96e4bb59dcb273542e9 (patch) | |
tree | 9b02ced4ebe2cff26d772431cc81b4ecfc2425ff /rule_parser.go | |
parent | 480bca50f6f74c0021910540a6e0ea8761eb5f61 (diff) | |
download | kati-65c7233c02ba0f62c38ef96e4bb59dcb273542e9.tar.gz |
fix panic based error reporting
Diffstat (limited to 'rule_parser.go')
-rw-r--r-- | rule_parser.go | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/rule_parser.go b/rule_parser.go index b7908ac..d71bd0f 100644 --- a/rule_parser.go +++ b/rule_parser.go @@ -56,6 +56,7 @@ func (p pattern) subst(repl, str string) string { } type rule struct { + srcpos outputs []string inputs []string orderOnlyInputs []string @@ -63,11 +64,13 @@ type rule struct { isDoubleColon bool isSuffixRule bool cmds []string - filename string - lineno int cmdLineno int } +func (r *rule) cmdpos() srcpos { + return srcpos{filename: r.filename, lineno: r.cmdLineno} +} + func isPatternRule(s []byte) (pattern, bool) { i := bytes.IndexByte(s, '%') if i < 0 { @@ -93,10 +96,10 @@ func (r *rule) parseInputs(s []byte) { } } -func (r *rule) parseVar(s []byte) *assignAST { +func (r *rule) parseVar(s []byte) (*assignAST, error) { eq := bytes.IndexByte(s, '=') if eq <= 0 { - return nil + return nil, nil } rhs := trimLeftSpaceBytes(s[eq+1:]) var lhs []byte @@ -116,10 +119,12 @@ func (r *rule) parseVar(s []byte) *assignAST { lhs = trimSpaceBytes(s[:eq]) op = "=" } - assign := newAssignAST(nil, lhs, rhs, op) - assign.filename = r.filename - assign.lineno = r.lineno - return assign + assign, err := newAssignAST(nil, lhs, rhs, op) + if err != nil { + return nil, err + } + assign.srcpos = r.srcpos + return assign, nil } func (r *rule) parse(line []byte) (*assignAST, error) { @@ -153,7 +158,11 @@ func (r *rule) parse(line []byte) (*assignAST, error) { } rest := line[index:] - if assign := r.parseVar(rest); assign != nil { + assign, err := r.parseVar(rest) + if err != nil { + return nil, err + } + if assign != nil { return assign, nil } index = bytes.IndexByte(rest, ':') |