Example #1
0
    void ParseEnum(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "enum".Length;

        string name = ReadWord(section.data, ref caret);

        if (name == "class")
        {
            name = ReadWord(section.data, ref caret);
        }

        string block = ReadBlock(section.data, ref caret).Trim(' ', '{', '}', '\r', '\t', '\n');
        string blockWithoutComments = RemoveComments(block);
        var    content = Split(blockWithoutComments, ',');

        LexEnum newEnum = new LexEnum()
        {
            begin = begin,
            end   = caret,
            data  = section.data.Substring(begin, caret - begin),
            name  = name
        };

        content.ForEach(x => newEnum.content.Add(x.Trim(' ', '\n', '\t', '\r')));

        section.enums.Add(newEnum);
    }
Example #2
0
    void ParseNamespace(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "namespace".Length;

        string namespaceName  = ReadWord(section.data, ref caret);
        int    namespaceBegin = section.data.IndexOf('{', caret) + 1;
        string block          = ReadBlock(section.data, ref caret).Trim(' ', '\r', '\t', '\n');
        string body           = block.Substring(1, block.Length - 2).Trim(' ', '\r', '\t', '\n');

        LexNamespace newNamespace = new LexNamespace()
        {
            begin            = begin,
            end              = caret,
            data             = body,
            name             = namespaceName,
            source           = source,
            parentLexSection = section
        };

        section.childSections.Add(newNamespace);

        ParseLexSection(newNamespace, ProtectLevel.Public);
    }
Example #3
0
    void ParseIfMacro(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#if".Length;

        string skipSymbols = " \r\n\t";
        string endWord     = "#endif";

        int dataLen = section.data.Length;

        for (; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
            {
                continue;
            }

            string sub = section.data.Substring(caret, Math.Min(endWord.Length, dataLen - caret));
            if (sub == endWord)
            {
                caret = Math.Min(dataLen, caret + endWord.Length);
                return;
            }
        }
    }
Example #4
0
    void ParseFriend(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "friend".Length;
        string name  = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
        string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
    }
Example #5
0
    void ParseLexSection(LexSection section, ProtectLevel protectionLevel)
    {
        section.source = source;

        string skipSymbols = " \r\n\t";
        int    dataLen     = section.data.Length;
        int    caret       = 0;

        for (caret = 0; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
            {
                continue;
            }

            Dictionary <string, ParserFunc> keyParsers = globalKeyParsers;

            if (section.GetType() == typeof(LexClass))
            {
                keyParsers = classBodyKeyParsers;
            }

            bool passedKeyWord = false;
            foreach (var keyWordParser in keyParsers)
            {
                string sub = section.data.Substring(caret, Math.Min(keyWordParser.Key.Length, dataLen - caret));

                if (sub == keyWordParser.Key)
                {
                    keyWordParser.Value(section, ref caret, ref protectionLevel);
                    passedKeyWord = true;
                    break;
                }
            }

            if (passedKeyWord)
            {
                continue;
            }

            int    blockbegin = caret;
            string block      = ReadBlock(section.data, ref caret);
            block = block.Trim(' ', '\r', '\t', '\n');

            if (block.Length > 0)
            {
                TryParseBlock(section, block, blockbegin, ref caret, ref protectionLevel);
            }
        }

        section.functions.ForEach(x => x.comment     = section.FindComment(x.begin, x.end));
        section.variables.ForEach(x => x.comment     = section.FindComment(x.begin, x.end));
        section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
    }
Example #6
0
    void ParseSingleLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "//".Length;
        string comment = ReadWord(section.data, ref caret, "\n", "").Trim(' ', '\r');

        section.comments.Add(new LexComment()
        {
            begin   = begin,
            end     = caret,
            data    = section.data.Substring(begin, caret - begin),
            comment = comment,
            source  = source
        });
    }
Example #7
0
    void ParsePragma(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#pragma".Length;
        string word = ReadWord(section.data, ref caret);

        source.pragmas.Add(new LexPragma()
        {
            begin      = begin,
            end        = caret,
            data       = section.data.Substring(begin, caret - begin),
            pragmaWord = word,
            source     = source
        });
    }
Example #8
0
    void ParseInclude(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#include".Length;
        string word = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '"');

        source.includes.Add(new LexInclude()
        {
            begin       = begin,
            end         = caret,
            data        = section.data.Substring(begin, caret - begin),
            includeFile = word,
            source      = source
        });
    }
