コード例 #1
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);
        }
コード例 #2
0
ファイル: VPPTextMakro.cs プロジェクト: ByteChkR/VisCPU
        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();
                }
            }
        }
コード例 #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);
        }