Beispiel #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());
        }
Beispiel #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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        private VPPMakro ParseFuncDefine(int start, string var, VPPTextParser parser)
        {
            parser.Eat('(');
            List <string> p = ParseList(parser, x => x.Is(')'));

            parser.Eat(')');

            parser.EatWhiteSpace();

            int pStart = parser.Eat('{');
            int end    = parser.FindClosing('{', '}');

            parser.SetPosition(pStart + 1);
            string block = parser.Get(end - pStart - 1).Trim();

            parser.SetPosition(start);
            parser.Remove(end + 1 - start);

            return(new VPPTextMakro(var, block, p.Select(x => new VPPMakroParameter {
                Name = x
            }).ToList()));
        }
Beispiel #5
0
        private void ApplyParameter(VPPTextParser parser, VPPMakroParameter p, string v)
        {
            parser.SetPosition(0);
            int idx;

            while ((idx = parser.Seek(p.Name)) != -1)
            {
                if (parser.IsValidPreWordCharacter(idx - 1) &&
                    parser.IsValidPostWordCharacter(idx + p.Name.Length))
                {
                    parser.Remove(p.Name.Length);
                    parser.Insert(v);
                }
                else
                {
                    parser.Eat();
                }
            }
        }