Example #9
0
    void ParseMultiLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "/*".Length;
        int end = section.data.IndexOf("*/", caret);

        caret = end;
        section.comments.Add(new LexComment()
        {
            begin   = begin,
            end     = end,
            data    = section.data.Substring(begin, caret - begin),
            comment = section.data.Substring(begin + 2, end - begin - 4).Trim(' ', '\r', '\t', '\n'),
            source  = source
        });
    }
Example #10
0
    void ParseTypedef(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "typedef".Length;
        string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
        string name  = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n', ';');

        section.typedefs.Add(new LexTypedef()
        {
            begin  = begin,
            end    = caret,
            data   = section.data.Substring(begin, caret - begin),
            name   = name,
            value  = value,
            source = source
        });
    }
Example #11
0
    void ParseUsing(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "using".Length;

        ReadWord(section.data, ref caret);

        string name = ReadWord(section.data, ref caret);

        section.usingNamespaces.Add(new LexUsingNamespace()
        {
            begin = begin,
            end   = caret,
            data  = section.data.Substring(begin, caret - begin),
            name  = name
        });
    }
Example #12
0
    void ParseDefine(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;

        caret += "#define".Length;

        string definition = ReadWord(section.data, ref caret);
        string next       = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '\t');

        source.defines.Add(new LexDefine()
        {
            begin      = begin,
            end        = caret,
            data       = section.data.Substring(begin, caret - begin),
            definition = definition,
            content    = next,
            source     = source
        });
    }
Example #13
0
        /// <summary>
        /// Add custom xml part into active document
        /// </summary>
        /// <param name="customXmlPartContent"></param>
        /// <param name="partId"></param>
        /// <returns></returns>
        private string AddCustomXmlPart(string customXmlPartContent, string partId)
        {
            string id = string.Empty;

            try
            {
                ProtectLevel protectLevel = CurrentTemplateInfo.ProtectLevel;
                if (protectLevel == ProtectLevel.Bookmark)
                {
                    UnprotectBookmark();
                }
                if (protectLevel == ProtectLevel.Document)
                {
                    UnprotectDocument();
                }

                if (!string.IsNullOrEmpty(partId))
                {
                    CustomXMLPart oldXmlPart = CommonProfile.ActiveDoc.CustomXMLParts.SelectByID(partId);

                    if (oldXmlPart != null)
                    {
                        oldXmlPart.Delete();
                    }
                }

                CustomXMLPart xmlPart = CommonProfile.ActiveDoc.CustomXMLParts.Add();
                xmlPart.LoadXML(customXmlPartContent);

                id = xmlPart.Id;
                if (protectLevel == ProtectLevel.Bookmark)
                {
                    ProtectBookmark();
                }
                if (protectLevel == ProtectLevel.Document)
                {
                    ProtectDocument();
                }
            }
            catch { }

            return(id);
        }
Example #14
0
        /// <summary>
        /// remove protect password in document
        /// </summary>
        /// <param name="wDoc">Word document</param>
        /// <param name="level">Level of protected to remove</param>
        /// <returns>Level of removed protection (0: bookmark, 1: document, other: -1)</returns>
        public static ProtectLevel RemoveProtectPassword(Document wDoc, ProtectLevel level)
        {
            ProtectLevel removedLevel = ProtectLevel.None;

            if (wDoc.ProtectionType == WdProtectionType.wdAllowOnlyReading)
            {
                object password = ProtectBookmarkPassword;
                if (level == ProtectLevel.Bookmark || level == ProtectLevel.All)
                {
                    wDoc.Unprotect(ref password);
                    removedLevel = ProtectLevel.Bookmark;
                }
                password = ProtectDocumentPassword;
                if (level == ProtectLevel.Document || level == ProtectLevel.All)
                {
                    wDoc.Unprotect(ref password);
                    removedLevel = ProtectLevel.Document;
                }
            }

            return(removedLevel);
        }
Example #15
0
    void ParseTemplate(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        caret += "template".Length;

        for (; caret < section.data.Length; caret++)
        {
            if (section.data[caret] == '<')
            {
                break;
            }
        }

        caret++;
        int braces = 1;
        int begin  = caret;

        for (; caret < section.data.Length; caret++)
        {
            if (section.data[caret] == '<')
            {
                braces++;
            }

            if (section.data[caret] == '>')
            {
                braces--;

                if (braces == 0)
                {
                    break;
                }
            }
        }

        string tempInside = section.data.Substring(begin, caret - begin);

        isNextLexTemplate = true;
        templatesBuffer   = tempInside;
    }
