示例#1
0
            public override void CaseADeconstructorDecl(ADeconstructorDecl node)
            {
                End  = Start = TextPoint.FromCompilerCoords(node.GetName().Line, node.GetName().Pos);
                Name = node.GetName().Text;

                base.CaseADeconstructorDecl(node);
            }
示例#2
0
        public VariableDescription(AALocalDecl localDecl, VariableTypes type)
        {
            Name = localDecl.GetName().Text;
            Type = Util.TypeToString(localDecl.GetType());
            switch (type)
            {
            case VariableTypes.LocalVariable:
                PlacementPrefix = "Local";
                break;

            case VariableTypes.Parameter:
                PlacementPrefix = "Parameter";
                break;

            case VariableTypes.StructVariable:
                PlacementPrefix = "Struct field";
                break;

            default:
                PlacementPrefix = "";
                break;
            }
            VariableType = type;
            Const        = localDecl.GetConst() != null;
            IsStatic     = localDecl.GetStatic() != null;
            Visibility   = localDecl.GetVisibilityModifier();
            realType     = (PType)localDecl.GetType().Clone();
            init         = localDecl.GetInit();
            Line         = localDecl.GetName().Line;
            Position     = TextPoint.FromCompilerCoords(localDecl.GetName());
        }
示例#3
0
        public static void CreateItems(APropertyDecl decl, List <MethodDescription> methods, out VariableDescription variable)
        {
            if (decl.GetName().Text == "")
            {
                variable = null;
            }
            else
            {
                variable = new VariableDescription(decl);
            }

            TextPoint getterStart, setterStart;

            getterStart = setterStart = TextPoint.FromCompilerCoords(decl.GetName());
            if (decl.GetSetter() != null && decl.GetGetter() != null)
            {
                if (Util.TokenLessThan(((AABlock)decl.GetSetter()).GetToken(), ((AABlock)decl.GetGetter()).GetToken()))
                {
                    getterStart = TextPoint.FromCompilerCoords(((AABlock)decl.GetSetter()).GetToken());
                }
                else
                {
                    setterStart = TextPoint.FromCompilerCoords(((AABlock)decl.GetGetter()).GetToken());
                }
            }
            if (decl.GetGetter() != null)
            {
                methods.Add(new MethodDescription(getterStart, decl.GetType(), (AABlock)decl.GetGetter(), decl.GetType()));
            }
            if (decl.GetSetter() != null)
            {
                methods.Add(new MethodDescription(setterStart, new AVoidType(new TVoid("void")), (AABlock)decl.GetSetter(), decl.GetType()));
            }
        }
示例#4
0
            public override void CaseAMethodDecl(AMethodDecl node)
            {
                End        = Start = TextPoint.FromCompilerCoords(node.GetName().Line, node.GetName().Pos);
                ReturnType = Util.TypeToString(node.GetReturnType());
                Name       = node.GetName().Text;

                base.CaseAMethodDecl(node);
            }
示例#5
0
            public override void CaseAInitializerDecl(AInitializerDecl node)
            {
                Name       = "";
                ReturnType = "void";
                End        = Start = TextPoint.FromCompilerCoords(node.GetToken().Line, node.GetToken().Pos);

                base.CaseAInitializerDecl(node);
            }
 public TypedefDescription(ATypedefDecl typeDef)
 {
     Name     = ((ANamedType)typeDef.GetName()).AsString();
     Snapshot = typeDef;
     typeDef.Parent().RemoveChild(typeDef);
     Position = TextPoint.FromCompilerCoords(typeDef.GetToken());
     realType = typeDef.GetType();
 }
示例#7
0
 public VariableDescription(ATriggerDecl triggerDecl)
 {
     Name            = triggerDecl.GetName().Text;
     Type            = "trigger";
     PlacementPrefix = "Field";
     VariableType    = VariableTypes.Field;
     Const           = false;
     IsStatic        = false;
     realType        = new ANamedType(new TIdentifier("trigger"), null);
     Visibility      = (PVisibilityModifier)triggerDecl.GetVisibilityModifier().Clone();
     Line            = triggerDecl.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(triggerDecl.GetActionsToken());
 }
