Beispiel #1
0
        private ISyntax CreateAbnfSyntax()
        {
            var syntax = new Syntax();

            syntax.DefaultConverter.Add(CommonConverters.GuidConverter);
            syntax.DefaultConverter.Add(CommonConverters.Int32Converter);

            HostExtenderRef.Setup(syntax);
            HostExtenders.Setup(syntax);
            //LibidReference.Setup(syntax);
            ProjectId.Setup(syntax);
            ProjectDocModule.Setup(syntax);
            ProjectStdModule.Setup(syntax);
            ProjectClassModule.Setup(syntax);
            ProjectDesignerModule.Setup(syntax);
            ProjectPackage.Setup(syntax);
            ProjectProperties.Setup(syntax);
            ProjectReference.Setup(syntax);
            ProjectWindow.Setup(syntax);
            ProjectWindowState.Setup(syntax);
            ProjectWindowRecord.Setup(syntax);
            ProjectWorkspace.Setup(syntax);
            VBAPROJECTText.Setup(syntax);

            return(syntax);
        }
Beispiel #2
0
        public void SetValuesFromStr(string str)
        {
            var syntax        = CreateAbnfSyntax();
            var entityBuilder = syntax.Entity <VBAPROJECTText>();

            bool canParse = entityBuilder.CanParse(str);

            if (!canParse)
            {
                string pattern = entityBuilder.GetRegexPattern();
                throw new InvalidOperationException(String.Format("Could not parse ABNF Syntax. Input was: {0}. Mapped regex pattern is: {1}", str, pattern));
            }

            var result = entityBuilder.FromAbnfSyntax(str);

#if DEBUG
            // When in debug mode, do a sanity check: convert the instantiated object back to ABNF syntax and check if it equals the initial string
            var  _abnfSanityCheck        = entityBuilder.ToAbnfSyntax(result);
            bool _abnfSanityCheckSuccess = String.Equals(str, _abnfSanityCheck);

            if (!_abnfSanityCheckSuccess)
            {
                throw new InvalidOperationException(String.Format("ABNF data {0} did not re-map to itself; result was {1}", syntax, _abnfSanityCheck));
            }
#endif

            this.ProjectText = result;
        }