示例#1
0
        public static List <CodePointer> GetPointers(string define, int startIndex)
        {
            List <CodePointer> pointers = new List <CodePointer>();
            Match  m    = Regex.Match(define, startPattern);
            string name = m.ToString();

            CodePointer cp = new CodePointer
            {
                Start = m.Index + startIndex,
                End   = m.Index + startIndex + name.Length - 1,
                Code  = name
            };

            pointers.Add(cp);

            define = define.Substring(m.Length);

            m = Regex.Match(define, MidPattern);

            define = define.Substring(m.Length);

            int st = cp.End + m.Length;
            int en = define.Length - 1 + startIndex;

            cp = new CodePointer
            {
                Start = st + 1,
                End   = en,
                Code  = define
            };

            pointers.Add(cp);

            return(pointers);
        }
示例#2
0
        private List <CodePointer> getPointersFromDefineSignature(CodePointer cmd, int lineIndex)
        {
            Define             d;
            List <CodePointer> pointers = new List <CodePointer>();

            if (Define.SignatureIsCorrect(cmd.Code))
            {
                d = Define.GetDefine(defines, cmd.Code, lineIndex, cmd.Start);

                if (defines.ContainsKey(d.Name))
                {
                    defines[d.Name].OthersPositions.Add(d.OthersPositions[0]);
                }
                else
                {
                    defines.Add(d.Name, d);
                }
                pointers = Define.GetPointers(cmd.Code, cmd.Start);
                if (pointers != null && pointers.Count >= 2)
                {
                    pointers[0].Group = DefineGroup;
                    pointers[1].Group = DefineArgsGroup;
                }
            }
            return(pointers);
        }
示例#3
0
        public static CodePointer[] Split(string line, string separatorPattern)
        {
            if (line == "" || line == null || line.Length <= 0)
            {
                return(null);
            }
            MatchCollection ms = Regex.Matches(line, separatorPattern);

            if (ms.Count == 0)
            {
                CodePointer[] pa = new CodePointer[1];
                pa[0] = new CodePointer
                {
                    Start = 0,
                    End   = line.Length - 1,
                    Code  = line
                };
                return(pa);
            }

            List <CodePointer> pointers = new List <CodePointer>();
            CodePointer        p;
            int s = 0;
            int e = 0;

            foreach (Match m in ms)
            {
                e = m.Index - 1;
                if (e >= s)
                {
                    p = new CodePointer
                    {
                        Start = s,
                        End   = e,
                        Code  = line.Substring(s, 1 + e - s)
                    };
                    pointers.Add(p);
                }
                s = m.Index + m.Length;
            }

            e = line.Length - 1;
            if (e >= s)
            {
                p = new CodePointer
                {
                    Start = s,
                    End   = e,
                    Code  = line.Substring(s, 1 + e - s)
                };
                pointers.Add(p);
            }

            return(pointers.ToArray());
        }
示例#4
0
        private List <CodePointer> getPointersFromLabels(CodePointer cmd, string nextChar)
        {
            List <CodePointer> pointers = new List <CodePointer>();
            List <CodePointer> tmps     = new List <CodePointer>();
            string             lab      = cmd.Code + nextChar;

            foreach (Label l in labels)
            {
                if (l.SyntaxIsCorrect(lab))
                {
                    cmd.Group = l.Group;
                    tmps.Add(cmd);
                    break;
                }
            }

            if (tmps != null && tmps.Count > 0)
            {
                IEnumerator <CodePointer> ienum = Define.definesFounded.GetEnumerator();
                CodePointer cp3;
                string      newCMD;
                foreach (CodePointer cp in tmps)
                {
                    ienum.Reset();
                    newCMD = cp.Code;
                    foreach (CodePointer cp2 in Define.replaced)
                    {
                        ienum.MoveNext();
                        if (cp.End >= cp2.End && cp.Start <= cp2.Start)
                        {
                            newCMD = newCMD.Replace(cp2.Code, ienum.Current.Code);
                        }
                    }
                    cp3 = new CodePointer
                    {
                        Start = cp.Start,
                        End   = cp.Start + newCMD.Length - 1,
                        Code  = newCMD,
                        Group = cp.Group
                    };
                    pointers.Add(cp3);
                }
            }

            return(pointers);
        }
