コード例 #1
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Public(ParseWriter w)
        {
            MatchToken(LexToken.TOKEN_CONST);

            /* Eat up an optional tag */
            MatchToken(LexToken.TOKEN_LABEL);

            /* Eat up a name */
            NeedToken(LexToken.TOKEN_SYMBOL);

            while (MatchChar('['))
            {
                DiscardUntilChar(']');
                NeedChar(']');
            }

            if (MatchChar('='))
            {
                ignore_block();
            }
            else if (MatchChar('(') && MatchChar(')'))
            {
                ignore_block();
                return;
            }

            NeedChar(';');
        }
コード例 #2
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_FuncTag(ParseWriter w)
        {
            w.BeginSection("functag");

            if (MatchToken(LexToken.TOKEN_PUBLIC))
            {
                w.WritePair("type", "public");
            }
            else if (MatchToken(LexToken.TOKEN_STOCK))
            {
                w.WritePair("type", "stock");
            }

            if (MatchToken(LexToken.TOKEN_LABEL))
            {
                w.WritePair("return", LexString);
            }

            /* Get the functag name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            w.WritePair("name", LexString);
            w.functagList.Add(LexString);

            ParseParameters(w);
            NeedChar(';');

            w.EndSection();
        }
コード例 #3
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Include(ParseWriter w)
        {
            /* read until the end of the line */
            int    index = Contents.ToString().IndexOf('\n');
            string value;

            if (index == -1)
            {
                value = Contents.ToString();
                Contents.Remove(0, value.Length);
            }
            else if (index == 0)
            {
                value = "";
            }
            else
            {
                value = Contents.ToString().Substring(0, index);
                Contents.Remove(0, index);
            }

            /* Strip whitespace */
            value = value.Trim('\r', '\t', ' ');

            /* Write */
            w.BeginSection("include");
            w.WritePair("name", value);
            w.EndSection();
        }
コード例 #4
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Enum(ParseWriter w)
        {
            string name = "";

            if (MatchToken(LexToken.TOKEN_SYMBOL))
            {
                name = LexString;
            }

            w.BeginSection("enum");
            w.WritePair("name", name);
            w.BeginSection("properties");

            w.enumList.Add(name);

            NeedChar('{');
            bool more_entries    = true;
            bool need_closebrace = true;

            if (MatchToken(LexToken.TOKEN_DOCBLOCK))
            {
                w.WritePair("doc", LexString);
            }

            do
            {
                if (MatchChar('}'))
                {
                    need_closebrace = false;
                    break;
                }
                NeedToken(LexToken.TOKEN_SYMBOL);
                name = LexString;

                if (MatchChar('='))
                {
                    DiscardUntilCharOrComment(",\n}", true);
                }
                more_entries = MatchChar(',');
                w.WritePair("name", name);
                w.enumTypeList.Add(name);
                if (MatchToken(LexToken.TOKEN_DOCBLOCK))
                {
                    w.WritePair("doc", LexString);
                }
            } while (more_entries);
            if (need_closebrace)
            {
                NeedChar('}');
            }
            NeedChar(';');
            w.EndSection();
            w.EndSection();
        }
コード例 #5
0
        private void PARSE_Public(ParseWriter w)
        {
            /* Eat up an optional tag */
            MatchToken(LexToken.TOKEN_LABEL);

            /* Eat up a name */
            NeedToken(LexToken.TOKEN_SYMBOL);

            if (MatchChar('='))
            {
                ignore_block();
            }

            NeedChar(';');
        }
コード例 #6
0
        static int SubMain(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: incparser <infile>");
                return(1);
            }

            IncParser inc = null;

            try
            {
                inc = new IncParser(args[0]);
            }
            catch (ParseException e)
            {
                Console.WriteLine("Initial browsing failed: " + e.Message);
                return(1);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Failed to read file: " + e.Message);
                return(1);
            }

            ParseWriter pw = new ParseWriter();

            try
            {
                inc.Parse(pw);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
                return(1);
            }

            if (pw.Level != 0)
            {
                Console.WriteLine("Fatal parse error detected; unable to complete output.");
                return(1);
            }

            Console.Write(pw.Contents);
            Console.Write("\n");

            return(0);
        }
