public static INumerable BuildTimTim(string name, List <Argument> args) { if (args.Count != 2) { throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 time arguments."); } ITimeable itim1 = TimeableBuilder.Build(args[0].tokens); ITimeable itim2 = TimeableBuilder.Build(args[1].tokens); if (itim1.IsNull()) { throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as time."); } if (itim2.IsNull()) { throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as time."); } if (name.Equals("yearsbetween")) { return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Year)); } else if (name.Equals("monthsbetween")) { return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Month)); } else if (name.Equals("daysbetween")) { return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Day)); } else if (name.Equals("hoursbetween")) { return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Hour)); } else if (name.Equals("minutesbetween")) { return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Minute)); } else if (name.Equals("secondsbetween")) { return(new Func__TimeBetween(itim1, itim2, TimeVariableType.Second)); } throw new SyntaxErrorException("ERROR! Function " + name + " not identified."); }
public static INumerable BuildTim(string name, List <Argument> args) { if (args.Count != 1) { throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 time argument."); } ITimeable itim = TimeableBuilder.Build(args[0].tokens); if (itim.IsNull()) { throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as time."); } if (name.Equals("yearday") || name.Equals("dayofyear")) { return(new FuncYearday(itim)); } throw new SyntaxErrorException("ERROR! Function " + name + " not identified."); }
public static ICommand Build(List <Token> tokens) { TokenType type = tokens[0].GetTokenType(); string name = type.Equals(TokenType.Recreate) ? "recreate" : (type.Equals(TokenType.Remodify) ? "remodify" : "reaccess"); tokens.RemoveAt(0); if (tokens.Where(t => t.GetTokenType().Equals(TokenType.To)).Count() > 1) { throw new SyntaxErrorException("ERROR! In " + name + " command keyword 'to' occurs too many times."); } List <Token> part1 = new List <Token>(); List <Token> part2 = new List <Token>(); bool pastTo = false; foreach (Token tok in tokens) { if (tok.GetTokenType().Equals(TokenType.To)) { pastTo = true; } else { if (pastTo) { part2.Add(tok); } else { part1.Add(tok); } } } if (part2.Count == 0) { throw new SyntaxErrorException("ERROR! Command " + name + " is too short and do not contain all necessary information."); } ITimeable expression2 = TimeableBuilder.Build(part2); if (expression2.IsNull()) { throw new SyntaxErrorException("ERROR! Second part of command " + name + " cannot be read as time."); } if (part1.Count == 0) { return(BuildSimple(type, expression2)); } else { IListable expression1 = ListableBuilder.Build(part1); if (expression1.IsNull()) { throw new SyntaxErrorException("ERROR! First part of command " + name + " cannot be read as list."); } return(BuildComplex(type, expression1, expression2)); } }