示例#5
0
        //string spliter = @"((\*\*|\~|\%|\<\<|\>\>|\+|\-|\/|\&|\||\*|\^)(\%[0-1]+|\$[\da-fA-F]+|\d+))+";
        public CodePointer[] GetPointers(int offset, string arg)
        {
            if (arg == null || arg == "" || arg.Length <= 0)
            {
                return(null);
            }
            List <CodePointer> pointers = new List <CodePointer>();

            CodePointer cp;

            cp = new CodePointer
            {
                Start = offset,
                End   = offset + arg.Length - 1,
                Code  = arg,
                Group = Group
            };
            pointers.Add(cp);

            return(pointers.ToArray());
        }
示例#6
0
        public CodePointer[] GetPointers(int offset, string cmd)
        {
            string name = cmd.Replace('\t', ' ').Split(' ')[0];

            List <CodePointer> pointers = new List <CodePointer>();

            CodePointer cp;

            cp = new CodePointer
            {
                Start = offset,
                End   = offset + name.Length - 1,
                Code  = name,
                Group = Group
            };
            pointers.Add(cp);

            string arg = cmd.Substring(name.Length);
            Match  m;

            CodePointer[] newcps;
            int           offs = cp.End + 1;

            if (Args != null)
            {
                string newAr;
                for (int i = 0; i < Args.Length; i++)
                {
                    newAr = Args[i].RegEXPattern.
                            Remove(Args[i].RegEXPattern.Length - 1);

                    m = Regex.Match(arg, whiteSpaces);
                    if (m.Success)
                    {
                        offs += m.Length;
                        arg   = arg.Substring(m.Length);
                    }

                    m = Regex.Match(arg, newAr);
                    if (m.Success)
                    {
                        newcps = Args[i].GetPointers(offs, m.ToString());

                        if (newcps != null)
                        {
                            foreach (CodePointer codp in newcps)
                            {
                                pointers.Add(codp);
                            }
                        }
                        arg   = arg.Substring(m.ToString().Length);
                        offs += m.ToString().Length;
                    }
                    if (i < Args.Length - 1)
                    {
                        arg = arg.Substring(1);
                        offs++;
                    }
                }
            }

            return(pointers.ToArray());
        }
示例#7
0
        private List <CodePointer> getPointersFromCommands(CodePointer cmd)
        {
            List <CodePointer> pointers = new List <CodePointer>();

            string scmd = cmd.Code.Split(';')[0];

            scmd = scmd.ToLower();
            scmd = scmd.Replace("\t", " ");
            string name = scmd.Split(' ')[0];

            if (!commands.ContainsKey(name))
            {
                return(pointers);
            }

            scmd = scmd.Replace(" ", "");

            scmd = scmd.Remove(0, name.Length);

            Command            foundedC;
            List <CodePointer> tmps = null;

            string prefix = "";
            Match  m      = null;

            foreach (string s in commands[name].Keys)
            {
                if (s != "NULL")
                {
                    m = Regex.Match(scmd, s);
                    if (m.Success)
                    {
                        prefix = s;
                        break;
                    }
                }
            }

            if (prefix == "")
            {
                prefix = "NULL";
            }

            string sufix = "";

            if (commands[name].ContainsKey(prefix))
            {
                foreach (string s in commands[name][prefix].Keys)
                {
                    if (s != "NULL")
                    {
                        m = Regex.Match(scmd, s);
                        if (m.Success)
                        {
                            sufix = s;
                            break;
                        }
                    }
                }

                if (sufix == "")
                {
                    sufix = "NULL";
                }
                else
                {
                    scmd = scmd.Remove(m.Index, m.Length);
                }


                if (commands[name][prefix].ContainsKey(sufix))
                {
                    foreach (Command c in commands[name][prefix][sufix])
                    {
                        if (c.IsCorrect(scmd))
                        {
                            tmps     = c.GetPointers(cmd.Start, cmd.Code).ToList();
                            foundedC = c;
                            break;
                        }
                    }
                }
                else
                {
                    return(pointers);
                }
            }
            else
            {
                return(pointers);
            }

            if (tmps != null)
            {
                IEnumerator <CodePointer> ienum = Define.definesFounded.GetEnumerator();
                CodePointer cp3;
                string      newCMD;
                foreach (CodePointer cp in tmps)
                {
                    ienum.Reset();
                    newCMD = cp.Code;
                    foreach (CodePointer cp2 in Define.replaced)
                    {
                        ienum.MoveNext();
                        if (cp.End >= cp2.End && cp.Start <= cp2.Start)
                        {
                            newCMD = newCMD.Replace(cp2.Code, ienum.Current.Code);
                        }
                    }
                    cp3 = new CodePointer
                    {
                        Start = cp.Start,
                        End   = cp.Start + newCMD.Length - 1,
                        Code  = newCMD,
                        Group = cp.Group
                    };
                    pointers.Add(cp3);
                }
            }

            return(pointers);
        }
