Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ScanRegex()

RegexNode System.Text.RegularExpressions.RegexParser.ScanRegex ( )
inlineprivate

Definition at line 244 of file RegexParser.cs.

245 {
246 char c = '@';
247 bool flag = false;
248 StartGroup(new RegexNode(28, _options, 0, -1));
249 while (CharsRight() > 0)
250 {
251 bool flag2 = flag;
252 flag = false;
253 ScanBlank();
254 int num = Textpos();
255 if (UseOptionX())
256 {
257 while (CharsRight() > 0 && (!IsStopperX(c = RightChar()) || (c == '{' && !IsTrueQuantifier())))
258 {
259 MoveRight();
260 }
261 }
262 else
263 {
264 while (CharsRight() > 0 && (!IsSpecial(c = RightChar()) || (c == '{' && !IsTrueQuantifier())))
265 {
266 MoveRight();
267 }
268 }
269 int num2 = Textpos();
270 ScanBlank();
271 if (CharsRight() == 0)
272 {
273 c = '!';
274 }
275 else if (IsSpecial(c = RightChar()))
276 {
277 flag = IsQuantifier(c);
278 MoveRight();
279 }
280 else
281 {
282 c = ' ';
283 }
284 if (num < num2)
285 {
286 int num3 = num2 - num - (flag ? 1 : 0);
287 flag2 = false;
288 if (num3 > 0)
289 {
291 }
292 if (flag)
293 {
294 AddUnitOne(CharAt(num2 - 1));
295 }
296 }
297 switch (c)
298 {
299 case '[':
300 AddUnitSet(ScanCharClass(UseOptionI(), scanOnly: false).ToStringClass());
301 goto IL_02cf;
302 case '(':
303 {
304 PushOptions();
305 RegexNode openGroup;
306 if ((openGroup = ScanGroupOpen()) == null)
307 {
309 continue;
310 }
311 PushGroup();
313 continue;
314 }
315 case '|':
316 AddAlternate();
317 continue;
318 case ')':
319 if (EmptyStack())
320 {
321 throw MakeException(RegexParseError.InsufficientOpeningParentheses, System.SR.InsufficientOpeningParentheses);
322 }
323 AddGroup();
324 PopGroup();
325 PopOptions();
326 if (Unit() == null)
327 {
328 continue;
329 }
330 goto IL_02cf;
331 case '\\':
332 if (CharsRight() == 0)
333 {
334 throw MakeException(RegexParseError.UnescapedEndingBackslash, System.SR.UnescapedEndingBackslash);
335 }
337 goto IL_02cf;
338 case '^':
339 AddUnitType(UseOptionM() ? 14 : 18);
340 goto IL_02cf;
341 case '$':
342 AddUnitType(UseOptionM() ? 15 : 20);
343 goto IL_02cf;
344 case '.':
345 if (UseOptionS())
346 {
347 AddUnitSet("\0\u0001\0\0");
348 }
349 else
350 {
351 AddUnitNotone('\n');
352 }
353 goto IL_02cf;
354 case '*':
355 case '+':
356 case '?':
357 case '{':
358 if (Unit() == null)
359 {
361 }
362 MoveLeft();
363 goto IL_02cf;
364 default:
366 case ' ':
367 continue;
368 case '!':
369 break;
370 IL_02cf:
371 ScanBlank();
372 if (CharsRight() == 0 || !(flag = IsTrueQuantifier()))
373 {
375 continue;
376 }
377 c = RightCharMoveRight();
378 while (Unit() != null)
379 {
380 int num4;
381 int num5;
382 if ((uint)c <= 43u)
383 {
384 if (c != '*')
385 {
386 if (c != '+')
387 {
388 goto IL_03cd;
389 }
390 num4 = 1;
391 num5 = int.MaxValue;
392 }
393 else
394 {
395 num4 = 0;
396 num5 = int.MaxValue;
397 }
398 }
399 else if (c != '?')
400 {
401 if (c != '{')
402 {
403 goto IL_03cd;
404 }
405 num = Textpos();
406 num5 = (num4 = ScanDecimal());
407 if (num < Textpos() && CharsRight() > 0 && RightChar() == ',')
408 {
409 MoveRight();
410 num5 = ((CharsRight() != 0 && RightChar() != '}') ? ScanDecimal() : int.MaxValue);
411 }
412 if (num == Textpos() || CharsRight() == 0 || RightCharMoveRight() != '}')
413 {
415 Textto(num - 1);
416 break;
417 }
418 }
419 else
420 {
421 num4 = 0;
422 num5 = 1;
423 }
424 ScanBlank();
425 bool lazy = false;
426 if (CharsRight() != 0 && RightChar() == '?')
427 {
428 MoveRight();
429 lazy = true;
430 }
431 if (num4 > num5)
432 {
433 throw MakeException(RegexParseError.ReversedQuantifierRange, System.SR.ReversedQuantifierRange);
434 }
436 continue;
437 IL_03cd:
439 }
440 continue;
441 }
442 break;
443 }
444 if (!EmptyStack())
445 {
446 throw MakeException(RegexParseError.InsufficientClosingParentheses, System.SR.InsufficientClosingParentheses);
447 }
448 AddGroup();
449 return Unit().FinalOptimize();
450 }
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string NestedQuantifiersNotParenthesized
Definition SR.cs:60
static string InsufficientOpeningParentheses
Definition SR.cs:86
static string InternalError_ScanRegex
Definition SR.cs:42
static string InsufficientClosingParentheses
Definition SR.cs:64
static string UnescapedEndingBackslash
Definition SR.cs:36
static string ReversedQuantifierRange
Definition SR.cs:38
Definition SR.cs:7
RegexParseException MakeException(RegexParseError error, string message)
RegexCharClass ScanCharClass(bool caseInsensitive, bool scanOnly)

