public LexerToken(LexerTokenKindEnum kind, BoostVariant value) : this() { Kind = kind; if (value != null && !value.IsEmpty) { Value.SetValue(value); } }
public LexerToken(LexerTokenKindEnum kind) : this(kind, BoostVariant.Empty) { }
private void DetermineWhen(ref LexerToken tok, ref DateSpecifier specifier) { Date today = TimesCommon.Current.CurrentDate; specifier = specifier ?? new DateSpecifier(); switch (tok.Kind) { case LexerTokenKindEnum.TOK_DATE: specifier = tok.Value.GetValue <DateSpecifier>(); break; case LexerTokenKindEnum.TOK_INT: { int amount = tok.Value.GetValue <int>(); int adjust = 0; tok = Lexer.PeekToken(); LexerTokenKindEnum kind = tok.Kind; switch (kind) { case LexerTokenKindEnum.TOK_YEAR: case LexerTokenKindEnum.TOK_YEARS: case LexerTokenKindEnum.TOK_QUARTER: case LexerTokenKindEnum.TOK_QUARTERS: case LexerTokenKindEnum.TOK_MONTH: case LexerTokenKindEnum.TOK_MONTHS: case LexerTokenKindEnum.TOK_WEEK: case LexerTokenKindEnum.TOK_WEEKS: case LexerTokenKindEnum.TOK_DAY: case LexerTokenKindEnum.TOK_DAYS: Lexer.NextToken(); tok = Lexer.NextToken(); switch (tok.Kind) { case LexerTokenKindEnum.TOK_AGO: adjust = -1; break; case LexerTokenKindEnum.TOK_HENCE: adjust = 1; break; default: tok.Unexpected(); break; } break; default: break; } Date when = today; switch (kind) { case LexerTokenKindEnum.TOK_YEAR: case LexerTokenKindEnum.TOK_YEARS: when = when.AddYears(amount * adjust); break; case LexerTokenKindEnum.TOK_QUARTER: case LexerTokenKindEnum.TOK_QUARTERS: when = when.AddMonths(amount * 3 * adjust); break; case LexerTokenKindEnum.TOK_MONTH: case LexerTokenKindEnum.TOK_MONTHS: when = when.AddMonths(amount * adjust); break; case LexerTokenKindEnum.TOK_WEEK: case LexerTokenKindEnum.TOK_WEEKS: when = when.AddDays(amount * 7 * adjust); break; case LexerTokenKindEnum.TOK_DAY: case LexerTokenKindEnum.TOK_DAYS: when = when.AddDays(amount * adjust); break; default: if (amount > 31) { specifier.Year = amount; } else { specifier.Day = amount; } break; } if (adjust != 0) { specifier = new DateSpecifier(when); } break; } case LexerTokenKindEnum.TOK_THIS: case LexerTokenKindEnum.TOK_NEXT: case LexerTokenKindEnum.TOK_LAST: { int adjust = 0; if (tok.Kind == LexerTokenKindEnum.TOK_NEXT) { adjust = 1; } else if (tok.Kind == LexerTokenKindEnum.TOK_LAST) { adjust = -1; } tok = Lexer.NextToken(); switch (tok.Kind) { case LexerTokenKindEnum.TOK_A_MONTH: { Date temp = new Date(today.Year, tok.Value.GetValue <int>(), 1); temp = temp.AddYears(adjust); specifier = new DateSpecifier(temp.Year, (MonthEnum)temp.Month); break; } case LexerTokenKindEnum.TOK_A_WDAY: { Date temp = DateDuration.FindNearest(today, SkipQuantumEnum.WEEKS); while (temp.DayOfWeek != tok.Value.GetValue <DayOfWeek>()) { temp = temp.AddDays(1); } temp = temp.AddDays(7 * adjust); specifier = new DateSpecifier(temp); break; } case LexerTokenKindEnum.TOK_YEAR: { Date temp = today; temp = temp.AddYears(adjust); specifier = new DateSpecifier(temp.Year); break; } case LexerTokenKindEnum.TOK_QUARTER: { Date baseDate = DateDuration.FindNearest(today, SkipQuantumEnum.QUARTERS); Date temp = default(Date); if (adjust < 0) { temp = baseDate.AddMonths(3 * adjust); } else if (adjust == 0) { temp = baseDate.AddMonths(3); } else if (adjust > 0) { baseDate = baseDate.AddMonths(3 * adjust); temp = baseDate.AddMonths(3 * adjust); } specifier = new DateSpecifier(adjust < 0 ? temp : baseDate); break; } case LexerTokenKindEnum.TOK_WEEK: { Date baseDate = DateDuration.FindNearest(today, SkipQuantumEnum.WEEKS); Date temp = default(Date); if (adjust < 0) { temp = baseDate.AddDays(7 * adjust); } else if (adjust == 0) { temp = baseDate.AddDays(7); } else if (adjust > 0) { baseDate = baseDate.AddDays(7 * adjust); temp = baseDate.AddDays(7 * adjust); } specifier = new DateSpecifier(adjust < 0 ? temp : baseDate); break; } case LexerTokenKindEnum.TOK_DAY: { Date temp = today; temp = temp.AddDays(adjust); specifier = new DateSpecifier(temp); break; } case LexerTokenKindEnum.TOK_MONTH: default: { Date temp = today; temp = temp.AddMonths(adjust); specifier = new DateSpecifier(temp.Year, (MonthEnum)temp.Month); break; } } break; } case LexerTokenKindEnum.TOK_A_MONTH: specifier.Month = tok.Value.GetValue <MonthEnum>(); tok = Lexer.PeekToken(); switch (tok.Kind) { case LexerTokenKindEnum.TOK_INT: specifier.Year = tok.Value.GetValue <int>(); break; case LexerTokenKindEnum.END_REACHED: break; default: break; } break; case LexerTokenKindEnum.TOK_A_WDAY: specifier.WDay = tok.Value.GetValue <DayOfWeek>(); break; case LexerTokenKindEnum.TOK_TODAY: specifier = new DateSpecifier(today); break; case LexerTokenKindEnum.TOK_TOMORROW: specifier = new DateSpecifier(today.AddDays(1)); break; case LexerTokenKindEnum.TOK_YESTERDAY: specifier = new DateSpecifier(today.AddDays(-1)); break; default: tok.Unexpected(); break; } }