Exemple #1
0
        public MIFragment GetFragmentState(String fcn, Int32 lineNumber, String visitName)
        {
            void Err()
            {
                this.Error(fcn,
                           lineNumber.ToString(),
                           $"Unexpected '#parent'");
                throw new Exception($"Unexpected '#{visitName}'");
            }

            switch (this.state.Peek())
            {
            case MacroBlock mBlock:
                MIFragment f = mBlock.Item as MIFragment;
                if (f == null)
                {
                    Err();
                }
                return(f);

            default:
                Err();
                break;
            }

            return(null);
        }
Exemple #2
0
        public override object VisitTitle(MFSHParser.TitleContext context)
        {
            const String fcn = "VisitFragTitle";

            this.TraceMsg(context, fcn);
            MIFragment f = this.GetFragmentState(fcn, context.Start.Line, "Title");

            f.Title = (String)this.Visit(context.anyString());
            return(null);
        }
Exemple #3
0
        public override object VisitParent(MFSHParser.ParentContext context)
        {
            const String fcn = "VisitFragParent";

            this.TraceMsg(context, fcn);
            MIFragment f = this.GetFragmentState(fcn, context.Start.Line, "Parent");

            f.Parent = context.NAME().GetText();
            return(null);
        }
Exemple #4
0
        public void FragTest1()
        {
            {
                MFsh mfsh = CreateMfsh();
                mfsh.Load(TestFile("MFshFragTest1A.mfsh"));
                CheckErrors(mfsh);
                mfsh.Load(TestFile("MFshFragTest1B.mfsh"));
                CheckErrors(mfsh);
                mfsh.Process();
                CheckErrors(mfsh);

                Assert.True(mfsh.MacroMgr.TryGetItem("Frag1", out MIApplicable item));
                MIFragment frag = (MIFragment)item;
                Assert.True(frag.Name == "Frag1");
                Assert.True(frag.Parent == "Observation");
                Assert.True(frag.Title == "Frag1 Title");
                Assert.True(frag.Description == "Frag1 Description");

                StringBuilder sb = new StringBuilder();
                sb.Append("Line 1\n");
                sb.Append("Line 2\n");
                sb.Append("Line 3\n");
                Assert.True(mfsh.TryGetTextByRelativePath("MFshFragTest1B.fsh", out String fsh));
                Assert.True(fsh == sb.ToString());
            }

            {
                MFsh mfsh = CreateMfsh();
                mfsh.Load(TestFile("MFshFragTest1A.mfsh"));
                CheckErrors(mfsh);
                mfsh.Load(TestFile("MFshFragTest1C.mfsh"));
                CheckErrors(mfsh);
                mfsh.Process();
                CheckErrors(mfsh);

                StringBuilder sb = new StringBuilder();
                sb.Append("Line 1\n");
                sb.Append("Line 2\n");
                sb.Append("Line 2\n");
                sb.Append("Line 2\n");
                sb.Append("Line 2\n");
                sb.Append("Line 3\n");
                Assert.True(mfsh.TryGetTextByRelativePath("MFshFragTest1C.fsh", out String fsh));
                Assert.True(fsh == sb.ToString());
            }
        }
Exemple #5
0
        public override object VisitFrag(MFSHParser.FragContext context)
        {
            const String fcn = "VisitFrag";

            this.TraceMsg(context, fcn);
            String fragName = context.NAME().GetText();

            String fragmentDefinition = String.Empty;

            MIFragment frag       = new MIFragment(this.SourceName, context.Start.Line, fragName);
            MacroBlock macroBlock = new MacroBlock("frag", frag);

            frag.OnceFlag = context.ONCE() != null;

            this.PushState(macroBlock);

            return(null);
        }