Ejemplo n.º 1
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");

            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();
        }
Ejemplo n.º 2
0
        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();
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
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.defineList.Add(name);

            w.BeginSection("define");
            w.WritePair("name", name);
            w.WritePair("linetext", value);
            w.EndSection();
        }
Ejemplo n.º 6
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(')');
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
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:
                {
                    if (_LexString == "static" || _LexString == "new")
                    {
                        PARSE_Public(w);
                        break;
                    }
                    throw new ParseException("Unrecognized token: " + tok + " " + _LexString);
                }
                }
            }
            w.EndSection();
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
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();
        }
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
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(')');
        }
Ejemplo n.º 16
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();
        }