コード例 #7
0
        static int SubMain(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: incparser <infile>");
                return 1;
            }

            IncParser inc = null;
            try
            {
                inc = new IncParser(args[0]);
            }
            catch (ParseException e)
            {
                Console.WriteLine("Initial browsing failed: " + e.Message);
                return 1;
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Failed to read file: " + e.Message);
                return 1;
            }

            ParseWriter pw = new ParseWriter();

            try
            {
                inc.Parse(pw);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
                return 1;
            }

            if (pw.Level != 0)
            {
                Console.WriteLine("Fatal parse error detected; unable to complete output.");
                return 1;
            }

            Console.Write(pw.Contents);
            Console.Write("\n");

            return 0;
        }
コード例 #8
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Function(LexToken tok, ParseWriter w, string tag, string name)
        {
            if (tok == LexToken.TOKEN_FORWARD)
            {
                w.BeginSection("forward");
                w.forwardList.Add(name);
            }
            else if (tok == LexToken.TOKEN_NATIVE)
            {
                w.BeginSection("native");
                w.nativeList.Add(name);
            }
            else if (tok == LexToken.TOKEN_STOCK)
            {
                w.BeginSection("stock");
                w.stockList.Add(name);
            }

            w.WritePair("name", name);

            if (tag.Length > 0)
            {
                w.WritePair("return", tag);
            }

            ParseParameters(w);

            if (tok == LexToken.TOKEN_STOCK)
            {
                ignore_block();
            }
            else
            {
                /* Make sure there's a semicolon */
                if (MatchChar('='))
                {
                    DiscardUntilCharOrComment(';', false);
                }
                NeedChar(';');
            }

            w.EndSection();
        }
コード例 #9
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Define(ParseWriter w)
        {
            /* first, get the symbol name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            string name = LexString;
            string value;

            /* read until we hit the end of a line OR a comment */
            int endpoint = -1;

            for (int i = 0; i < Contents.Length; i++)
            {
                if (Contents[i] == '\n')
                {
                    endpoint = i;
                    break;
                }
                else if (CheckString(i, "/**"))
                {
                    endpoint = i;
                    break;
                }
            }

            if (endpoint < 1)
            {
                value = "";
            }
            else
            {
                value = Contents.ToString().Substring(0, endpoint);
                Contents.Remove(0, endpoint);
            }

            /* Write */
            w.defineList.Add(name);

            w.BeginSection("define");
            w.WritePair("name", name);
            w.WritePair("linetext", value);
            w.EndSection();
        }
コード例 #10
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Struct(ParseWriter w)
        {
            /* For now, we completely ignore these (they're not written to the output) */
            NeedToken(LexToken.TOKEN_SYMBOL);
            w.structList.Add(LexString);
            NeedChar('{');

            bool need_closebrace = true;
            bool more_entries    = true;

            do
            {
                if (MatchChar('}'))
                {
                    need_closebrace = false;
                    break;
                }
                MatchToken(LexToken.TOKEN_CONST);
                MatchToken(LexToken.TOKEN_LABEL);
                NeedToken(LexToken.TOKEN_SYMBOL);
                while (MatchChar('['))
                {
                    DiscardUntilChar(']');
                    NeedChar(']');
                }
                more_entries = MatchChar(',');
                MatchToken(LexToken.TOKEN_DOCBLOCK);
                if (!more_entries)
                {
                    break;
                }
            } while (true);
            if (need_closebrace)
            {
                NeedChar('}');
            }
            NeedChar(';');
        }
