Пример #1
0
        //往关键字树中添加关键字
        private void AddPrimaryKey(string sPKeyName, Color cColor)
        {
            PKeyCharElement cTempPKeyCharElement = aPKeyTreeHeadList;
            int             i = 0;

            for (; i < sPKeyName.Length - 1; i++)
            {
                int iIndex = cTempPKeyCharElement.AddCharElement(new PKeyCharElement(sPKeyName[i], Color.Black));
                cTempPKeyCharElement = (PKeyCharElement)cTempPKeyCharElement.aPKeyTreeList[iIndex];
            }
            cTempPKeyCharElement.AddCharElement(new PKeyCharElement(sPKeyName[i], cColor));

            if (!sPKeyName.StartsWith("<"))
            {
                sPKeyName            = sPKeyName.ToLower();
                cTempPKeyCharElement = aPKeyTreeHeadList;
                i = 0;
                for (; i < sPKeyName.Length - 1; i++)
                {
                    int iIndex = cTempPKeyCharElement.AddCharElement(new PKeyCharElement(sPKeyName[i], Color.Black));
                    cTempPKeyCharElement = (PKeyCharElement)cTempPKeyCharElement.aPKeyTreeList[iIndex];
                }
                cTempPKeyCharElement.AddCharElement(new PKeyCharElement(sPKeyName[i], cColor));
            }
        }
Пример #2
0
        public int AddCharElement(PKeyCharElement cPKeyCharElement)
        {
            int iIndex = NOTINSERT;

            for (int i = 0; i < aPKeyTreeList.Count; i++)
            {
                if (cPKeyCharElement.chKeyChar == ((PKeyCharElement)aPKeyTreeList[i]).chKeyChar)
                {
                    iIndex = i;
                    if (cPKeyCharElement.cFontColor != Color.Black)
                    {
                        ((PKeyCharElement)aPKeyTreeList[i]).cFontColor = cPKeyCharElement.cFontColor;
                    }
                    break;
                }
                else if (cPKeyCharElement.chKeyChar < ((PKeyCharElement)aPKeyTreeList[i]).chKeyChar)
                {
                    aPKeyTreeList.Insert(i, cPKeyCharElement);
                    iIndex = i;
                    break;
                }
            }
            if (iIndex == NOTINSERT)           //没有被插入到树,那么就加进去
            {
                aPKeyTreeList.Add(cPKeyCharElement);
                iIndex = aPKeyTreeList.Count - 1;
            }
            return(iIndex);
        }
Пример #3
0
 bool bCommentStartForLastLine;                                                          //表示上一行分析的结果是否包含注释的开始
 public AnlyseSyntax()
 {
     aPKeyTreeHeadList = new PKeyCharElement('a', Color.Black);
     SortListSeparator();            //排序分隔字符
     SortNotStartChar();
     CreateColorString();
     AddXmlKey();
     AddSqlKey();
 }
Пример #4
0
        //分析读入的一行,并生成相应格式的RTF文本串
        private void AnyslseSynataxForAnLine(string sLineText)
        {
            sLineText = sLineText.Replace("\\", "\\\\");
            sLineText = sLineText.Replace("{", "\\{");
            sLineText = sLineText.Replace("}", "\\}");
            int   iTextLen            = sLineText.Length;
            int   iTempStart          = 0;              //重新开始分析的位置
            int   iTempLen            = 0;              //分析字符的长度
            int   iFindListSptorIndex = NOTFOUND;       //分隔符号索引
            int   iTempIndex          = NOTFOUND;       //当前字符在语法树中当前节点子节点的索引
            bool  bCommentStart       = false;          //代表当前起始位置是注释的开始
            Color cColor = Color.Black;

            PKeyCharElement aTempTreeList = aPKeyTreeHeadList;                                  //当前语法树节点
            int             i             = 0;

            iTempStart = i;
            if (bCommentStartForLastLine)
            {
                int iCommentEndIndex = FindCommentEnd(sLineText, iTempStart);
                cColor   = COMMENTCOLOR;
                i        = iCommentEndIndex;
                iTempLen = i - iTempStart;
                AppendToSRtf(sLineText.Substring(iTempStart, iTempLen), cColor);
            }
            iTempStart = i;
            while (iTempStart < iTextLen)
            {
                iTempLen = i - iTempStart;
                AppendToSRtf(sLineText.Substring(iTempStart, iTempLen), cColor);
                iTempStart = i;
                if (iTempStart >= iTextLen)
                {
                    break;
                }
                cColor   = Color.Black;
                i        = FindStartCharIndex(sLineText, i);
                iTempLen = i - iTempStart;
                AppendToSRtf(sLineText.Substring(iTempStart, iTempLen), cColor);

                iTempStart = i;
                if (iTempStart >= iTextLen)
                {
                    break;
                }
                //判断开始处是不是以注释关键字开始的
                bCommentStart = IsCommentStart(sLineText, iTempStart);
                if (bCommentStart)
                {
                    int iCommentEndIndex = FindCommentEnd(sLineText, iTempStart);
                    cColor = COMMENTCOLOR;
                    i      = iCommentEndIndex;

                    continue;
                }
                aTempTreeList = aPKeyTreeHeadList;
                iTempIndex    = aTempTreeList.IndexOfArray(sLineText[i]);
                while (iTempIndex != NOTFOUND)
                {
                    i++;
                    if (i >= iTextLen)
                    {
                        aTempTreeList = (PKeyCharElement)aTempTreeList.aPKeyTreeList[iTempIndex];
                        break;
                    }
                    aTempTreeList = (PKeyCharElement)aTempTreeList.aPKeyTreeList[iTempIndex];
                    iTempIndex    = aTempTreeList.IndexOfArray(sLineText[i]);
                }
                if (i >= iTextLen)
                {
                    iFindListSptorIndex = NOTFOUND - 1;
                }
                else
                {
                    iFindListSptorIndex = FindListSeparatorIndex(sLineText[i]);
                    if (iFindListSptorIndex == MORETHANCHARINDEX)
                    {
                        cColor = ERRORKEYCOLOR;
                        iFindListSptorIndex = NOTFOUND;
                    }
                }
                if (iFindListSptorIndex == NOTFOUND)
                {
                    if (aTempTreeList.chKeyChar == '>')
                    {
                        cColor = aTempTreeList.cFontColor;
                        continue;
                    }
                    else                    //查找下一个分隔符所在的位置
                    {
                        i++;
                        if (i >= iTextLen)
                        {
                            i = iTextLen;
                            continue;
                        }
                        iFindListSptorIndex = FindListSeparatorIndex(sLineText[i]);
                        while (iFindListSptorIndex == NOTFOUND)
                        {
                            i++;
                            if (i >= iTextLen)
                            {
                                i = iTextLen;
                                break;
                            }
                            iFindListSptorIndex = FindListSeparatorIndex(sLineText[i]);
                        }
                        if (iFindListSptorIndex == MORETHANCHARINDEX)
                        {
                            cColor = ERRORKEYCOLOR;
                            i++;
                        }
                        else
                        {
                            cColor = Color.Black;
                        }
                        continue;
                    }
                }
                else
                {
                    cColor = aTempTreeList.cFontColor;
                    continue;
                }
            }
        }