示例#8
0
 public override void CaseAABlock(AABlock node)
 {
     if (node == null)
     {
         return;
     }
     //If this is the first block, it marks the end
     if (node.Parent() is AMethodDecl || node.Parent() is AInitializerDecl || node.Parent() is ATriggerDecl ||
         node.Parent() is APropertyDecl || node.Parent() is AConstructorDecl || node.Parent() is ADeconstructorDecl)
     {
         End = TextPoint.FromCompilerCoords(node.GetToken().Line, node.GetToken().Pos);
     }
     base.CaseAABlock(node);
 }
示例#9
0
 public VariableDescription(AFieldDecl fieldDecl)
 {
     Name            = fieldDecl.GetName().Text;
     Type            = Util.TypeToString(fieldDecl.GetType());
     PlacementPrefix = "Field";
     VariableType    = VariableTypes.Field;
     Const           = fieldDecl.GetConst() != null;
     IsStatic        = fieldDecl.GetStatic() != null;
     Visibility      = fieldDecl.GetVisibilityModifier();
     realType        = (PType)fieldDecl.GetType().Clone();
     init            = fieldDecl.GetInit();
     Line            = fieldDecl.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(fieldDecl.GetName());
 }
        public EnrichmentDescription(AEnrichmentDecl structDecl)
        {
            Parser parser = new Parser(structDecl);

            Fields         = parser.Fields;
            Methods        = parser.Methods;
            Constructors   = parser.Constructors;
            Deconstructors = parser.Deconstructors;
            LineFrom       = structDecl.GetToken().Line;
            LineTo         = structDecl.GetEndToken().Line;
            type           = structDecl.GetType();
            type.Parent().RemoveChild(type);
            IsClass  = structDecl.GetDimention() != null;
            Position = TextPoint.FromCompilerCoords(structDecl.GetToken());
        }
示例#11
0
 public VariableDescription(APropertyDecl property)
 {
     Name            = property.GetName().Text;
     IsArrayProperty = Name == "array property";
     if (IsArrayProperty)
     {
         Name = "";
     }
     Type            = Util.TypeToString(property.GetType());
     PlacementPrefix = "Property";
     VariableType    = VariableTypes.Field;
     Const           = false;
     IsStatic        = property.GetStatic() != null;
     Visibility      = property.GetVisibilityModifier();
     realType        = (PType)property.GetType().Clone();
     Line            = property.GetName().Line;
     Position        = TextPoint.FromCompilerCoords(property.GetName());
 }
示例#12
0
        public MethodDescription(AInitializerDecl initializer)
        {
            Parser parser = new Parser(initializer);

            Start      = parser.Start;
            End        = parser.End;
            ReturnType = parser.ReturnType;
            Name       = parser.Name;
            Formals    = parser.Formals;
            Locals     = parser.Locals;
            if (initializer.Parent() != null)
            {
                initializer.Parent().RemoveChild(initializer);
            }
            //Decl = initializer;
            IsStatic = false;
            Position = TextPoint.FromCompilerCoords(initializer.GetToken());
        }