Example #16
0
        /// <summary>
        /// remove protect password in document
        /// </summary>
        /// <param name="wDoc">Word document</param>
        /// <param name="level">Level of protected to remove</param>
        /// <returns>Level of removed protection (0: bookmark, 1: document, other: -1)</returns>
        internal static ProtectLevel RemoveProtectPassword(Document wDoc, ProtectLevel level)
        {
            ProtectLevel removedLevel = ProtectLevel.None;

            if (wDoc.ProtectionType == WdProtectionType.wdAllowOnlyReading)
            {
                object password = ProtectBookmarkPassword;
                if (level == ProtectLevel.Bookmark || level == ProtectLevel.All)
                {
                    try
                    {
                        wDoc.Unprotect(ref password);
                        removedLevel = ProtectLevel.Bookmark;
                    }
                    catch (Exception ex)
                    {
                        SxLogger.LogInfo(LogLevel.Error, ex.Message);
                    }
                }
                password = ProtectDocumentPassword;
                if (level == ProtectLevel.Document || level == ProtectLevel.All)
                {
                    try
                    {
                        wDoc.Unprotect(ref password);
                        removedLevel = ProtectLevel.Document;
                    }
                    catch (Exception ex)
                    {
                        SxLogger.LogInfo(LogLevel.Error, ex.Message);
                    }
                }
            }

            return(removedLevel);
        }
Example #17
0
        /// <summary>
        /// protect document with password
        /// </summary>
        /// <param name="wDoc"></param>
        /// <param name="level"></param>
        public static void ProtectDocument(Document wDoc, ProtectLevel level)
        {
            object missing  = System.Type.Missing;
            object password = null;

            switch (level)
            {
            case ProtectLevel.All:
            case ProtectLevel.Document:
                password = ProtectDocumentPassword;
                break;

            case ProtectLevel.Bookmark:
                password = ProtectBookmarkPassword;
                break;

            default:
                break;
            }
            if (password != null)
            {
                wDoc.Protect(WdProtectionType.wdAllowOnlyReading, ref missing, ref password, ref missing, ref missing);
            }
        }
Example #18
0
    void ParseLexSection(LexSection section, ProtectLevel protectionLevel)
    {
        section.source = source;

        string skipSymbols = " \r\n\t";
        int dataLen = section.data.Length;
        int caret = 0;

        for (caret = 0; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
                continue;

            Dictionary<string, ParserFunc> keyParsers = globalKeyParsers;

            if (section.GetType() == typeof(LexClass))
                keyParsers = classBodyKeyParsers;

            bool passedKeyWord = false;
            foreach (var keyWordParser in keyParsers)
            {
                string sub = section.data.Substring(caret, Math.Min(keyWordParser.Key.Length, dataLen - caret));

                if (sub == keyWordParser.Key)
                {
                    keyWordParser.Value(section, ref caret, ref protectionLevel);
                    passedKeyWord = true;
                    break;
                }
            }

            if (passedKeyWord)
                continue;

            int blockbegin = caret;
            string block = ReadBlock(section.data, ref caret);
            block = block.Trim(' ', '\r', '\t', '\n');

            if (block.Length > 0)
                TryParseBlock(section, block, blockbegin, ref caret, ref protectionLevel);
        }

        section.functions.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
        section.variables.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
        section.unknownBlocks.ForEach(x => x.comment = section.FindComment(x.begin, x.end));
    }
Example #19
0
 void ParseClassPublic(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret          += "public:".Length;
     protectionLevel = ProtectLevel.Public;
 }
Example #20
0
 void ParseTypedef(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "typedef".Length;
     string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
     string name = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n', ';');
     section.typedefs.Add(new LexTypedef()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         name = name,
         value = value,
         source = source
     });
 }