コード例 #11
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_Function(LexToken tok, ParseWriter w)
        {
            string tag = "", name;

            /* Get the return value */
            if (MatchToken(LexToken.TOKEN_LABEL))
            {
                tag = LexString;
            }

            if (MatchToken(LexToken.TOKEN_OPERATOR))
            {
                /* Check if we're some sort of invalid function */
                DiscardUntilCharOrComment('(', false);
                ParseParameters(null);
                if (tok == LexToken.TOKEN_STOCK)
                {
                    ignore_block();
                }
                else if (tok == LexToken.TOKEN_NATIVE || tok == LexToken.TOKEN_FORWARD)
                {
                    if (MatchChar('='))
                    {
                        DiscardUntilCharOrComment(';', false);
                    }
                    NeedChar(';');
                }
                return;
            }

            /* Get the name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            name = LexString;

            PARSE_Function(tok, w, tag, name);
        }
コード例 #12
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void ParseParameters(ParseWriter w)
        {
            NeedChar('(');
            string extra;

            do
            {
                if (MatchChar(')'))
                {
                    return;
                }

                /* Start the parameter */
                if (w != null)
                {
                    w.BeginSection("parameter");
                }

                /* Check for a 'const' token */
                if (MatchToken(LexToken.TOKEN_CONST) && w != null)
                {
                    w.WritePair("const", "true");
                }

                /* Check if it's by reference */
                if (MatchChar('&') && w != null)
                {
                    w.WritePair("byref", "true");
                }

                /* Check for a tag */
                if (MatchToken(LexToken.TOKEN_LABEL) && w != null)
                {
                    w.WritePair("tag", LexString);
                }

                /* Get the symbol and write it */
                if (MatchString(0, "...") && w != null)
                {
                    w.WritePair("name", "...");
                }
                else
                {
                    NeedToken(LexToken.TOKEN_SYMBOL);
                    if (w != null)
                    {
                        w.WritePair("name", LexString);
                    }
                }

                /* Check if we have a default value yet */
                bool default_value = false;
                if (MatchChar('='))
                {
                    default_value = true;
                }
                else if (MatchChar('['))
                {
                    extra = "";
                    string temp;
                    do
                    {
                        extra += "[";
                        temp   = ConsumeUntilChar(']');
                        if (temp != null)
                        {
                            extra += temp;
                        }
                        extra += "]";
                        NeedChar(']');
                    } while (MatchChar('['));
                    w.WritePair("decoration", extra);
                }

                /* If we have a default value, get it */
                if (default_value || MatchChar('='))
                {
                    if ((extra = ConsumeParamDefValue()) == null)
                    {
                        throw new ParseException("Expected a default value; found none");
                    }
                    if (w != null)
                    {
                        w.WritePair("defval", extra);
                    }
                }

                /* End the parameter */
                if (w != null)
                {
                    w.EndSection();
                }

                if (!MatchChar(','))
                {
                    break;
                }
            } while (true);

            NeedChar(')');
        }
コード例 #13
0
        private void PARSE_Include(ParseWriter w)
        {
            /* read until the end of the line */
            int index = Contents.ToString().IndexOf('\n');
            string value;
            if (index == -1)
            {
                value = Contents.ToString();
                Contents.Remove(0, value.Length);
            }
            else if (index == 0)
            {
                value = "";
            }
            else
            {
                value = Contents.ToString().Substring(0, index);
                Contents.Remove(0, index);
            }

            /* Strip whitespace */
            value = value.Trim('\r', '\t', ' ');

            /* Write */
            w.BeginSection("include");
            w.WritePair("name", value);
            w.EndSection();
        }
コード例 #14
0
        private void PARSE_Public(ParseWriter w)
        {
            /* Eat up an optional tag */
            MatchToken(LexToken.TOKEN_LABEL);

            /* Eat up a name */
            NeedToken(LexToken.TOKEN_SYMBOL);

            if (MatchChar('='))
            {
                ignore_block();
            }

            NeedChar(';');
        }