示例#8
0
        private List <CodePointer> getPointersFromMiniLine(CodePointer pointer, int lineIndex)
        {
            List <CodePointer> pointers = new List <CodePointer>();

            CodePointer[] cmds = CodePointer.Split(pointer.Code, @":(\ |\t)*");
            if (cmds == null || cmds.Length <= 0)
            {
                return(pointers);
            }

            List <CodePointer> tmps;
            CodePointer        cp;
            string             rep;
            string             nextChar;


            for (int i = 0; i < cmds.Length; i++)
            {
                cmds[i].Move(pointer.Start);

                tmps = getPointersFromDefineSignature(cmds[i], lineIndex);
                if (tmps.Count > 0)
                {
                    if (Define.possibleError != null)
                    {
                        tmps[1].Group = ErrorGroup;
                        if (!errors.ContainsKey(lineIndex))
                        {
                            errors.Add(lineIndex, new List <Error>());
                        }
                        errors[lineIndex].Add(Define.possibleError);
                        newErrors = true;
                    }
                }


                if (tmps.Count <= 0)
                {
                    rep = Define.Replace(defines, cmds[i].Code, lineIndex, cmds[i].Start);
                    cp  = new CodePointer
                    {
                        Start = cmds[i].Start,
                        End   = cmds[i].Start + rep.Length - 1,
                        Code  = rep
                    };


                    tmps = getPointersFromCommands(cp);
                    if (tmps.Count <= 0)
                    {
                        nextChar = "";
                        if (pointer.Code.Length + pointer.Start > cmds[i].End + 1 &&
                            pointer.Code[cmds[i].End - cmds[i].Start + 1] == ':')
                        {
                            nextChar = ":";
                        }

                        tmps = getPointersFromLabels(cp, nextChar);
                    }
                }


                if (tmps.Count <= 0)
                {
                    tmps          = new List <CodePointer>();
                    cmds[i].Group = ErrorGroup;
                    tmps.Add(cmds[i]);

                    if (!errors.ContainsKey(lineIndex))
                    {
                        errors.Add(lineIndex, new List <Error>());
                    }
                    errors[lineIndex].Add(new Error(lineIndex, cmds[i].Start,
                                                    cmds[i].Code, ErrorCode.InvalidDefineSignature, cmds[i].Code));

                    newErrors = true;
                }

                foreach (CodePointer cp1 in tmps)
                {
                    pointers.Add(cp1);
                }
            }

            return(pointers);
        }