Example #21
0
    LexVariable ParseVariable(string data, ProtectLevel protectLevel, int begin, int end)
    {
        LexVariable res = new LexVariable()
        {
            begin = begin,
            end = end,
            data = data
        };

        res.type = new LexVariableType();

        res.definition = data;

        int caret = 0;
        string typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
        string typeDefinition = typeWord;

        if (typeWord == "static")
        {
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
            typeDefinition += " " + typeWord;
            res.isStatic = true;
        }

        if (typeWord == "const")
        {
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
            res.type.isContstant = true;

            typeDefinition += " " + typeWord;
        }

        if (typeWord.Last() == '&')
            res.type.type = LexVariableType.Type.Reference;

        if (typeWord.Last() == '*')
            res.type.type = LexVariableType.Type.Pointer;

        res.type.name = typeWord;
        res.type.definition = typeDefinition;

        res.protectLevel = protectLevel;

        if (GetNextSymbol(data, caret, " \n\r\t") == '(')
        {
            string braces = ReadBraces(data, ref caret).Trim(' ', '\r', '\t', '\t', '(', ')');
            string nexBraces = ReadBraces(data, ref caret).Trim(' ', '\r', '\t', '\t', '(', ')');

            int tmpCaret = 0;
            string bracesFirst = ReadWord(braces, ref tmpCaret);
            tmpCaret += 3;
            res.name = braces.Substring(tmpCaret);

            res.type.name = res.type.name + " (" + bracesFirst + "*)(" + nexBraces + ")";
            res.type.definition = res.type.name;
        }
        else
        {
            res.name = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        return res;
    }
Example #22
0
 void ParsePragma(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "#pragma".Length;
     string word = ReadWord(section.data, ref caret);
     source.pragmas.Add(new LexPragma()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         pragmaWord = word,
         source = source
     });
 }
Example #23
0
 void ParseStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     ParseClassOrStruct(section, ref caret, ref protectionLevel, true);
 }
Example #24
0
 void ParseClassProtected(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret += "protected:".Length;
     protectionLevel = ProtectLevel.Protected;
 }
Example #25
0
 void ParseClassPublic(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret += "public:".Length;
     protectionLevel = ProtectLevel.Public;
 }
Example #26
0
    void TryParseBlock(LexSection section, string block, int blockBegin, ref int caret, ref ProtectLevel protectionLevel)
    {
        int locCaret = 0;
        bool isFunction = false;

        string firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord.Length == 0)
        {
            LexUnknown unkn = new LexUnknown()
            {
                begin = blockBegin,
                end = caret,
                data = block,
                protectLevel = protectionLevel,
                value = block
            };

            section.unknownBlocks.Add(unkn);
            return;
        }

        if (firstWord == "virtual")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord == "static")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord == "typename")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord == "inline")
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
        {
            string braces = ReadBraces(block, ref locCaret).Trim(' ', '\n', '\t', '\r', '(', ')');
            int tmpCaret = 0;
            string word = ReadWord(braces, ref tmpCaret);

            isFunction = GetNextSymbol(braces, tmpCaret, " \n\r\t") != ':';

            if (!isFunction && braces.StartsWith("std"))
                isFunction = true;
        }
        else
        {
            if (firstWord == "const")
                ReadWord(block, ref locCaret, " \n\r(){}[]");

            string thirdWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

            if (thirdWord == "operator")
                thirdWord = ReadWord(block, ref locCaret, " \n\r(){}");

            if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
                isFunction = true;
        }

        if (isFunction)
            section.functions.Add(ParseFunction(block, protectionLevel, blockBegin, caret));
        else
            section.variables.Add(ParseVariable(block, protectionLevel, blockBegin, caret));
    }
