llvm.org GIT mirror llvm / 13a38c4
various cleanups, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129192 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
1 changed file(s) with 6 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
130130 }
131131
132132 // Paren value #0 is for the fully matched string. Any new parenthesized
133 // values add from their.
133 // values add from there.
134134 unsigned CurParen = 1;
135135
136136 // Otherwise, there is at least one regex piece. Build up the regex pattern
137137 // by escaping scary characters in fixed strings, building up one big regex.
138138 while (!PatternStr.empty()) {
139139 // RegEx matches.
140 if (PatternStr.size() >= 2 &&
141 PatternStr[0] == '{' && PatternStr[1] == '{') {
140 if (PatternStr.startswith("{{")) {
142141
143142 // Otherwise, this is the start of a regex match. Scan for the }}.
144143 size_t End = PatternStr.find("}}");
145144 if (End == StringRef::npos) {
146145 SM.PrintMessage(SMLoc::getFromPointer(PatternStr.data()),
147 "found start of regex string with no end '}}'", "error");
146 "found start of regex string with no end '}}'","error");
148147 return true;
149148 }
150149
151150 if (AddRegExToRegEx(PatternStr.substr(2, End-2), CurParen, SM))
152151 return true;
152
153153 PatternStr = PatternStr.substr(End+2);
154154 continue;
155155 }
159159 // second form is [[foo]] which is a reference to foo. The variable name
160160 // itself must be of the form "[a-zA-Z_][0-9a-zA-Z_]*", otherwise we reject
161161 // it. This is to catch some common errors.
162 if (PatternStr.size() >= 2 &&
163 PatternStr[0] == '[' && PatternStr[1] == '[') {
162 if (PatternStr.startswith("[[")) {
164163 // Verify that it is terminated properly.
165164 size_t End = PatternStr.find("]]");
166165 if (End == StringRef::npos) {
184183
185184 // Verify that the name is well formed.
186185 for (unsigned i = 0, e = Name.size(); i != e; ++i)
187 if (Name[i] != '_' &&
188 (Name[i] < 'a' || Name[i] > 'z') &&
189 (Name[i] < 'A' || Name[i] > 'Z') &&
190 (Name[i] < '0' || Name[i] > '9')) {
186 if (Name[i] != '_' && !isalnum(Name[i])) {
191187 SM.PrintMessage(SMLoc::getFromPointer(Name.data()+i),
192188 "invalid name in named regex", "error");
193189 return true;