示例#13
0
        public MethodDescription(ADeconstructorDecl method)
        {
            Parser parser = new Parser(method);


            Start      = parser.Start;
            End        = parser.End;
            ReturnType = "void";
            Name       = parser.Name;
            Formals    = parser.Formals;
            Locals     = parser.Locals;
            if (method.Parent() != null)
            {
                method.Parent().RemoveChild(method);
            }
            while (method.GetFormals().Count > 0)
            {
                Decl.GetFormals().Add(method.GetFormals()[0]);
            }
            Visibility = method.GetVisibilityModifier();
            Position   = TextPoint.FromCompilerCoords(method.GetName());
        }
            /*public override void OutAIncludeDecl(AIncludeDecl node)
             * {
             *  string name = Util.GetString(node.GetName());
             *  SourceFileContents sourceFile = compiler.LookupFile(name);
             *  if (sourceFile != null)
             *  {
             *      Includes.Add(sourceFile);
             *  }
             * }*/

            public override void OutATriggerDecl(ATriggerDecl node)
            {
                //Add field
                Fields.Add(new VariableDescription(node));
                //Add event method
                //The methods don't start from node.GetName(), make the parser add the events, conditions and action tokens
                if (node.GetEvents() != null)
                {
                    Methods.Add(
                        new MethodDescription(TextPoint.FromCompilerCoords(node.GetEventToken().Line, node.GetEventToken().Pos),
                                              new AVoidType(new TVoid("void")), (AABlock)node.GetEvents(), null));
                }
                if (node.GetConditions() != null)
                {
                    Methods.Add(
                        new MethodDescription(TextPoint.FromCompilerCoords(node.GetConditionsToken().Line, node.GetConditionsToken().Pos),
                                              new AVoidType(new TVoid("void")), (AABlock)node.GetConditions(), null));
                }
                //Actions. this one can be called
                {
                    AMethodDecl method = new AMethodDecl((PVisibilityModifier)node.GetVisibilityModifier().Clone(), null, null, null, null, null,
                                                         new ANamedType(new TIdentifier("bool"), null),
                                                         new TIdentifier(node.GetName().Text, node.GetActionsToken().Line, node.GetActionsToken().Pos),
                                                         new ArrayList()
                    {
                        new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                        new ANamedType(
                                            new TIdentifier("bool"), null),
                                        new TIdentifier("testConds"), null),
                        new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null,
                                        new ANamedType(
                                            new TIdentifier("bool"), null),
                                        new TIdentifier("runActions"), null)
                    },
                                                         node.GetActions());
                    Methods.Add(new MethodDescription(method));
                }
            }
示例#15
0
        public StructDescription(AStructDecl structDecl)
        {
            Parser parser = new Parser(structDecl);

            Name   = parser.Name;
            IsEnum = Name.StartsWith("enum ");
            if (IsEnum)
            {
                Name = Name.Substring(5);
                foreach (VariableDescription field in parser.Fields)
                {
                    field.PlacementPrefix = "Enum Field";
                }
            }
            Fields = parser.Fields;

            Methods        = parser.Methods;
            Constructors   = parser.Constructors;
            Deconstructors = parser.Deconstructors;
            LineFrom       = structDecl.GetName().Line;
            LineTo         = structDecl.GetEndToken().Line;
            if (structDecl.GetBase() is AGenericType)
            {
                BaseRef = (ANamedType)((AGenericType)structDecl.GetBase()).GetBase();
            }
            else
            {
                BaseRef = (ANamedType)structDecl.GetBase();
            }
            structDecl.RemoveChild(BaseRef);
            foreach (TIdentifier identifier in structDecl.GetGenericVars())
            {
                GenericVars.Add(identifier.Text);
            }
            IsClass    = structDecl.GetClassToken() != null;
            Visibility = (PVisibilityModifier)structDecl.GetVisibilityModifier().Clone();
            Position   = TextPoint.FromCompilerCoords(structDecl.GetName());
        }
示例#16
0
        public MethodDescription(AMethodDecl method)
        {
            Parser parser = new Parser(method);


            Start      = parser.Start;
            End        = parser.End;
            ReturnType = parser.ReturnType;
            Name       = parser.Name;
            Formals    = parser.Formals;
            Locals     = parser.Locals;
            if (method.Parent() != null)
            {
                method.Parent().RemoveChild(method);
            }
            IsDelegate = method.GetDelegate() != null;
            //if (!IsDelegate)
            Decl       = method;
            IsStatic   = method.GetStatic() != null;
            Visibility = method.GetVisibilityModifier();
            realType   = (PType)method.GetReturnType().Clone();
            Position   = TextPoint.FromCompilerCoords(method.GetName());
        }