Example #27
0
    LexVariable ParseVariable(string data, ProtectLevel protectLevel, int begin, int end)
    {
        LexVariable res = new LexVariable()
        {
            begin = begin,
            end   = end,
            data  = data
        };

        res.type = new LexVariableType();

        res.definition = data;

        int    caret          = 0;
        string typeWord       = ReadWord(data, ref caret, " \n\r(){}[]");
        string typeDefinition = typeWord;

        if (typeWord == "static")
        {
            typeWord        = ReadWord(data, ref caret, " \n\r(){}[]");
            typeDefinition += " " + typeWord;
            res.isStatic    = true;
        }

        if (typeWord == "const")
        {
            typeWord             = ReadWord(data, ref caret, " \n\r(){}[]");
            res.type.isContstant = true;

            typeDefinition += " " + typeWord;
        }

        if (typeWord.Last() == '&')
        {
            res.type.type = LexVariableType.Type.Reference;
        }

        if (typeWord.Last() == '*')
        {
            res.type.type = LexVariableType.Type.Pointer;
        }

        res.type.name       = typeWord;
        res.type.definition = typeDefinition;

        res.protectLevel = protectLevel;

        if (GetNextSymbol(data, caret, " \n\r\t") == '(')
        {
            string braces    = ReadBraces(data, ref caret).Trim(' ', '\r', '\t', '\t', '(', ')');
            string nexBraces = ReadBraces(data, ref caret).Trim(' ', '\r', '\t', '\t', '(', ')');

            int    tmpCaret    = 0;
            string bracesFirst = ReadWord(braces, ref tmpCaret);
            tmpCaret += 3;
            res.name  = braces.Substring(tmpCaret);

            res.type.name       = res.type.name + " (" + bracesFirst + "*)(" + nexBraces + ")";
            res.type.definition = res.type.name;
        }
        else
        {
            res.name = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        return(res);
    }
Example #28
0
    LexFunction ParseFunction(string data, ProtectLevel protectLevel, int begin, int end)
    {
        LexFunction res = new LexFunction()
        {
            begin = begin,
            end   = end,
            data  = data
        };

        if (isNextLexTemplate)
        {
            res.isTemplate    = true;
            res.templates     = templatesBuffer;
            isNextLexTemplate = false;
        }

        res.returnType = new LexVariableType();

        res.definition   = data;
        res.protectLevel = protectLevel;

        int    caret    = 0;
        string typeWord = ReadWord(data, ref caret, " \n\r(){}[]");

        if (typeWord == "virtual")
        {
            res.isVirtual = true;
            typeWord      = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "static")
        {
            res.isStatic = true;
            typeWord     = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "inline")
        {
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "typename")
        {
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "explicit")
        {
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "operator")
        {
            string nextWord = ReadWord(data, ref caret, " \n\r(){}[]");
            res.name            = typeWord + nextWord;
            res.returnType.name = "void";
        }
        else
        {
            if (GetNextSymbol(data, caret, " \n\r\t") == '(')
            {
                res.name            = typeWord;
                res.returnType.name = "void";
            }
            else
            {
                string typeDefinition = typeWord;

                if (typeWord == "const")
                {
                    typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
                    res.returnType.isContstant = true;

                    typeDefinition += " " + typeWord;
                }

                if (typeWord.Last() == '&')
                {
                    res.returnType.type = LexVariableType.Type.Reference;
                }

                if (typeWord.Last() == '*')
                {
                    res.returnType.type = LexVariableType.Type.Pointer;
                }

                res.returnType.name       = typeWord;
                res.returnType.definition = typeDefinition;

                res.name = ReadWord(data, ref caret, " \n\r(){}[]");

                if (res.name == "operator")
                {
                    res.name += " " + ReadWord(data, ref caret, " \n\r(){}");
                }
            }
        }

        string paramsStr      = ReadBraces(data, ref caret).Trim(' ', '\n', '\r', '\t');
        string afterParamWord = ReadWord(data, ref caret);

        if (afterParamWord == "const")
        {
            res.isContstant = true;
        }

        if (paramsStr.Length > 0)
        {
            var paramsArr = Split(paramsStr, ',');
            foreach (var prm in paramsArr)
            {
                string trimmedParam = prm.Trim(' ', '\r', '\n', '\t');
                res.parameters.Add(ParseVariable(trimmedParam, ProtectLevel.Public, begin, end));
            }
        }

        return(res);
    }
Example #29
0
 void ParseStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     ParseClassOrStruct(section, ref caret, ref protectionLevel, true);
 }