References System.Text.RegularExpressions.RegexParser._options, System.Text.RegularExpressions.RegexParser.AddAlternate(), System.Text.RegularExpressions.RegexParser.AddConcatenate(), System.Text.RegularExpressions.RegexParser.AddGroup(), System.Text.RegularExpressions.RegexParser.AddUnitNode(), System.Text.RegularExpressions.RegexParser.AddUnitNotone(), System.Text.RegularExpressions.RegexParser.AddUnitOne(), System.Text.RegularExpressions.RegexParser.AddUnitSet(), System.Text.RegularExpressions.RegexParser.AddUnitType(), System.Text.RegularExpressions.RegexParser.CharAt(), System.Text.RegularExpressions.RegexParser.CharsRight(), System.Text.RegularExpressions.RegexParser.EmptyStack(), System.Text.RegularExpressions.RegexNode.FinalOptimize(), System.SR.Format(), System.SR.InsufficientClosingParentheses, System.SR.InsufficientOpeningParentheses, System.SR.InternalError_ScanRegex, System.Text.RegularExpressions.RegexParser.IsQuantifier(), System.Text.RegularExpressions.RegexParser.IsSpecial(), System.Text.RegularExpressions.RegexParser.IsStopperX(), System.Text.RegularExpressions.RegexParser.IsTrueQuantifier(), System.Text.RegularExpressions.RegexParser.MakeException(), System.Text.RegularExpressions.RegexParser.MoveLeft(), System.Text.RegularExpressions.RegexParser.MoveRight(), System.SR.NestedQuantifiersNotParenthesized, System.Text.RegularExpressions.RegexParser.PopGroup(), System.Text.RegularExpressions.RegexParser.PopKeepOptions(), System.Text.RegularExpressions.RegexParser.PopOptions(), System.Text.RegularExpressions.RegexParser.PushGroup(), System.Text.RegularExpressions.RegexParser.PushOptions(), System.SR.QuantifierAfterNothing, System.SR.ReversedQuantifierRange, System.Text.RegularExpressions.RegexParser.RightChar(), System.Text.RegularExpressions.RegexParser.RightCharMoveRight(), System.Text.RegularExpressions.RegexParser.ScanBackslash(), System.Text.RegularExpressions.RegexParser.ScanBlank(), System.Text.RegularExpressions.RegexParser.ScanCharClass(), System.Text.RegularExpressions.RegexParser.ScanDecimal(), System.Text.RegularExpressions.RegexParser.ScanGroupOpen(), System.Text.RegularExpressions.RegexParser.StartGroup(), System.Text.RegularExpressions.RegexParser.Textpos(), System.Text.RegularExpressions.RegexParser.Textto(), System.SR.UnescapedEndingBackslash, System.Text.RegularExpressions.RegexParser.Unit(), System.Text.RegularExpressions.RegexParser.UseOptionI(), System.Text.RegularExpressions.RegexParser.UseOptionM(), System.Text.RegularExpressions.RegexParser.UseOptionS(), and System.Text.RegularExpressions.RegexParser.UseOptionX().