示例#17
0
        public MethodDescription(AConstructorDecl method, string type)
        {
            Parser parser = new Parser(method);


            Start      = parser.Start;
            End        = parser.End;
            ReturnType = type;
            Name       = parser.Name;
            Formals    = parser.Formals;
            Locals     = parser.Locals;
            if (method.Parent() != null)
            {
                method.Parent().RemoveChild(method);
            }
            Decl = new AMethodDecl(new APublicVisibilityModifier(), null, null, null, null, null, new ANamedType(new TIdentifier(type), null),
                                   new TIdentifier(""), new ArrayList(), method.GetBlock());
            while (method.GetFormals().Count > 0)
            {
                Decl.GetFormals().Add(method.GetFormals()[0]);
            }
            Visibility = method.GetVisibilityModifier();
            Position   = TextPoint.FromCompilerCoords(method.GetName());
        }
        public NamespaceDescription(ANamespaceDecl ns)
        {
            decl     = ns;
            LineFrom = decl.GetToken().Line;
            if (decl.GetEndToken() == null)
            {
                LineTo = int.MaxValue;
            }
            else
            {
                LineTo = decl.GetEndToken().Line;
            }
            SourceFileContents.Parser parser = new SourceFileContents.Parser(ns);

            //if (Structs.Count != parser.Structs.Count && Form1.Form.CurrentOpenFile != null && Form1.Form.CurrentOpenFile.OpenFile != null)
            //  Form1.Form.CurrentOpenFile.OpenFile.Editor.Restyle();


            Methods = parser.Methods;
            foreach (MethodDescription method in Methods)
            {
                method.ParentFile = this;
            }
            Fields = parser.Fields;
            foreach (VariableDescription field in Fields)
            {
                field.ParentFile = this;
            }
            Structs = parser.Structs;
            foreach (StructDescription structDescription in Structs)
            {
                foreach (MethodDescription method in structDescription.Methods)
                {
                    method.ParentFile = this;
                }
                foreach (VariableDescription field in structDescription.Fields)
                {
                    field.ParentFile = this;
                }
                structDescription.ParentFile = this;
            }
            Enrichments = parser.Enrichments;
            foreach (EnrichmentDescription structDescription in Enrichments)
            {
                structDescription.ParentFile = this;
                foreach (MethodDescription method in structDescription.Methods)
                {
                    method.ParentFile = this;
                }
                foreach (VariableDescription field in structDescription.Fields)
                {
                    field.ParentFile = this;
                }
            }
            Typedefs = parser.Typedefs;
            foreach (TypedefDescription typedef in Typedefs)
            {
                typedef.ParentFile = this;
            }
            Usings     = parser.Usings;
            Namespaces = parser.Namespaces;
            foreach (NamespaceDescription namespaceDescription in Namespaces)
            {
                namespaceDescription.Parent = this;
            }
            Position = TextPoint.FromCompilerCoords(ns.GetName());
        }
示例#19
0
        public void InsertEvent(string name, bool jumpToIt)
        {
            //Look for method with signature
            //void <name>(int sender, <dialogname>* dialog);
            //If found, set caret to that place, if not - append it and set carret

            //Don't assume the code can compile
            string code  = ActualCode;
            int    lines = 0;

            foreach (char c in code)
            {
                if (c == '\n')
                {
                    lines++;
                }
            }
            TextPoint focusAt = new TextPoint(-1, -1);

            using (StringReader reader = new StringReader(code))
            {
                Lexer        lexer  = new Lexer(reader);
                List <Token> tokens = new List <Token>();
                Token        token  = null;
                while ((token = lexer.Next()) != null)
                {
                    if (token is EOF)
                    {
                        break;
                    }
                    if (token is TWhiteSpace || token is TTraditionalComment || token is TEndOfLineComment)
                    {
                        continue;
                    }
                    tokens.Add(token);
                }
                for (int i = 0; i < tokens.Count - 11; i++)
                {
                    token = tokens[i];
                    if (token is TVoid)
                    {
                        token = tokens[i + 1];
                        if (token is TIdentifier && token.Text == name && tokens[i + 2] is TLParen)
                        {
                            token = tokens[i + 3];
                            if (token is TIdentifier && token.Text == "int" &&
                                tokens[i + 4] is TIdentifier && tokens[i + 5] is TComma)
                            {
                                token = tokens[i + 6];
                                if (token is TIdentifier && token.Text == DialogIdentiferName &&
                                    tokens[i + 7] is TStar && tokens[i + 8] is TIdentifier &&
                                    tokens[i + 9] is TRParen && tokens[i + 10] is TLBrace)
                                {
                                    focusAt = TextPoint.FromCompilerCoords(tokens[i + 10]);
                                }
                            }
                        }
                    }
                }
            }

            if (focusAt.Line == -1)
            {                    //Didn't find it. Append it
                jumpToIt = true; //This should not be auto saved. Have to open it.
                string s = "\n\nvoid " + name + "(int sender, " + DialogIdentiferName + "* dialog)\n" +
                           "{\n" +
                           "\t\n" +
                           "}\n";
                Form1.Form.OpenFile(DialogItem, DialogItem.CodeGUINode);
                CodeEditor.Text += s;
                focusAt          = new TextPoint(lines + 4, 1);
            }
            else if (jumpToIt)
            {
                Form1.Form.OpenFile(DialogItem, DialogItem.CodeGUINode);
            }
            if (jumpToIt)
            {
                CodeEditor.MoveCaretTo(focusAt);
            }
        }