Example #30
0
    void ParseClassOrStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel, bool isstruct)
    {
        int begin = caret;

        if (isstruct)
        {
            caret += "struct".Length;
        }
        else
        {
            caret += "class".Length;
        }

        string className = ReadWord(section.data, ref caret, " \n\t\r:;/");
        string afterName = ReadWord(section.data, ref caret, ";{/").Trim(' ', ':', '\r', '\n', '\t');

        string shortClassName = className;

        if (section.GetType() == typeof(LexClass))
        {
            className = (section as LexClass).name + "::" + className;
        }
        else
        {
            className = (section as LexNamespace).name + "::" + className;
        }

        LexClass newClass = new LexClass()
        {
            begin            = begin,
            end              = caret,
            data             = section.data.Substring(begin, caret - begin),
            name             = className,
            shortName        = shortClassName,
            source           = source,
            parentLexSection = section,
            protectLevel     = protectionLevel,
            haveBody         = false,
            isTemplate       = isNextLexTemplate
        };

        if (isNextLexTemplate)
        {
            newClass.templates = templatesBuffer;
        }

        isNextLexTemplate = false;

        if (afterName.Length > 0)
        {
            var baseClasses = Split(afterName, ',');

            foreach (var baseClass in baseClasses)
            {
                string trimmedBaseClass = baseClass.Trim();

                int spacePos = trimmedBaseClass.IndexOf(' ');
                if (spacePos < 0)
                {
                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type      = ProtectLevel.Private,
                        className = trimmedBaseClass
                    });
                }
                else
                {
                    string sectionTypeName = trimmedBaseClass.Substring(0, spacePos);
                    string baseClassName   = trimmedBaseClass.Substring(spacePos + 1);

                    if (baseClassName.StartsWith("virtual"))
                    {
                        baseClassName = baseClassName.Substring("virtual".Length + 1);
                    }

                    ProtectLevel sectionType = ProtectLevel.Private;

                    if (sectionTypeName == "public")
                    {
                        sectionType = ProtectLevel.Public;
                    }
                    else if (sectionTypeName == "protected")
                    {
                        sectionType = ProtectLevel.Protected;
                    }

                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type      = sectionType,
                        className = baseClassName
                    });
                }
            }
        }

        if (caret < section.data.Length && section.data[caret] == '/')
        {
            string comment = ReadWord(section.data, ref caret, "\n");
            ReadWord(section.data, ref caret, ";{/");

            newClass.comment = new LexComment()
            {
                comment = comment
            };
        }

        if (caret < section.data.Length && section.data[caret] == '{')
        {
            int sectionBegin = caret;
            newClass.data     = ReadBlock(section.data, ref caret).Trim('{', '}', ' ', '\n', '\r', '\t');
            newClass.haveBody = true;

            section.classes.Add(newClass);
            section.childSections.Add(newClass);

            ParseLexSection(newClass, isstruct ? ProtectLevel.Public : ProtectLevel.Private);
        }
    }
Example #31
0
 void ParseMultiLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "/*".Length;
     int end = section.data.IndexOf("*/", caret);
     caret = end;
     section.comments.Add(new LexComment()
     {
         begin = begin,
         end = end,
         data = section.data.Substring(begin, caret - begin),
         comment = section.data.Substring(begin + 2, end - begin - 4).Trim(' ', '\r', '\t', '\n'),
         source = source
     });
 }
Example #32
0
    void ParseDefine(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "#define".Length;

        string definition = ReadWord(section.data, ref caret);
        string next = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '\t');

        source.defines.Add(new LexDefine()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            definition = definition,
            content = next,
            source = source
        });
    }
Example #33
0
    void ParseNamespace(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "namespace".Length;

        string namespaceName = ReadWord(section.data, ref caret);
        int namespaceBegin = section.data.IndexOf('{', caret) + 1;
        string block = ReadBlock(section.data, ref caret).Trim(' ', '\r', '\t', '\n');
        string body = block.Substring(1, block.Length - 2).Trim(' ', '\r', '\t', '\n');

        LexNamespace newNamespace = new LexNamespace()
        {
            begin = begin,
            end = caret,
            data = body,
            name = namespaceName,
            source = source,
            parentLexSection = section
        };
        section.childSections.Add(newNamespace);

        ParseLexSection(newNamespace, ProtectLevel.Public);
    }
Example #34
0
    void ParseEnum(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "enum".Length;

        string name = ReadWord(section.data, ref caret);

        if (name == "class")
            name = ReadWord(section.data, ref caret);

        string block = ReadBlock(section.data, ref caret).Trim(' ', '{', '}', '\r', '\t', '\n');
        string blockWithoutComments = RemoveComments(block);
        var content = Split(blockWithoutComments, ',');

        LexEnum newEnum = new LexEnum()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            name = name
        };

        content.ForEach(x => newEnum.content.Add(x.Trim(' ', '\n', '\t', '\r')));

        section.enums.Add(newEnum);
    }
Example #35
0
 void ParseSingleLineComment(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "//".Length;
     string comment = ReadWord(section.data, ref caret, "\n", "").Trim(' ', '\r');
     section.comments.Add(new LexComment()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         comment = comment,
         source = source
     });
 }
Example #36
0
 void ParseFriend(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "friend".Length;
     string name = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
     string value = ReadWord(section.data, ref caret, " \n\r\t").Trim(' ', '\r', '\t', '\n');
 }
Example #37
0
    void ParseTemplate(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        caret += "template".Length;

        for (; caret < section.data.Length; caret++)
            if (section.data[caret] == '<')
                break;

        caret++;
        int braces = 1;
        int begin = caret;

        for (; caret < section.data.Length; caret++)
        {
            if (section.data[caret] == '<')
                braces++;

            if (section.data[caret] == '>')
            {
                braces--;

                if (braces == 0)
                    break;
            }
        }

        string tempInside = section.data.Substring(begin, caret - begin);

        isNextLexTemplate = true;
        templatesBuffer = tempInside;
    }
