aboutsummaryrefslogtreecommitdiff
path: root/rule.cc
diff options
context:
space:
mode:
authorShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-23 20:24:53 +0900
committerShinichiro Hamaji <shinichiro.hamaji@gmail.com>2015-06-23 20:27:40 +0900
commit2928f46a3097334af15d492eb0b355ed4c1a21e9 (patch)
treec43ca12324055c4d47561e7e059d4ae623263dfc /rule.cc
parent3c785c76ce9662c67c70fa7fe4532915799c16bd (diff)
[C++] Implement ; in rule
Diffstat (limited to 'rule.cc')
-rw-r--r--rule.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/rule.cc b/rule.cc
index d98a409..0bf87bc 100644
--- a/rule.cc
+++ b/rule.cc
@@ -59,7 +59,7 @@ Rule::Rule()
cmd_lineno(0) {
}
-void ParseRule(Loc& loc, StringPiece line, bool is_assign,
+void ParseRule(Loc& loc, StringPiece line, char term,
Rule** out_rule, RuleVarAssignment* rule_var) {
size_t index = line.find(':');
if (index == string::npos) {
@@ -90,12 +90,13 @@ void ParseRule(Loc& loc, StringPiece line, bool is_assign,
}
StringPiece rest = line.substr(index);
- size_t equal_index = rest.find('=');
- if (equal_index != string::npos || is_assign) {
- if (equal_index == string::npos)
- equal_index = rest.size();
+ size_t term_index = rest.find_first_of("=;");
+ if ((term_index != string::npos && rest[term_index] == '=') ||
+ (term_index == string::npos && term == '=')) {
+ if (term_index == string::npos)
+ term_index = rest.size();
rule_var->outputs.swap(outputs);
- ParseAssignStatement(rest, equal_index,
+ ParseAssignStatement(rest, term_index,
&rule_var->lhs, &rule_var->rhs, &rule_var->op);
*out_rule = NULL;
return;
@@ -110,6 +111,13 @@ void ParseRule(Loc& loc, StringPiece line, bool is_assign,
} else {
rule->outputs.swap(outputs);
}
+ if (term_index != string::npos && term != ';') {
+ CHECK(rest[term_index] == ';');
+ // TODO: Maybe better to avoid Intern here?
+ rule->cmds.push_back(
+ NewLiteral(Intern(TrimLeftSpace(rest.substr(term_index + 1)))));
+ rest = rest.substr(0, term_index);
+ }
index = rest.find(':');
if (index == string::npos) {