示例#9
0
        public List <CodePointer> GetPointersFromLine(int lineIndex, string line)
        {
            List <CodePointer> pointers = new List <CodePointer>();

            CodePointer cp = new CodePointer
            {
                Start = 0,
                End   = line.Length - 1,
                Code  = line,
                Group = DefaultGroup
            };

            pointers.Add(cp);

            string[] splittedLine = line.Split(';');
            if (splittedLine == null || splittedLine.Length <= 0)
            {
                return(pointers);
            }

            string lineCode = splittedLine[0];
            string comment  = line.Substring(lineCode.Length);

            Match stMatch = Regex.Match(lineCode, startPattern);

            if (stMatch.Success)
            {
                cp = new CodePointer
                {
                    Start = stMatch.Index,
                    End   = stMatch.Index + stMatch.Length - 1,
                    Code  = stMatch.ToString(),
                    Group = ErrorGroup
                };
                pointers.Add(cp);
                newErrors = true;
            }
            else
            {
                stMatch = Regex.Match(lineCode, startSpaces);
            }

            string shorterLineCode = lineCode.Substring(stMatch.Length).Replace('\r', '\n').Replace("\n", "");
            Match  m = Regex.Match(shorterLineCode, endSpaces);

            if (m.Success)
            {
                int ll = shorterLineCode.Length - m.Length;
                if (ll < 0)
                {
                    ll = 0;
                }
                shorterLineCode =
                    shorterLineCode.Substring(0, ll);
            }

            CodePointer[] cmds = CodePointer.Split(shorterLineCode, separatorPattern);
            removeDefinesAtPosition(lineIndex);
            removeErrorsAtPosition(lineIndex);

            if (cmds != null && cmds.Length > 0)
            {
                List <CodePointer> tmps;

                for (int j = 0; j < cmds.Length; j++)
                {
                    cmds[j].Move(stMatch.Length);
                    tmps = getPointersFromMiniLine(cmds[j], lineIndex);
                    foreach (CodePointer cp1 in tmps)
                    {
                        pointers.Add(cp1);
                    }
                }
            }

            Match endMatch = Regex.Match(lineCode, endPattern);

            if (endMatch.Success)
            {
                cp = new CodePointer
                {
                    Start = endMatch.Index,
                    End   = endMatch.Index + endMatch.Length - 1,
                    Code  = endMatch.ToString(),
                    Group = ErrorGroup
                };
                pointers.Add(cp);
                newErrors = true;
            }

            cp = new CodePointer
            {
                Start = lineCode.Length,
                End   = line.Length - 1,
                Code  = comment,
                Group = CommentGroup
            };
            pointers.Add(cp);

            return(pointers);
        }
示例#10
0
        public static string Replace(Dictionary <string, Define> Defines,
                                     string define, int line, int startIndex)
        {
            definesFounded = new List <CodePointer>();
            replaced       = new List <CodePointer>();
            MatchCollection ms = Regex.Matches(define, startPattern1);

            if (ms.Count <= 0)
            {
                return(define);
            }
            List <Define> defines = new List <Define>();
            CodePointer   cp;
            string        s;

            foreach (Match m in ms)
            {
                s = m.ToString();
                if (Defines.ContainsKey(s))
                {
                    defines.Add(Defines[s]);
                    cp = new CodePointer
                    {
                        Start = startIndex + m.Index,
                        End   = startIndex + m.Index + m.Length - 1,
                        Code  = m.ToString()
                    };
                    definesFounded.Add(cp);
                }
            }

            List <string> SplitedDef = new List <string>();
            int           st         = 0;
            int           len        = 0;

            foreach (Match m in ms)
            {
                if (m.Index == 0)
                {
                    len = m.Length;
                    SplitedDef.Add(define.Substring(st, len));
                }
                else
                {
                    len = m.Index - st;
                    SplitedDef.Add(define.Substring(st, len));
                    st  = m.Index;
                    len = m.Length;
                    SplitedDef.Add(define.Substring(st, len));
                }
                st += m.Length;
            }
            int lenn = define.Length - st;

            if (lenn > 0)
            {
                SplitedDef.Add(define.Substring(st, lenn));
            }

            Define[] defarr = defines.ToArray();
            if (defarr.Length <= 0)
            {
                return(define);
            }
            int                      q  = 0;
            StringBuilder            sb = new StringBuilder();
            string                   newm;
            Tuple <int, int, string> tup;

            foreach (string str in SplitedDef)
            {
                if (q < defarr.Length && defarr[q].Name == str)
                {
                    tup = defarr[q].NearestPosition(line, startIndex);
                    if (tup == null)
                    {
                        sb.Append(str);
                    }
                    else
                    {
                        newm = tup.Item3;
                        cp   = new CodePointer
                        {
                            Start = startIndex + sb.Length,
                            End   = startIndex + sb.Length + newm.Length - 1,
                            Code  = newm
                        };
                        replaced.Add(cp);
                        sb.Append(newm);
                    }
                    q++;
                }
                else
                {
                    sb.Append(str);
                }
            }

            return(sb.ToString());
        }