コード例 #15
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        private void PARSE_FuncEnum(ParseWriter w)
        {
            w.BeginSection("funcenum");

            /* Get the functag name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            w.WritePair("name", LexString);
            w.funcenumList.Add(LexString);

            NeedChar('{');

            bool need_closebrace = true;

            do
            {
                /* Shortcut out? */
                if (MatchChar('}'))
                {
                    need_closebrace = false;
                    break;
                }

                /* Start function section */
                w.BeginSection("function");

                if (MatchToken(LexToken.TOKEN_DOCBLOCK))
                {
                    w.WritePair("doc", LexString);
                }

                /* Get the return tag */
                if (MatchToken(LexToken.TOKEN_LABEL))
                {
                    w.WritePair("return", LexString);
                }

                /* Get function type */
                if (MatchToken(LexToken.TOKEN_PUBLIC))
                {
                    w.WritePair("type", "public");
                }
                else if (MatchToken(LexToken.TOKEN_STOCK))
                {
                    w.WritePair("type", "stock");
                }

                /* Parse the parameters */
                ParseParameters(w);

                /* End the section */
                w.EndSection();

                if (!MatchChar(','))
                {
                    break;
                }
            } while (true);

            if (need_closebrace)
            {
                NeedChar('}');
            }
            NeedChar(';');

            w.EndSection();
        }
コード例 #16
0
        private void PARSE_Struct(ParseWriter w)
        {
            /* For now, we completely ignore these (they're not written to the output) */
            NeedToken(LexToken.TOKEN_SYMBOL);
            NeedChar('{');

            bool need_closebrace = true;
            bool more_entries = true;
            do
            {
                if (MatchChar('}'))
                {
                    need_closebrace = false;
                    break;
                }
                MatchToken(LexToken.TOKEN_CONST);
                MatchToken(LexToken.TOKEN_LABEL);
                NeedToken(LexToken.TOKEN_SYMBOL);
                while (MatchChar('['))
                {
                    DiscardUntilChar(']');
                    NeedChar(']');
                }
                more_entries = MatchChar(',');
                MatchToken(LexToken.TOKEN_DOCBLOCK);
                if (!more_entries)
                {
                    break;
                }
            } while (true);
            if (need_closebrace)
            {
                NeedChar('}');
            }
            NeedChar(';');
        }
コード例 #17
0
        private void PARSE_FuncEnum(ParseWriter w)
        {
            w.BeginSection("funcenum");

            /* Get the functag name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            w.WritePair("name", LexString);

            NeedChar('{');

            bool need_closebrace = true;
            do
            {
                /* Shortcut out? */
                if (MatchChar('}'))
                {
                    need_closebrace = false;
                    break;
                }

                /* Start function section */
                w.BeginSection("function");

                if (MatchToken(LexToken.TOKEN_DOCBLOCK))
                {
                    w.WritePair("doc", LexString);
                }

                /* Get the return tag */
                if (MatchToken(LexToken.TOKEN_LABEL))
                {
                    w.WritePair("return", LexString);
                }

                /* Get function type */
                if (MatchToken(LexToken.TOKEN_PUBLIC))
                {
                    w.WritePair("type", "public");
                }
                else if (MatchToken(LexToken.TOKEN_STOCK))
                {
                    w.WritePair("type", "stock");
                }

                /* Parse the parameters */
                ParseParameters(w);

                /* End the section */
                w.EndSection();

                if (!MatchChar(','))
                {
                    break;
                }
            } while (true);

            if (need_closebrace)
            {
                NeedChar('}');
            }
            NeedChar(';');

            w.EndSection();
        }
