示例#1
0
        private string[] ParseKeyedValues(VPPTextParser parser, string key)
        {
            parser.SetPosition(0);
            int defIndex;

            List <string> ret = new();

            while ((defIndex = parser.Seek(key)) != -1)
            {
                parser.Eat(key);
                parser.EatWhiteSpace();

                if (parser.Is('\"'))
                {
                    continue;
                }

                int pstart = parser.Eat('<');
                int end    = parser.EatUntil('>');
                parser.SetPosition(pstart + 1);

                ret.Add(parser.Get(end - pstart - 1));
                parser.Set(pstart, '\"');
                parser.Set(end, '\"');
            }

            return(ret.ToArray());
        }
示例#2
0
        private static bool ResolveDirective(VPPDirective directive, List <VPPMakro> makros, VPPTextParser parser)
        {
            parser.SetPosition(0);

            int idx;

            bool resolved = false;

            while ((idx = parser.Seek(directive.DirectiveName)) != -1)
            {
                parser.Eat(directive.DirectiveName);

                if (!parser.IsValidPreWordCharacter(idx - 1) ||
                    !parser.IsValidPostWordCharacter(idx + directive.DirectiveName.Length))
                {
                    continue;
                }

                parser.EatWhiteSpace();

                if (parser.Is('('))
                {
                    parser.Eat('(');
                    List <string> p   = ParseList(parser, x => x.Is(')'));
                    int           end = parser.Eat(')');
                    parser.SetPosition(idx);
                    parser.Remove(end + 1 - idx);

                    if (directive.ResolveParameters)
                    {
                        for (int i = 0; i < p.Count; i++)
                        {
                            VPPTextParser arg = new VPPTextParser(p[i]);

                            while (ResolveMakros(arg, makros))
                            {
                            }

                            p[i] = arg.ToString();
                        }
                    }

                    string resolvedString = directive.Resolve(makros, parser, p.ToArray());
                    parser.Insert(resolvedString);
                }
                else
                {
                    parser.SetPosition(idx);
                    parser.Remove(directive.DirectiveName.Length);
                    parser.Insert(directive.Resolve(makros, parser, new string[0]));
                }
                resolved = true;
            }

            return(resolved);
        }
示例#3
0
        private List <VPPMakro> ParseDefines(VPPTextParser parser)
        {
            int defIndex;

            List <VPPMakro> ret = new();

            while ((defIndex = parser.Seek("#define")) != -1)
            {
                parser.Eat("#define");
                parser.EatWhiteSpace();
                string var = parser.EatWord();
                parser.EatWhiteSpaceUntilNewLine();

                if (parser.Is('('))
                {
                    ret.Add(ParseFuncDefine(defIndex, var, parser));

                    continue;
                }

                string value = "1";

                if (parser.Is('\n'))
                {
                    parser.Eat('\n');
                    parser.RemoveReverse(defIndex);
                }
                else
                {
                    value = parser.EatUntilWhitespace();
                    parser.RemoveReverse(defIndex);
                }

                ret.Add(
                    new VPPTextMakro(var, value, new List <VPPMakroParameter>())
                    );
            }

            return(ret);
        }
示例#4
0
        private static bool ResolveMakro(VPPMakro makro, VPPTextParser parser)
        {
            parser.SetPosition(0);

            int idx;

            bool resolved = false;

            while ((idx = parser.Seek(makro.Name)) != -1)
            {
                parser.Eat(makro.Name);

                if (!parser.IsValidPreWordCharacter(idx - 1) ||
                    !parser.IsValidPostWordCharacter(idx + makro.Name.Length))
                {
                    continue;
                }

                parser.EatWhiteSpace();

                if (parser.Is('('))
                {
                    parser.Eat('(');
                    List <string> p   = ParseList(parser, x => x.Is(')'));
                    int           end = parser.Eat(')');
                    parser.SetPosition(idx);
                    parser.Remove(end + 1 - idx);
                    parser.Insert(makro.GenerateValue(p.ToArray()));
                }
                else
                {
                    parser.SetPosition(idx);
                    parser.Remove(makro.Name.Length);
                    parser.Insert(makro.GenerateValue(new string[0]));
                }

                resolved = true;
            }

            return(resolved);
        }