Example #38
0
    LexFunction ParseFunction(string data, ProtectLevel protectLevel, int begin, int end)
    {
        LexFunction res = new LexFunction()
        {
            begin = begin,
            end = end,
            data = data
        };

        if (isNextLexTemplate)
        {
            res.isTemplate = true;
            res.templates = templatesBuffer;
            isNextLexTemplate = false;
        }

        res.returnType = new LexVariableType();

        res.definition = data;
        res.protectLevel = protectLevel;

        int caret = 0;
        string typeWord = ReadWord(data, ref caret, " \n\r(){}[]");

        if (typeWord == "virtual")
        {
            res.isVirtual = true;
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "static")
        {
            res.isStatic = true;
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
        }

        if (typeWord == "inline")
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");

        if (typeWord == "typename")
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");

        if (typeWord == "explicit")
            typeWord = ReadWord(data, ref caret, " \n\r(){}[]");

        if (typeWord == "operator")
        {
            string nextWord = ReadWord(data, ref caret, " \n\r(){}[]");
            res.name = typeWord + nextWord;
            res.returnType.name = "void";
        }
        else
        {
            if (GetNextSymbol(data, caret, " \n\r\t") == '(')
            {
                res.name = typeWord;
                res.returnType.name = "void";
            }
            else
            {
                string typeDefinition = typeWord;

                if (typeWord == "const")
                {
                    typeWord = ReadWord(data, ref caret, " \n\r(){}[]");
                    res.returnType.isContstant = true;

                    typeDefinition += " " + typeWord;
                }

                if (typeWord.Last() == '&')
                    res.returnType.type = LexVariableType.Type.Reference;

                if (typeWord.Last() == '*')
                    res.returnType.type = LexVariableType.Type.Pointer;

                res.returnType.name = typeWord;
                res.returnType.definition = typeDefinition;

                res.name = ReadWord(data, ref caret, " \n\r(){}[]");

                if (res.name == "operator")
                    res.name += " " + ReadWord(data, ref caret, " \n\r(){}");
            }
        }

        string paramsStr = ReadBraces(data, ref caret).Trim(' ', '\n', '\r', '\t');
        string afterParamWord = ReadWord(data, ref caret);

        if (afterParamWord == "const")
            res.isContstant = true;

        if (paramsStr.Length > 0)
        {
            var paramsArr = Split(paramsStr, ',');
            foreach (var prm in paramsArr)
            {
                string trimmedParam = prm.Trim(' ', '\r', '\n', '\t');
                res.parameters.Add(ParseVariable(trimmedParam, ProtectLevel.Public, begin, end));
            }
        }

        return res;
    }
Example #39
0
    void ParseUsing(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "using".Length;

        ReadWord(section.data, ref caret);

        string name = ReadWord(section.data, ref caret);
        section.usingNamespaces.Add(new LexUsingNamespace()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            name = name
        });
    }
