aboutsummaryrefslogtreecommitdiff
path: root/rule_parser.go
diff options
context:
space:
mode:
authorFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-07-21 13:07:44 +0900
committerFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-07-21 13:07:44 +0900
commit4b3a7dd8c84856419bd5f5bdcb17939a14cc75e1 (patch)
tree43349479759ffccc7b89e209613cb4f1d039a840 /rule_parser.go
parentf92954f49fbbb834c835453a3e8de54a43cd16dc (diff)
downloadkati-4b3a7dd8c84856419bd5f5bdcb17939a14cc75e1.tar.gz
[go] fix colon_ws_in_file.mk
Diffstat (limited to 'rule_parser.go')
-rw-r--r--rule_parser.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/rule_parser.go b/rule_parser.go
index 3b03bab..5711310 100644
--- a/rule_parser.go
+++ b/rule_parser.go
@@ -77,15 +77,31 @@ func (r *rule) cmdpos() srcpos {
}
func isPatternRule(s []byte) (pattern, bool) {
- i := bytes.IndexByte(s, '%')
+ i := findLiteralChar(s, '%', 0)
if i < 0 {
return pattern{}, false
}
return pattern{prefix: string(s[:i]), suffix: string(s[i+1:])}, true
}
+func unescapeInput(s []byte) []byte {
+ // only "\ ", "\=" becoms " ", "=" respectively?
+ // other \-escape, such as "\:" keeps "\:".
+ for i := 0; i < len(s); i++ {
+ if s[i] != '\\' {
+ continue
+ }
+ if i+1 < len(s) && s[i+1] == ' ' || s[i+1] == '=' {
+ copy(s[i:], s[i+1:])
+ s = s[:len(s)-1]
+ }
+ }
+ return s
+}
+
func (r *rule) parseInputs(s []byte) {
ws := newWordScanner(s)
+ ws.esc = true
isOrderOnly := false
for ws.Scan() {
input := ws.Bytes()
@@ -93,6 +109,7 @@ func (r *rule) parseInputs(s []byte) {
isOrderOnly = true
continue
}
+ input = unescapeInput(input)
if isOrderOnly {
r.orderOnlyInputs = append(r.orderOnlyInputs, internBytes(input))
} else {
@@ -197,7 +214,7 @@ func (r *rule) parse(line []byte, assign *assignAST, rhs expr) (*assignAST, erro
r.cmds = append(r.cmds, string(rest[index+1:]))
rest = rest[:index-1]
}
- index = bytes.IndexByte(rest, ':')
+ index = findLiteralChar(rest, ':', 0)
if index < 0 {
r.parseInputs(rest)
return nil, nil