Example #1
0
        protected static void VerifyFragment(GenDataBase genData, GenFragment genFragment, string expectedClass, FragmentType expectedType, string profileLabel, string profileText, string expected, bool isText, string parentClassName, GenDataDef profileDataDef)
        {
            Assert.AreEqual(expectedClass, genFragment.GetType().Name, "Fragment Class");
            Assert.AreEqual(expectedType, genFragment.Fragment.FragmentType, "Fragment Fragment Type");
            Assert.AreEqual(expectedType, genFragment.FragmentType, "Fragment Type");
            Assert.AreEqual(isText, genFragment.IsTextFragment, "Is text fragment?");
            if (genFragment.GenObject == null)
            {
                genFragment.GenObject = GetFirstObjectOfSubClass(GetFirstObject(genData), "Property");
            }
            var fragment = genFragment.Fragment;

            Assert.AreEqual(expected, GenFragmentExpander.Expand(genData.GenDataDef, genFragment.GenObject, fragment), "Expanded fragment");
            var genFragmentLabel = new GenFragmentLabel(fragment);

            Assert.AreEqual(profileLabel, genFragmentLabel.ProfileLabel(), "Profile label");
            Assert.AreEqual(profileText, genFragment.ProfileText(ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary), "Profile text");
            if (parentClassName != null)
            {
                Assert.AreEqual(parentClassName, genFragment.Fragment.ClassName(), "Parent Class ID");
            }
            var str = GenerateFragment(genData, genFragment);

            Assert.AreEqual(expected, str);
            var genDataDef = genData.GenDataDef;

            ValidateFragmentData(genDataDef, parentClassName, genFragment, profileDataDef);
        }
        private GenFragment ScanLookup(GenContainerFragmentBase parentContainer, bool isPrimary)
        {
            var s      = Scan.ScanLookup();
            var lookup =
                new GenLookup(new GenLookupParams(GenDataDef, parentContainer, s, isPrimary));
            GenFragment frag = lookup;

            ScanBody(lookup.ClassId, lookup.Body, lookup, lookup.Lookup);
            return(frag);
        }
        private GenFragment ScanSegment(GenContainerFragmentBase parentContainer, bool isPrimary)
        {
            var s   = Scan.ScanSegmentClass();
            var seg =
                ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary.ParseSegmentHeading(
                    GenDataDef, s, parentContainer, isPrimary);
            GenFragment frag = seg;

            ScanBody(seg.ClassId, seg.Body, seg, seg.Segment);
            return(frag);
        }
        private GenFragment ScanFunction(GenContainerFragmentBase parentContainer, bool isPrimary)
        {
            var s    = Scan.ScanFunctionName();
            var func =
                new GenFunction(new GenFunctionParams(GenDataDef, parentContainer,
                                                      s, FragmentType.Function, isPrimary));
            GenFragment frag = func;

            ScanBlockParams(func.Body, func, func.Function, func.Function.Body());
            return(frag);
        }
Example #5
0
 protected static string GenerateFragment(GenDataBase genData, GenFragment fragment)
 {
     using (var s = new MemoryStream(100000))
     {
         var w = new GenWriter(s);
         GenFragmentGenerator.Generate(genData.GenDataDef, w, fragment.GenObject ?? genData.Root, fragment.Fragment);
         w.Flush();
         s.Seek(0, SeekOrigin.Begin);
         var r = new StreamReader(s);
         return(r.ReadToEnd());
     }
 }
        private GenFragment ScanCondition(int classId, GenContainerFragmentBase parentContainer, bool isPrimary)
        {
            var s = Scan.ScanCondition();
            var c =
                ProfileFragmentSyntaxDictionary.ActiveProfileFragmentSyntaxDictionary.ParseCondition(
                    GenDataDef, s);
            var cond =
                new GenCondition(new GenConditionParams(GenDataDef, parentContainer, c, isPrimary));

            GenFragment frag = cond;

            ScanBody(classId, cond.Body, cond, cond.Condition);
            return(frag);
        }
        internal GenFragment ScanFragment(int classId, ref TokenType nextToken, out string s, GenContainerFragmentBase parentContainer, FragmentBody fragmentBody, ref GenTextBlock textBlock, bool isPrimary)
        {
            Contract.Ensures(Contract.OldValue(nextToken) == TokenType.Name ||
                             Contract.Result <GenFragment>() != null);
            var         oldToken = nextToken;
            GenFragment frag     = null;

            s = "";
            switch (oldToken)
            {
            case TokenType.Segment:
                frag = ScanSegment(parentContainer, isPrimary);
                break;

            case TokenType.Block:
                frag = ScanBlock(classId, parentContainer, isPrimary);
                break;

            case TokenType.Lookup:
                frag = ScanLookup(parentContainer, isPrimary);
                break;

            case TokenType.Condition:
                frag = ScanCondition(classId, parentContainer, isPrimary);
                break;

            case TokenType.Function:
                frag = ScanFunction(parentContainer, isPrimary);
                break;

            case TokenType.Name:
                ScanPlaceholder(parentContainer, ref textBlock, isPrimary);
                break;

            case TokenType.Annotation:
                frag = ScanAnnotation(classId, parentContainer, isPrimary);
                break;

            default:
                OutputText(parentContainer, isPrimary, "Unknown token type: " + nextToken);
                throw new GeneratorException("Unknown token type: " + nextToken + "; " + Scan.Buffer);
            }
            s = Scan.ScanText();
            return(frag);
        }
Example #8
0
        protected static void ValidateFragmentData(GenDataDef genDataDef, string parentClassName, GenFragment genFragment, GenDataDef profileDataDef)
        {
            var fragment = genFragment.Fragment;

            VerifyObjectClass(profileDataDef, genFragment.FragmentType.ToString(), fragment.GenObject);
            var containerFragment = fragment as ContainerFragment;

            if (containerFragment != null)
            {
                var genContainerFragment = (GenContainerFragmentBase)genFragment;
                var className            = parentClassName;
                ValidateProfileSegmentData(genDataDef, containerFragment, genContainerFragment, ref className);
                ValidateProfileTextBlockData(containerFragment, genContainerFragment);
                ValidateProfileContainerData(genContainerFragment, genDataDef, className, profileDataDef);
            }
        }
 protected override void AddFragment(GenSegBody body, GenFragment frag)
 {
     Contract.Assert(!body.Fragment.Contains(frag), "Fragment added to body again");
     body.Add(frag);
 }
Example #10
0
 protected abstract void AddFragment(GenSegBody body, GenFragment frag);