Example #40
0
    void ParseIfMacro(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
    {
        int begin = caret;
        caret += "#if".Length;

        string skipSymbols = " \r\n\t";
        string endWord = "#endif";

        int dataLen = section.data.Length;
        for (; caret < dataLen; caret++)
        {
            if (skipSymbols.Contains(section.data[caret]))
                continue;

            string sub = section.data.Substring(caret, Math.Min(endWord.Length, dataLen - caret));
            if (sub == endWord)
            {
                caret = Math.Min(dataLen, caret + endWord.Length);
                return;
            }
        }
    }
Example #41
0
    void TryParseBlock(LexSection section, string block, int blockBegin, ref int caret, ref ProtectLevel protectionLevel)
    {
        int  locCaret   = 0;
        bool isFunction = false;

        string firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

        if (firstWord.Length == 0)
        {
            LexUnknown unkn = new LexUnknown()
            {
                begin        = blockBegin,
                end          = caret,
                data         = block,
                protectLevel = protectionLevel,
                value        = block
            };

            section.unknownBlocks.Add(unkn);
            return;
        }

        if (firstWord == "virtual")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (firstWord == "static")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (firstWord == "typename")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (firstWord == "inline")
        {
            firstWord = ReadWord(block, ref locCaret, " \n\r(){}[]");
        }

        if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
        {
            string braces   = ReadBraces(block, ref locCaret).Trim(' ', '\n', '\t', '\r', '(', ')');
            int    tmpCaret = 0;
            string word     = ReadWord(braces, ref tmpCaret);

            isFunction = GetNextSymbol(braces, tmpCaret, " \n\r\t") != ':';

            if (!isFunction && braces.StartsWith("std"))
            {
                isFunction = true;
            }
        }
        else
        {
            if (firstWord == "const")
            {
                ReadWord(block, ref locCaret, " \n\r(){}[]");
            }

            string thirdWord = ReadWord(block, ref locCaret, " \n\r(){}[]");

            if (thirdWord == "operator")
            {
                thirdWord = ReadWord(block, ref locCaret, " \n\r(){}");
            }

            if (GetNextSymbol(block, locCaret, " \n\r\t") == '(')
            {
                isFunction = true;
            }
        }

        if (isFunction)
        {
            section.functions.Add(ParseFunction(block, protectionLevel, blockBegin, caret));
        }
        else
        {
            section.variables.Add(ParseVariable(block, protectionLevel, blockBegin, caret));
        }
    }
Example #42
0
 void ParseInclude(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     int begin = caret;
     caret += "#include".Length;
     string word = ReadWord(section.data, ref caret, "\n").Trim(' ', '\r', '"');
     source.includes.Add(new LexInclude()
     {
         begin = begin,
         end = caret,
         data = section.data.Substring(begin, caret - begin),
         includeFile = word,
         source = source
     });
 }
Example #43
0
    void ParseClassOrStruct(LexSection section, ref int caret, ref ProtectLevel protectionLevel, bool isstruct)
    {
        int begin = caret;

        if (isstruct) caret += "struct".Length;
        else caret += "class".Length;

        string className = ReadWord(section.data, ref caret, " \n\t\r:;/");
        string afterName = ReadWord(section.data, ref caret, ";{/").Trim(' ', ':', '\r', '\n', '\t');

        string shortClassName = className;

        if (section.GetType() == typeof(LexClass))
            className = (section as LexClass).name + "::" + className;
        else
            className = (section as LexNamespace).name + "::" + className;

        LexClass newClass = new LexClass()
        {
            begin = begin,
            end = caret,
            data = section.data.Substring(begin, caret - begin),
            name = className,
            shortName = shortClassName,
            source = source,
            parentLexSection = section,
            protectLevel = protectionLevel,
            haveBody = false,
            isTemplate = isNextLexTemplate
        };

        if (isNextLexTemplate)
            newClass.templates = templatesBuffer;

        isNextLexTemplate = false;

        if (afterName.Length > 0)
        {
            var baseClasses = Split(afterName, ',');

            foreach (var baseClass in baseClasses)
            {
                string trimmedBaseClass = baseClass.Trim();

                int spacePos = trimmedBaseClass.IndexOf(' ');
                if (spacePos < 0)
                {
                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type = ProtectLevel.Private,
                        className = trimmedBaseClass
                    });
                }
                else
                {
                    string sectionTypeName = trimmedBaseClass.Substring(0, spacePos);
                    string baseClassName = trimmedBaseClass.Substring(spacePos + 1);

                    if (baseClassName.StartsWith("virtual"))
                        baseClassName = baseClassName.Substring("virtual".Length + 1);

                    ProtectLevel sectionType = ProtectLevel.Private;

                    if (sectionTypeName == "public")
                        sectionType = ProtectLevel.Public;
                    else if (sectionTypeName == "protected")
                        sectionType = ProtectLevel.Protected;

                    newClass.baseClasses.Add(new LexClass.BaseClassDef()
                    {
                        type = sectionType,
                        className = baseClassName
                    });
                }
            }
        }

        if (caret < section.data.Length && section.data[caret] == '/')
        {
            string comment = ReadWord(section.data, ref caret, "\n");
            ReadWord(section.data, ref caret, ";{/");

            newClass.comment = new LexComment() { comment = comment };
        }

        if (caret < section.data.Length && section.data[caret] == '{')
        {
            int sectionBegin = caret;
            newClass.data = ReadBlock(section.data, ref caret).Trim('{', '}', ' ', '\n', '\r', '\t');
            newClass.haveBody = true;

            section.classes.Add(newClass);
            section.childSections.Add(newClass);

            ParseLexSection(newClass, isstruct ? ProtectLevel.Public : ProtectLevel.Private);
        }
    }
Example #44
0
 void ParseClassProtected(LexSection section, ref int caret, ref ProtectLevel protectionLevel)
 {
     caret          += "protected:".Length;
     protectionLevel = ProtectLevel.Protected;
 }