示例#20
0
        private static void ReplaceInvocations(ref string source, List <Macro> macros, List <Macro> currentReplacePath, ErrorCollection errors)
        {
            Lexer        lexer  = new Lexer(new StringReader(source));
            List <Token> tokens = new List <Token>();
            Token        token;

            while (!((token = lexer.Next()) is EOF))
            {
                if (token is TWhiteSpace || token is TTraditionalComment || token is TDocumentationComment || token is TEndOfLineComment)
                {
                    continue;
                }
                tokens.Add(token);
            }

            List <Util.Pair <Util.Pair <TextPoint, TextPoint>, string> > macroSpan = new List <Util.Pair <Util.Pair <TextPoint, TextPoint>, string> >();

            for (int j = 0; j < tokens.Count - 1; j++)
            {
                int t = j;
                if (tokens[t] is TSharp && tokens[t + 1] is TIdentifier)
                {
                    Token     sharp = tokens[t];
                    TextPoint start = TextPoint.FromCompilerCoords(tokens[t]);
                    t++;
                    string Name = tokens[t].Text;
                    //Check for parameters
                    t++;
                    bool          IsMethod  = false;
                    List <string> arguments = new List <string>();
                    TextPoint     end;
                    if (tokens[t] is TLParen)
                    {
                        IsMethod = true;
                        int       parens   = 1;
                        TextPoint argStart = TextPoint.FromCompilerCoords(tokens[t + 1]);
                        while (true)
                        {
                            t++;
                            if (t >= tokens.Count)
                            {
                                errors.Add(new ErrorCollection.Error(sharp, LocRM.GetString("ErrorText214")));
                                t--;
                                break;
                            }

                            if (tokens[t] is TLParen || tokens[t] is TLBrace || tokens[t] is TLBracket)
                            {
                                parens++;
                            }
                            if (tokens[t] is TRParen || tokens[t] is TRBrace || tokens[t] is TRBracket)
                            {
                                parens--;
                            }
                            if (parens == 0)
                            {
                                if (!(tokens[t] is TRParen))
                                {
                                    errors.Add(new ErrorCollection.Error(tokens[t], LocRM.GetString("ErrorText215")));
                                }
                                if (!(tokens[t - 1] is TLParen))
                                {
                                    TextPoint e = TextPoint.FromCompilerCoords(tokens[t]);
                                    e.Pos++;
                                    arguments.Add(GetText(source, argStart, e));
                                }

                                break;
                            }
                            if (parens > 1)
                            {
                                continue;
                            }
                            if (tokens[t] is TComma)
                            {
                                TextPoint e = TextPoint.FromCompilerCoords(tokens[t]);
                                e.Pos++;
                                arguments.Add(GetText(source, argStart, e));
                                argStart = e;
                            }
                        }
                        end = TextPoint.FromCompilerCoords(tokens[t]);
                        end.Pos++;
                    }
                    else
                    {
                        end      = TextPoint.FromCompilerCoords(tokens[t - 1]);
                        end.Pos += Name.Length;
                    }

                    bool found = false;
                    foreach (Macro macro in macros)
                    {
                        if (macro.Name == Name &&
                            macro.Method == IsMethod &&
                            macro.Parameters.Count == arguments.Count)
                        {
                            found = true;
                            if (currentReplacePath.Contains(macro))
                            {
                                List <ErrorCollection.Error> subErrors = new List <ErrorCollection.Error>();
                                for (int i = currentReplacePath.IndexOf(macro); i < currentReplacePath.Count; i++)
                                {
                                    subErrors.Add(new ErrorCollection.Error(currentReplacePath[i].token, LocRM.GetString("ErrorText216")));
                                }
                                errors.Add(new ErrorCollection.Error(sharp, LocRM.GetString("ErrorText217"), false, subErrors.ToArray()));
                                break;
                            }
                            string       macroText      = macro.GetText(arguments);
                            List <Macro> newCurrentPath = new List <Macro>();
                            newCurrentPath.AddRange(currentReplacePath);
                            newCurrentPath.Add(macro);
                            ReplaceInvocations(ref macroText, macros, newCurrentPath, errors);
                            macroSpan.Add(new Util.Pair <Util.Pair <TextPoint, TextPoint>, string>(new Util.Pair <TextPoint, TextPoint>(start, end), macroText));
                        }
                    }
                    if (!found)
                    {
                        errors.Add(new ErrorCollection.Error(sharp, LocRM.GetString("ErrorText218")));
                    }
                    j = t - 1;
                }
            }


            //Remove macros
            for (int i = macroSpan.Count - 1; i >= 0; i--)
            {
                List <string> lines = source.Split('\n').ToList();
                TextPoint     start = macroSpan[i].First.First;
                TextPoint     end   = macroSpan[i].First.Second;
                string        text  = macroSpan[i].Second;

                lines[start.Line] = lines[start.Line].Substring(0, start.Pos - 1) + text + lines[end.Line].Substring(end.Pos - 1);
                for (int line = end.Line; line > start.Line; line--)
                {
                    lines.RemoveAt(line);
                }

                StringBuilder builder = new StringBuilder();
                builder.Append(lines[0]);
                for (int j = 0; j < lines.Count; j++)
                {
                    builder.Append("\n" + lines[j]);
                }
                source = builder.ToString();
            }
        }