コード例 #18
0
        private void ParseParameters(ParseWriter w)
        {
            NeedChar('(');
            string extra;
            do
            {
                if (MatchChar(')'))
                {
                    return;
                }

                /* Start the parameter */
                if (w != null)
                {
                    w.BeginSection("parameter");
                }

                /* Check for a 'const' token */
                if (MatchToken(LexToken.TOKEN_CONST) && w != null)
                {
                    w.WritePair("const", "true");
                }

                /* Check if it's by reference */
                if (MatchChar('&') && w != null)
                {
                    w.WritePair("byref", "true");
                }

                /* Check for a tag */
                if (MatchToken(LexToken.TOKEN_LABEL) && w != null)
                {
                    w.WritePair("tag", LexString);
                }

                /* Get the symbol and write it */
                if (MatchString(0, "...") && w != null)
                {
                    w.WritePair("name", "...");
                }
                else
                {
                    NeedToken(LexToken.TOKEN_SYMBOL);
                    if (w != null)
                    {
                        w.WritePair("name", LexString);
                    }
                }

                /* Check if we have a default value yet */
                bool default_value = false;
                if (MatchChar('='))
                {
                    default_value = true;
                }
                else if (MatchChar('['))
                {
                    extra = "";
                    string temp;
                    do
                    {
                        extra += "[";
                        temp = ConsumeUntilChar(']');
                        if (temp != null)
                        {
                            extra += temp;
                        }
                        extra += "]";
                        NeedChar(']');
                    } while (MatchChar('['));
                    w.WritePair("decoration", extra);
                }

                /* If we have a default value, get it */
                if (default_value || MatchChar('='))
                {
                    if ((extra = ConsumeParamDefValue()) == null)
                    {
                        throw new ParseException("Expected a default value; found none");
                    }
                    if (w != null)
                    {
                        w.WritePair("defval", extra);
                    }
                }

                /* End the parameter */
                if (w != null)
                {
                    w.EndSection();
                }

                if (!MatchChar(','))
                {
                    break;
                }
            } while (true);

            NeedChar(')');
        }
