Exemplo n.º 1
0
        public static IBoolable BuildStrStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 text arguments.");
            }

            IStringable istr1 = StringableBuilder.Build(args[0].tokens);
            IStringable istr2 = StringableBuilder.Build(args[1].tokens);

            if (istr1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (istr2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("existinside") || name.Equals("existsinside"))
            {
                return(new FuncExistinside(istr1, istr2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 2
0
        public static IBoolable BuildLisStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: one list and one text.");
            }

            IListable   ilis = ListableBuilder.Build(args[0].tokens);
            IStringable istr = StringableBuilder.Build(args[1].tokens);

            if (ilis.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as list.");
            }
            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("contain") || name.Equals("contains"))
            {
                return(new FuncContain(ilis, istr));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 3
0
        public static INumerable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("number"))
            {
                return(new FuncNumber(istr));
            }
            if (name.Equals("length"))
            {
                return(new FuncLength(istr));
            }
            if (name.Equals("year"))
            {
                return(new FuncYear(istr));
            }
            if (name.Equals("size"))
            {
                return(new FuncSize(istr));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 4
0
        public static ITimeable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("access"))
            {
                return(new FuncAccess(istr));
            }
            else if (name.Equals("creation"))
            {
                return(new FuncCreation(istr));
            }
            else if (name.Equals("modification"))
            {
                return(new FuncModification(istr));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 5
0
        public static ICommand Build(List <Token> tokens, bool forced)
        {
            TokenType type = tokens[0].GetTokenType();

            tokens.RemoveAt(0);

            if (tokens.Where(t => t.GetTokenType().Equals(TokenType.To)).Count() > 1)
            {
                throw new SyntaxErrorException("ERROR! In " + GetName(type) + " 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 " + GetName(type) + " is too short and do not contain all necessary information.");
            }

            IStringable expression2 = StringableBuilder.Build(part2);

            if (expression2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second part of command " + GetName(type) + " cannot be read as text.");
            }

            if (part1.Count == 0)
            {
                return(BuildSimple(type, expression2, forced));
            }
            else
            {
                IListable expression1 = ListableBuilder.Build(part1);
                if (expression1.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! First part of command " + GetName(type) + " cannot be read as list.");
                }
                return(BuildComplex(type, expression1, expression2, forced));
            }
        }
Exemplo n.º 6
0
        public static IStringable BuildStrStr(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: two texts.");
            }

            IStringable istr1 = StringableBuilder.Build(args[0].tokens);
            IStringable istr2 = StringableBuilder.Build(args[1].tokens);

            if (istr1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (istr2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("beforetext") || name.Equals("textbefore"))
            {
                return(new FuncBeforeText(istr1, istr2));
            }
            else if (name.Equals("aftertext") || name.Equals("textafter"))
            {
                return(new FuncAfterText(istr1, istr2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 7
0
        public static IStringable BuildStrNumNum(string name, List <Argument> args)
        {
            if (args.Count != 3)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 3 arguments: one text and two numbers.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);
            INumerable  inu1 = NumerableBuilder.Build(args[1].tokens);
            INumerable  inu2 = NumerableBuilder.Build(args[2].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (inu1.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }
            if (inu2.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Third argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("substring"))
            {
                return(new FuncSubstring__3args(istr, inu1, inu2));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 8
0
        public static IStringable BuildStrNum(string name, List <Argument> args)
        {
            if (args.Count != 2)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 2 arguments: one text and one number.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);
            INumerable  inu  = NumerableBuilder.Build(args[1].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! First argument of function " + name + " cannot be read as text.");
            }
            if (inu.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Second argument of function " + name + " cannot be read as number.");
            }

            if (name.Equals("filled") || name.Equals("fill"))
            {
                return(new FuncFilled(istr, inu));
            }
            else if (name.Equals("repeat") || name.Equals("repeated"))
            {
                return(new FuncRepeat(istr, inu));
            }
            else if (name.Equals("substring"))
            {
                return(new FuncSubstring__2args(istr, inu));
            }
            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 9
0
        public static ICommand Build(List <Token> tokens, bool forced)
        {
            TokenType type = tokens[0].GetTokenType();

            tokens.RemoveAt(0);

            int toIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.To);
            int asIndex = TokenGroups.IndexOfTokenOutsideBrackets(tokens, TokenType.As);

            if (asIndex < toIndex)
            {
                return(null);
            }
            if (toIndex == asIndex - 1)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " do not have definition of destination directory.");
            }
            if (asIndex == tokens.Count - 1)
            {
                throw new SyntaxErrorException("ERROR! Command " + GetName(type) + " do not have definition of new name for file/directory.");
            }

            List <Token> listTokens        = tokens.Take(toIndex).ToList();
            List <Token> destinationTokens = tokens.GetRange(toIndex + 1, asIndex - toIndex - 1);
            List <Token> nameTokens        = tokens.Skip(asIndex + 1).ToList();

            IStringable destination = StringableBuilder.Build(destinationTokens);

            if (destination.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of destination directory cannot be read as text.");
            }
            IStringable name = StringableBuilder.Build(nameTokens);

            if (name.IsNull())
            {
                throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of new name for file/directory cannot be read as text.");
            }

            if (listTokens.Count == 0)
            {
                return(BuildSimple(type, destination, name, forced));
            }
            else
            {
                IListable list = ListableBuilder.Build(listTokens);
                if (list.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! In command " + GetName(type) + " definition of list of files and directories is not correct.");
                }
                return(BuildComplex(type, list, destination, name, forced));
            }
        }
Exemplo n.º 10
0
        public static IStringable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }

            if (name.Equals("upper") || name.Equals("toupper"))
            {
                return(new FuncUpper(istr));
            }
            else if (name.Equals("lower") || name.Equals("tolower"))
            {
                return(new FuncLower(istr));
            }
            else if (name.Equals("digits"))
            {
                return(new FuncDigits(istr));
            }
            else if (name.Equals("letters"))
            {
                return(new FuncLetters(istr));
            }
            else if (name.Equals("trim"))
            {
                return(new FuncTrim(istr));
            }
            else if (name.Equals("name"))
            {
                return(new FuncName(istr));
            }
            else if (name.Equals("fullname"))
            {
                return(new FuncFullname(istr));
            }
            else if (name.Equals("extension"))
            {
                return(new FuncExtension(istr));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 11
0
        // functions are grouped by their arguments
        // every set of arguments is one method below

        public static IBoolable BuildStr(string name, List <Argument> args)
        {
            if (args.Count != 1)
            {
                throw new SyntaxErrorException("ERROR! Function " + name + " has to have 1 text argument.");
            }

            IStringable istr = StringableBuilder.Build(args[0].tokens);

            if (istr.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Argument of function " + name + " cannot be read as text.");
            }
            if (name.Equals("exist") || name.Equals("exists"))
            {
                return(new FuncExist(istr));
            }
            else if (name.Equals("empty") || name.Equals("emptydirectory"))
            {
                return(new FuncEmpty(istr));
            }
            else if (name.Equals("iscorrect"))
            {
                return(new FuncIscorrect(istr));
            }
            else if (name.Equals("isdirectory"))
            {
                return(new FuncIsdirectory(istr));
            }
            else if (name.Equals("isfile"))
            {
                return(new FuncIsfile(istr));
            }
            else if (name.Equals("hidden"))
            {
                return(new FuncHidden(istr));
            }
            else if (name.Equals("readonly"))
            {
                return(new FuncReadonly(istr));
            }

            throw new SyntaxErrorException("ERROR! Function " + name + " not identified.");
        }
Exemplo n.º 12
0
        public static ICommand Build(List <Token> tokens)
        {
            string name = tokens[0].GetContent();

            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            List <Token> indexTokens = new List <Token>();

            while (tokens.First().GetTokenType() != TokenType.SquareBracketOff)
            {
                indexTokens.Add(tokens.First());
                tokens.RemoveAt(0);
            }
            tokens.RemoveAt(0);

            INumerable index = NumerableBuilder.Build(indexTokens);

            if (index.IsNull())
            {
                throw new SyntaxErrorException("ERROR! Index of element of list " + name + " cannot be read as number.");
            }
            if (tokens.First().GetTokenType() != TokenType.Equals)
            {
                return(null);
            }

            tokens.RemoveAt(0);

            IStringable newValue = StringableBuilder.Build(tokens);

            if (newValue.IsNull())
            {
                return(null);
            }

            return(new ListElementDeclaration(name, newValue, index));
        }
Exemplo n.º 13
0
        public static ICommand BuildCreateFrom(List <Token> tokens, bool forced, bool directory)
        {
            List <Token> part1    = new List <Token>();
            List <Token> part2    = new List <Token>();
            bool         pastFrom = false;

            foreach (Token tok in tokens)
            {
                if (tok.GetTokenType().Equals(TokenType.From))
                {
                    pastFrom = true;
                }
                else
                {
                    if (pastFrom)
                    {
                        part2.Add(tok);
                    }
                    else
                    {
                        part1.Add(tok);
                    }
                }
            }
            if (part2.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Source in " + (directory ? "directory" : "file")
                                               + " creation command is empty.");
            }

            IListable   ilist;
            IStringable istring = StringableBuilder.Build(part2);

            if (part1.Count == 0)
            {
                ilist = new StringVariableRefer("this");
            }
            else
            {
                ilist = ListableBuilder.Build(part1);
            }

            if (ilist.IsNull())
            {
                throw new SyntaxErrorException("ERROR! There are is something wrong with new " + (directory ? "directory" : "file") +
                                               " name in " + (directory ? "directory" : "file") + " creation command syntax.");
            }
            if (istring.IsNull())
            {
                throw new SyntaxErrorException("ERROR! There are is something wrong with source " + (directory ? "directory" : "file") +
                                               " name in " + (directory ? "directory" : "file") + " creation command syntax.");
            }

            if (directory)
            {
                return(new CreateDirectoryFrom(istring, ilist, forced));
            }
            else
            {
                return(new CreateFileFrom(istring, ilist, forced));
            }
        }
        public static ICommand Build(List <Token> tokens)
        {
            string name = tokens[0].GetContent();

            tokens.RemoveAt(0);
            tokens.RemoveAt(0);

            if (tokens.Count == 0)
            {
                throw new SyntaxErrorException("ERROR! Variable " + name + " has no assigned value.");
            }

            if (name.Contains('.'))
            {
                return(BuildWithPoint(tokens, name));
            }

            if (!InterVariables.GetInstance().Contains(name))
            {
                IListable value = ListableBuilder.Build(tokens);
                if (value.IsNull())
                {
                    throw new SyntaxErrorException("ERROR! There are is something wrong with assigning value to variable " + name + ".");
                }

                if (value is IBoolable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.Bool);
                    return(new BoolDeclaration(name, (IBoolable)value));
                }
                else if (value is INumerable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.Number);
                    return(new NumericDeclaration(name, (INumerable)value));
                }
                else if (value is ITimeable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.Time);
                    return(new TimeDeclaration(name, (ITimeable)value));
                }
                else if (value is IStringable)
                {
                    InterVariables.GetInstance().Add(name, InterVarType.String);
                    return(new StringDeclaration(name, (IStringable)value));
                }
                else
                {
                    InterVariables.GetInstance().Add(name, InterVarType.List);
                    return(new ListDeclaration(name, value));
                }
            }
            else
            {
                InterVar ivar = InterVariables.GetInstance().GetVar(name);

                if (ivar.IsBool())
                {
                    IBoolable value = BoolableBuilder.Build(tokens);
                    if (value.IsNull())
                    {
                        throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be logical.");
                    }
                    return(new BoolDeclaration(name, value));
                }
                else
                {
                    if (ivar.IsNumber())
                    {
                        INumerable value = NumerableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be numeric.");
                        }
                        return(new NumericDeclaration(name, value));
                    }
                    else if (ivar.IsTime())
                    {
                        ITimeable value = TimeableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be time.");
                        }
                        return(new TimeDeclaration(name, value));
                    }
                    else if (ivar.IsString())
                    {
                        IStringable value = StringableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be text.");
                        }
                        return(new StringDeclaration(name, value));
                    }
                    else
                    {
                        IListable value = ListableBuilder.Build(tokens);
                        if (value.IsNull())
                        {
                            throw new SyntaxErrorException("ERROR! Value assigned to variable " + name + " must be list.");
                        }
                        return(new ListDeclaration(name, value));
                    }
                }
            }
        }