示例#21
0
        public static void Parse(List <string> files, ErrorCollection errors)
        {
            /*
             * #macro <identifier>[(<identifiers>)]
             * anything...#arg1...anything
             *
             * #endmacro
             *
             * #<identifier>(anything_but_comma, #anything_but_hash#)
             *
             *
             */

            //Phase 1: locate all macros
            List <Macro> macros = new List <Macro>();

            for (int i = 0; i < files.Count; i++)
            {
                string source = files[i];


                Lexer        lexer  = new Lexer(new StringReader(source));
                List <Token> tokens = new List <Token>();
                Token        token;
                while (!((token = lexer.Next()) is EOF))
                {
                    if (token is TWhiteSpace || token is TTraditionalComment || token is TDocumentationComment || token is TEndOfLineComment)
                    {
                        continue;
                    }
                    tokens.Add(token);
                }

                List <Util.Pair <TextPoint, TextPoint> > macroSpan = new List <Util.Pair <TextPoint, TextPoint> >();

                for (int j = 0; j < tokens.Count - 1; j++)
                {
                    int t = j;
                    if (tokens[t] is TSharp && tokens[t + 1].Text == "macro")
                    {
                        Macro macro = new Macro();
                        Token sharp = tokens[t];
                        macro.token = sharp;
                        TextPoint start = TextPoint.FromCompilerCoords(tokens[t]);
                        t += 2;
                        if (t >= tokens.Count || !(tokens[t] is TIdentifier))
                        {
                            errors.Add(new ErrorCollection.Error(sharp, LocRM.GetString("ErrorText206")));
                            continue;
                        }
                        macro.Name = tokens[t].Text;
                        //Find end
                        TextPoint end = new TextPoint(-1, -1);
                        for (int k = t; k < tokens.Count - 1; k++)
                        {
                            if (tokens[k] is TSharp)
                            {
                                if (tokens[k + 1].Text == "macro")
                                {
                                    errors.Add(new ErrorCollection.Error(tokens[k],
                                                                         LocRM.GetString("ErrorText207"),
                                                                         false,
                                                                         new ErrorCollection.Error(sharp,
                                                                                                   LocRM.GetString("ErrorText208"))));
                                }
                                else if (tokens[k + 1].Text == "endmacro")
                                {
                                    end = TextPoint.FromCompilerCoords(tokens[k]);
                                    break;
                                }
                            }
                        }
                        if (end.Line == -1)
                        {
                            errors.Add(new ErrorCollection.Error(sharp, LocRM.GetString("ErrorText209")));
                            continue;
                        }
                        //Check for parameters
                        t++;
                        TextPoint textStart;
                        if (tokens[t] is TLParen)
                        {
                            macro.Method = true;
                            bool needComma = false;
                            while (true)
                            {
                                t++;
                                if (tokens[t] is TRParen)
                                {
                                    break;
                                }
                                if (tokens[t] is TComma)
                                {
                                    if (!needComma)
                                    {
                                        errors.Add(new ErrorCollection.Error(tokens[t], LocRM.GetString("ErrorText210")));
                                        break;
                                    }
                                    needComma = false;
                                    t++;
                                }
                                if (tokens[t] is TIdentifier)
                                {
                                    if (needComma)
                                    {
                                        errors.Add(new ErrorCollection.Error(tokens[t], LocRM.GetString("ErrorText211")));
                                        break;
                                    }
                                    macro.Parameters.Add(tokens[t].Text);
                                    needComma = true;
                                    continue;
                                }
                                if (needComma)
                                {
                                    errors.Add(new ErrorCollection.Error(tokens[t], LocRM.GetString("ErrorText211")));
                                }
                                else
                                {
                                    errors.Add(new ErrorCollection.Error(tokens[t], LocRM.GetString("ErrorText210")));
                                }
                                break;
                            }
                            textStart = TextPoint.FromCompilerCoords(tokens[t]);
                            textStart.Pos++;
                            t++;
                        }
                        else
                        {
                            textStart      = TextPoint.FromCompilerCoords(tokens[t - 1]);
                            textStart.Pos += macro.Name.Length;
                        }

                        macro.Text = GetText(source, textStart, end);
                        macroSpan.Add(new Util.Pair <TextPoint, TextPoint>(start, end));
                        macros.Add(macro);
                        j = t;
                    }
                }


                //Remove macros
                List <string> lines = source.Split('\n').ToList();
                for (int j = macroSpan.Count - 1; j >= 0; j--)
                {
                    TextPoint start = macroSpan[j].First;
                    TextPoint end   = macroSpan[j].Second;

                    lines[start.Line] = lines[start.Line].Substring(0, start.Pos - 1) + lines[end.Line].Substring(end.Pos + "#endmacro".Length - 1);
                    for (int line = end.Line; line > start.Line; line--)
                    {
                        lines.RemoveAt(line);
                    }
                }

                StringBuilder builder = new StringBuilder();
                builder.Append(lines[0]);
                for (int j = 0; j < lines.Count; j++)
                {
                    builder.Append("\n" + lines[j]);
                }
                source = builder.ToString();

                files[i] = source;
            }

            //Check for dublicate macros
            for (int i = 0; i < macros.Count; i++)
            {
                List <Macro> conflicts = new List <Macro>()
                {
                    macros[i]
                };
                for (int j = i + 1; j < macros.Count; j++)
                {
                    if (macros[i].Name == macros[j].Name &&
                        macros[i].Method == macros[j].Method &&
                        macros[i].Parameters.Count == macros[j].Parameters.Count)
                    {
                        conflicts.Add(macros[j]);
                    }
                }
                if (conflicts.Count > 1)
                {
                    List <ErrorCollection.Error> subErrors = new List <ErrorCollection.Error>();
                    foreach (Macro macro in conflicts)
                    {
                        subErrors.Add(new ErrorCollection.Error(macro.token, LocRM.GetString("ErrorText212")));
                        macros.Remove(macro);
                    }
                    errors.Add(new ErrorCollection.Error(conflicts[0].token, LocRM.GetString("ErrorText213"), false, subErrors.ToArray()));
                    i--;
                }
            }

            //Search for macro invocations

            for (int i = 0; i < files.Count; i++)
            {
                string source = files[i];
                ReplaceInvocations(ref source, macros, new List <Macro>(), errors);
                files[i] = source;
            }
        }