コード例 #19
0
ファイル: IncParser.cs プロジェクト: angryzor/sourcemod-v8
        public void Parse(ParseWriter w)
        {
            w.BeginSection(System.IO.Path.GetFileName(FileName));
            LexToken tok = LexToken.TOKEN_NONE;

            while ((tok = lex()) != LexToken.TOKEN_EOF)
            {
                switch (tok)
                {
                case LexToken.TOKEN_DOCBLOCK:
                {
                    w.WritePair("doc", LexString);
                    break;
                }

                case LexToken.TOKEN_DEFINE:
                {
                    PARSE_Define(w);
                    break;
                }

                case LexToken.TOKEN_ENUM:
                {
                    PARSE_Enum(w);
                    break;
                }

                case LexToken.TOKEN_FORWARD:
                {
                    PARSE_Function(tok, w);
                    break;
                }

                case LexToken.TOKEN_NATIVE:
                {
                    PARSE_Function(tok, w);
                    break;
                }

                case LexToken.TOKEN_STOCK:
                {
                    PARSE_Function(tok, w);
                    break;
                }

                case LexToken.TOKEN_FUNCTAG:
                {
                    PARSE_FuncTag(w);
                    break;
                }

                case LexToken.TOKEN_FUNCENUM:
                {
                    PARSE_FuncEnum(w);
                    break;
                }

                case LexToken.TOKEN_INCLUDE:
                {
                    PARSE_Include(w);
                    break;
                }

                case LexToken.TOKEN_STRUCT:
                {
                    PARSE_Struct(w);
                    break;
                }

                case LexToken.TOKEN_PUBLIC:
                {
                    PARSE_Public(w);
                    break;
                }

                default:
                {
                    if (_LexString == "static" || _LexString == "new")
                    {
                        PARSE_Public(w);
                        break;
                    }
                    throw new ParseException("Unrecognized token: " + tok + " " + _LexString);
                }
                }
            }
            w.EndSection();
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: 404UserNotFound/sourcemod
        static int SubMain(string[] args)
        {
            string directory = ".";
            string template = "template.txt";
            string outputfile = "output.txt";
            string file = null;

            if (args.Length == 0 || (args.Length == 1 && args[0] == "-h"))
            {
                PrintHelp();
                return 0;
            }

            for (int i=0; i<args.Length-1; i++)
            {
                if (args[i] == "-d")
                {
                    directory = args[i + 1];
                }

                if (args[i] == "-t")
                {
                    template = args[i + 1];
                }

                if (args[i] == "-o")
                {
                    outputfile = args[i + 1];
                }

                if (args[i] == "-f")
                {
                    file = args[i + 1];
                }

                if (args[i] == "-h")
                {
                    if (args[i + 1] == "template")
                    {
                        PrintTemplateHelp();
                        return 0;
                    }
                    PrintHelp();
                    return 0;
                }
            }

            IncParser inc = null;

            if (file == null)
            {
                DirectoryInfo di = new DirectoryInfo(directory);
                FileInfo[] rgFiles = di.GetFiles("*.inc");

                ParseWriter pwr = new ParseWriter();

                foreach (FileInfo fi in rgFiles)
                {
                    pwr.Reset();

                    Console.Write("Parsing file: " + fi.ToString() + "... ");

                    try
                    {
                      inc = new IncParser(fi.FullName);
                    }
                    catch (ParseException e)
                    {
                        Console.WriteLine("Initial browsing failed: " + e.Message);
                        continue;
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine("Failed to read file: " + e.Message);
                        continue;
                    }

                    try
                    {
                        inc.Parse(pwr);
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
                        continue;
                    }

                    if (pwr.Level != 0)
                    {
                        Console.WriteLine("Fatal parse error detected; unable to complete output.");
                        continue;
                    }

                    Console.WriteLine("Complete!");
                 }

                 pwr.WriteFiles(template, outputfile);

                 Console.WriteLine("Parsing Complete!");

                 return 0;
            }

            try
            {
                inc = new IncParser(file);
            }
            catch (ParseException e)
            {
                Console.WriteLine("Initial browsing failed: " + e.Message);
                return 1;
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Failed to read file: " + e.Message);
                return 1;
            }

            ParseWriter pw = new ParseWriter();

            try
            {
                inc.Parse(pw);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
                return 1;
            }

            if (pw.Level != 0)
            {
                Console.WriteLine("Fatal parse error detected; unable to complete output.");
                return 1;
            }

            Console.Write(pw.Contents);
            Console.Write("\n");

            return 0;
        }
コード例 #21
0
        private void PARSE_Define(ParseWriter w)
        {
            /* first, get the symbol name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            string name = LexString;
            string value;

            /* read until we hit the end of a line OR a comment */
            int endpoint = -1;
            for (int i = 0; i < Contents.Length; i++)
            {
                if (Contents[i] == '\n')
                {
                    endpoint = i;
                    break;
                }
                else if (CheckString(i, "/**"))
                {
                    endpoint = i;
                    break;
                }
            }

            if (endpoint < 1)
            {
                value = "";
            }
            else
            {
                value = Contents.ToString().Substring(0, endpoint);
                Contents.Remove(0, endpoint);
            }

            /* Write */
            w.BeginSection("define");
            w.WritePair("name", name);
            w.WritePair("linetext", value);
            w.EndSection();
        }
コード例 #22
0
        private void PARSE_Function(LexToken tok, ParseWriter w)
        {
            string tag="", name;

            /* Get the return value */
            if (MatchToken(LexToken.TOKEN_LABEL))
            {
                tag = LexString;
            }

            if (MatchToken(LexToken.TOKEN_OPERATOR))
            {
                /* Check if we're some sort of invalid function */
                DiscardUntilCharOrComment('(', false);
                ParseParameters(null);
                if (tok == LexToken.TOKEN_STOCK)
                {
                    ignore_block();
                }
                else if (tok == LexToken.TOKEN_NATIVE || tok == LexToken.TOKEN_FORWARD)
                {
                    if (MatchChar('='))
                    {
                        DiscardUntilCharOrComment(';', false);
                    }
                    NeedChar(';');
                }
                return;
            }

            /* Get the name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            name = LexString;

            PARSE_Function(tok, w, tag, name);
        }
コード例 #23
0
        private void PARSE_FuncTag(ParseWriter w)
        {
            w.BeginSection("functag");

            /* Get the functag name */
            NeedToken(LexToken.TOKEN_SYMBOL);
            w.WritePair("name", LexString);

            if (MatchToken(LexToken.TOKEN_LABEL))
            {
                w.WritePair("return", LexString);
            }

            if (MatchToken(LexToken.TOKEN_PUBLIC))
            {
                w.WritePair("type", "public");
            }
            else if (MatchToken(LexToken.TOKEN_STOCK))
            {
                w.WritePair("type", "stock");
            }

            ParseParameters(w);
            NeedChar(';');

            w.EndSection();
        }
コード例 #24
0
        private void PARSE_Public(ParseWriter w)
        {
            MatchToken(LexToken.TOKEN_CONST);

            /* Eat up an optional tag */
            MatchToken(LexToken.TOKEN_LABEL);

            /* Eat up a name */
            NeedToken(LexToken.TOKEN_SYMBOL);

            while (MatchChar('['))
            {
                DiscardUntilChar(']');
                NeedChar(']');
            }

            if (MatchChar('='))
            {
                ignore_block();
            }
            else if (MatchChar('(') && MatchChar(')'))
            {
                ignore_block();
                return;
            }

            NeedChar(';');
        }
コード例 #25
0
 public void Parse(ParseWriter w)
 {
     w.BeginSection(System.IO.Path.GetFileName(FileName));
     LexToken tok = LexToken.TOKEN_NONE;
     while ((tok = lex()) != LexToken.TOKEN_EOF)
     {
         switch (tok)
         {
             case LexToken.TOKEN_DOCBLOCK:
                 {
                     w.WritePair("doc", LexString);
                     break;
                 }
             case LexToken.TOKEN_DEFINE:
                 {
                     PARSE_Define(w);
                     break;
                 }
             case LexToken.TOKEN_ENUM:
                 {
                     PARSE_Enum(w);
                     break;
                 }
             case LexToken.TOKEN_FORWARD:
                 {
                     PARSE_Function(tok, w);
                     break;
                 }
             case LexToken.TOKEN_NATIVE:
                 {
                     PARSE_Function(tok, w);
                     break;
                 }
             case LexToken.TOKEN_STOCK:
                 {
                     PARSE_Function(tok, w);
                     break;
                 }
             case LexToken.TOKEN_FUNCTAG:
                 {
                     PARSE_FuncTag(w);
                     break;
                 }
             case LexToken.TOKEN_FUNCENUM:
                 {
                     PARSE_FuncEnum(w);
                     break;
                 }
             case LexToken.TOKEN_INCLUDE:
                 {
                     PARSE_Include(w);
                     break;
                 }
             case LexToken.TOKEN_STRUCT:
                 {
                     PARSE_Struct(w);
                     break;
                 }
             case LexToken.TOKEN_PUBLIC:
                 {
                     PARSE_Public(w);
                     break;
                 }
             default:
                 {
                     throw new ParseException("Unrecognized token: " + tok);
                 }
         }
     }
     w.EndSection();
 }
コード例 #26
0
        private void PARSE_Enum(ParseWriter w)
        {
            string name = "";
            if (MatchToken(LexToken.TOKEN_SYMBOL))
            {
                name = LexString;
            }

            w.BeginSection("enum");
            w.WritePair("name", name);
            w.BeginSection("properties");

            NeedChar('{');
            bool more_entries = true;
            bool need_closebrace = true;
            do
            {
                if (MatchChar('}'))
                {
                    need_closebrace = false;
                    break;
                }
                NeedToken(LexToken.TOKEN_SYMBOL);
                name = LexString;
                if (MatchChar('='))
                {
                    DiscardUntilCharOrComment(',', true);
                }
                more_entries = MatchChar(',');
                w.WritePair("name", name);
                if (MatchToken(LexToken.TOKEN_DOCBLOCK))
                {
                    w.WritePair("doc", LexString);
                }
            } while (more_entries);
            if (need_closebrace)
            {
                NeedChar('}');
            }
            NeedChar(';');
            w.EndSection();
            w.EndSection();
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: angryzor/sourcemod-v8
        static int SubMain(string[] args)
        {
            string directory  = ".";
            string template   = "template.txt";
            string outputfile = "output.txt";
            string file       = null;

            if (args.Length == 0 || (args.Length == 1 && args[0] == "-h"))
            {
                PrintHelp();
                return(0);
            }

            for (int i = 0; i < args.Length - 1; i++)
            {
                if (args[i] == "-d")
                {
                    directory = args[i + 1];
                }

                if (args[i] == "-t")
                {
                    template = args[i + 1];
                }

                if (args[i] == "-o")
                {
                    outputfile = args[i + 1];
                }

                if (args[i] == "-f")
                {
                    file = args[i + 1];
                }

                if (args[i] == "-h")
                {
                    if (args[i + 1] == "template")
                    {
                        PrintTemplateHelp();
                        return(0);
                    }
                    PrintHelp();
                    return(0);
                }
            }

            IncParser inc = null;

            if (file == null)
            {
                DirectoryInfo di      = new DirectoryInfo(directory);
                FileInfo[]    rgFiles = di.GetFiles("*.inc");

                ParseWriter pwr = new ParseWriter();

                foreach (FileInfo fi in rgFiles)
                {
                    pwr.Reset();

                    Console.Write("Parsing file: " + fi.ToString() + "... ");

                    try
                    {
                        inc = new IncParser(fi.FullName);
                    }
                    catch (ParseException e)
                    {
                        Console.WriteLine("Initial browsing failed: " + e.Message);
                        continue;
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine("Failed to read file: " + e.Message);
                        continue;
                    }

                    try
                    {
                        inc.Parse(pwr);
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
                        continue;
                    }

                    if (pwr.Level != 0)
                    {
                        Console.WriteLine("Fatal parse error detected; unable to complete output.");
                        continue;
                    }

                    Console.WriteLine("Complete!");
                }

                pwr.WriteFiles(template, outputfile);

                Console.WriteLine("Parsing Complete!");

                return(0);
            }

            try
            {
                inc = new IncParser(file);
            }
            catch (ParseException e)
            {
                Console.WriteLine("Initial browsing failed: " + e.Message);
                return(1);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Failed to read file: " + e.Message);
                return(1);
            }

            ParseWriter pw = new ParseWriter();

            try
            {
                inc.Parse(pw);
            }
            catch (System.Exception e)
            {
                Console.WriteLine("Error parsing file (line " + inc.GetLineNumber() + "): " + e.Message);
                return(1);
            }

            if (pw.Level != 0)
            {
                Console.WriteLine("Fatal parse error detected; unable to complete output.");
                return(1);
            }

            Console.Write(pw.Contents);
            Console.Write("\n");

            return(0);
        }
コード例 #28
0
        private void PARSE_Function(LexToken tok, ParseWriter w, string tag, string name)
        {
            if (tok == LexToken.TOKEN_FORWARD)
            {
                w.BeginSection("forward");
            }
            else if (tok == LexToken.TOKEN_NATIVE)
            {
                w.BeginSection("native");
            }
            else if (tok == LexToken.TOKEN_STOCK)
            {
                w.BeginSection("stock");
            }

            w.WritePair("name", name);

            if (tag.Length > 0)
            {
                w.WritePair("return", tag);
            }

            ParseParameters(w);

            if (tok == LexToken.TOKEN_STOCK)
            {
                ignore_block();
            }
            else
            {
                /* Make sure there's a semicolon */
                if (MatchChar('='))
                {
                    DiscardUntilCharOrComment(';', false);
                }
                NeedChar(';');
            }

            w.EndSection();
        }