示例#1
0
文件: Formula.cs 项目: cubeme/ssharp
        /// <summary>
        ///   Returns a string that represents the current object.
        /// </summary>
        public override string ToString()
        {
            var visitor = new ToStringVisitor();

            visitor.Visit(this);
            return(visitor.FormulaString);
        }
示例#2
0
        public override string ToString()
        {
            var visitor = new ToStringVisitor();

            visitor.Visit(this, 0);
            return(visitor.Result);
        }
示例#3
0
        public override sealed string ToString()
        {
            var tsv = new ToStringVisitor();

            Accept(tsv);
            return(tsv.Result);
        }
示例#4
0
        public void Asd()
        {
            var eventDeclaration = new EventDeclaration
            {
                Name = Names.Event("[MyEvent, IO, 1.2.3.4] [DeclaringType, GUI, 5.6.7.8].E")
            };
            var fieldDeclaration = new FieldDeclaration
            {
                Name = Names.Field("[MyField, mscore, 4.0.0.0] [DeclaringType, mscore, 4.0.0.0]._f")
            };

            var sst = new SST {
                EnclosingType = Names.Type("MyType, mscore, 4.0.0.0")
            };

            sst.Events.Add(eventDeclaration);
            sst.Fields.Add(fieldDeclaration);

            var context = new StringBuilder();

            var sut = new ToStringVisitor();

            sst.Accept(sut, context);

            var          actual   = context.ToString();
            const string expected = "class MyType {\n\tevent MyEvent E;\n\tMyField _f;\n}\n";

            Assert.AreEqual(expected, actual);
        }
示例#5
0
        public void MultipleNotTest()
        {
            var root    = _parser.Parse("!!!:A && !!:B");
            var visitor = new ToStringVisitor(new TextOperatorType());

            AcceptVisitor(root, visitor);
            Assert.Equal("(not(not(not(:A))) and not(not(:B)))", visitor.Result);
        }
示例#6
0
        public void PrecedenceTest()
        {
            var root    = _parser.Parse(":A || :B && :C");
            var visitor = new ToStringVisitor(new LogicalOperatorType());

            AcceptVisitor(root, visitor);
            Assert.Equal("(:A ∨ (:B ∧ :C))", visitor.Result);
        }
示例#7
0
        public void AndAssociativityTest()
        {
            var root    = _parser.Parse(":A && :B && :C && :D");
            var visitor = new ToStringVisitor(new ProgrammingOperatorType());

            AcceptVisitor(root, visitor);
            Assert.Equal("(((:A && :B) && :C) && :D)", visitor.Result);
        }
示例#8
0
        public void TestToStringVisitor()
        {
            var source  = new Source("{\n  node(id: 4) {\n    id,\n    name\n  }\n}\n");
            var result  = Parser.Parse(source);
            var visitor = new ToStringVisitor(_output);

            visitor.Visit(result);
        }
示例#9
0
        public void SimpleQuery()
        {
            var root    = _parser.Parse(":test or true and (:movie or not :blue)");
            var visitor = new ToStringVisitor(new LogicalOperatorType());

            AcceptVisitor(root, visitor);

            Assert.Equal("(:test ∨ (true ∧ (:movie ∨ ¬:blue)))", visitor.Result);
            Assert.False(_parser.IllegalExpression);
        }
        public void Parse_When_ComparingWithToStringVisitor_Then_ResultShouldBeExpectedResult(string input, string expectedResult)
        {
            expectedResult ??= input;
            var testee          = new BindingPathParser(new BindingPathLexicalAnalyzer());
            var toStringVisitor = new ToStringVisitor();

            var result = testee.Parse(input);

            result.IsSuccess.Should().BeTrue();
            toStringVisitor.Visit(result.Value, ˍ._).Should().Be(expectedResult);
        }
示例#11
0
        public void ExplicitMemberMappingWithConflictToStringTest()
        {
            string correct = "ObjectToObject<From, To>\n    attrSrc => attr Copy<String>";

            ToStringVisitor visitor = new ToStringVisitor();

            Mapping.Instance.Mappings.AcceptForAll(visitor);

            string mappingToString = visitor.GetResult();

            Assert.AreEqual(correct, mappingToString);
        }
示例#12
0
        public void SubClassAttributesToStringTest()
        {
            string correct = "ObjectToObject<SubFrom, SubTo>\n    GetValue2 => Value2 Copy<String>\n    GetValue => Value Copy<String>\n    GetValue3 => value3 Copy<String>";

            ToStringVisitor visitor = new ToStringVisitor();

            Mapping.Instance.Mappings.AcceptForAll(visitor);

            string mappingToString = visitor.GetResult();

            Assert.AreEqual(correct, mappingToString);
        }
示例#13
0
        public void NoAttributesMappingToStringTest()
        {
            string correct = "ObjectToObject<From, To>";

            ToStringVisitor visitor = new ToStringVisitor();

            Mapping.Instance.Mappings.AcceptForAll(visitor);

            string mappingToString = visitor.GetResult();

            Assert.AreEqual(correct, mappingToString);
        }
示例#14
0
        public void MappingToString()
        {
            string expected = "NullableWithSync<From, To>\n    ObjectToObject<From, To>\n        Inner => Inner NullableWithSync<From, To>\n            ...";

            ToStringVisitor visitor = new ToStringVisitor();

            Mapping.Instance.Mappings.AcceptForAll(visitor);

            string mappingToString = visitor.GetResult();

            Assert.AreEqual(expected, mappingToString);
        }
示例#15
0
        public void StructuringToStringTest()
        {
            string correct = "ObjectToObject<From, To>\n    InnerData => Inner.Data Copy<String>\n    Data => Data Copy<String>";

            ToStringVisitor visitor = new ToStringVisitor();

            Mapping.Instance.Mappings.AcceptForAll(visitor);

            string mappingToString = visitor.GetResult();

            Assert.AreEqual(correct, mappingToString);
        }
示例#16
0
        private void Parse_OnClick(object sender, RoutedEventArgs e)
        {
            var gg     = Grammar.Create();
            var rast   = gg.Parse(Lang.Text);
            var reader = new Reader();
            var rg     = reader.Read(rast);

            var r     = rg.Parse(Test.Text);
            var toStr = new ToStringVisitor <string, string>();
            var str   = toStr.BuildString(r);

            MessageBox.Show(str, "AST");
        }
示例#17
0
        public void DynamicVisitorPatternTest()
        {
            IVisitable personA = new PersonA();
            IVisitable personB = new PersonB();

            IVisitor toStrVisitor     = new ToStringVisitor();
            IVisitor toElementVisitor = new ToElementPersonVisitor();

            _testOutputHelper.WriteLine(personA.Accept(toElementVisitor));
            _testOutputHelper.WriteLine(personA.Accept(toStrVisitor));
            _testOutputHelper.WriteLine(personB.Accept(toElementVisitor));
            _testOutputHelper.WriteLine(personB.Accept(toStrVisitor));
        }
示例#18
0
 void IterateWithApprove()
 {
     using (var tr = _db.StartTransaction())
     {
         var fastVisitor = new ToStringFastVisitor();
         var visitor     = new ToStringVisitor();
         var iterator    = new ODBIterator(tr, fastVisitor);
         iterator.Iterate();
         iterator = new ODBIterator(tr, visitor);
         iterator.Iterate();
         var text = visitor.ToString();
         Approvals.Verify(text);
         Assert.Equal(fastVisitor.Keys.ToByteArray(), visitor.Keys.ToByteArray());
     }
 }
示例#19
0
        public void VisitValue()
        {
            var valueExpr =
                new ValueExpression(
                    new FuzzyVariable("MyFuzzyVariable", new NumericVariable("MyNumVariable")),
                    new FuzzyTerm("MyTerm", new MembershipFunction()));

            var sut = new ToStringVisitor();

            var result = sut.Visit(valueExpr);
            Assert.AreEqual("MyFuzzyVariable=MyTerm", result);

            result = valueExpr.Accept(sut);
            Assert.AreEqual("MyFuzzyVariable=MyTerm", result);
        }
示例#20
0
 void IterateWithApprove([CallerMemberName] string testName = null)
 {
     using (var tr = _db.StartTransaction())
     {
         var fastVisitor = new ToStringFastVisitor();
         var visitor     = new ToStringVisitor();
         var iterator    = new ODBIterator(tr, fastVisitor);
         iterator.Iterate();
         iterator = new ODBIterator(tr, visitor);
         iterator.Iterate();
         var text = visitor.ToString();
         this.Assent(text, null, testName);
         Assert.Equal(fastVisitor.Keys.ToByteArray(), visitor.Keys.ToByteArray());
     }
 }
示例#21
0
        public void SubClassMappingToStringTest()
        {
            string correct = "SubClassToObject<From, To>\n    SubFrom1 => SubTo1 ObjectToObject<SubFrom1, SubTo1>\n    SubFrom2 => SubTo1 ObjectToObject<SubFrom2, SubTo1>\n    SubFrom3 => SubTo2 ObjectToObject<SubFrom3, SubTo2>\n    From => To ObjectToObject<From, To>\n"
                             + Constants.SEPARATOR + "ObjectToObject<SubFrom1, SubTo1>\n"
                             + Constants.SEPARATOR + "ObjectToObject<SubFrom2, SubTo1>\n"
                             + Constants.SEPARATOR + "ObjectToObject<SubFrom3, SubTo2>";

            ToStringVisitor visitor = new ToStringVisitor();

            Mapping.Instance.Mappings.AcceptForAll(visitor);

            string mappingToString = visitor.GetResult();

            Assert.AreEqual(correct, mappingToString);
        }
示例#22
0
        public static string Compile(string input)
        {
            Console.Write("# Parsing {0}: ", input);
            FunctionDecl main;

            using (var file = new FileStream(input, FileMode.Open)) {
                var scanner = new Scanner(file);
                var parser  = new Parser(scanner);
                if (!parser.Parse())
                {
                    Console.WriteLine("Not OK :(");
                    throw new ArgumentException("Input is not valid...");
                }
                Console.WriteLine("OK");
                main = parser.Prog;
            }

            Console.Write("# Type checking {0}: ", input);
            var tcv = new TypecheckVisitor();

            main.Accept(tcv);
            Console.WriteLine("OK");

            Console.Write("# Return checking {0}: ", input);
            var rcv = new ReturnCheckVisitor();

            main.Accept(rcv);
            Console.WriteLine("OK");

            Console.WriteLine("# Contents of {0}:", input);
            var toStringVisitor = new ToStringVisitor();

            main.Accept(toStringVisitor);
            Console.Write(toStringVisitor.Result);

            var prefix = input.Substring(0, input.LastIndexOf('.'));

            Console.Write("# Compiling {0} into {1}: ", input, prefix + ".exe");
            var cecilVisitor = new CecilVisitor(tcv.Assembly, tcv.Module);

            main.Accept(cecilVisitor);
            cecilVisitor.Write(prefix);
            Console.WriteLine("OK");

            Console.Out.Flush();
            return(prefix + ".exe");
        }
示例#23
0
        static void Main(string[] args)
        {
            AbstractFactoryClient client = new AbstractFactoryClient(MANUFACTURES.PRODUCT1FACTORY);

            client.ProductList();
            client = new AbstractFactoryClient(MANUFACTURES.PRODUCT2FACTORY);
            client.ProductList();

            IBuilder builder1 = new ConcreteBuilder1();

            Console.WriteLine($"New Product created: {Manufacture.Construct(builder1)}");
            builder1 = new ConcreteBuilder2();
            Console.WriteLine($"New Product created: {Manufacture.Construct(builder1)}");

            Creator  creator = new Creator();
            IProduct product;

            product = creator.GetProduct(PRODUCT.TYPE1);
            Console.WriteLine(product.Description);
            product = creator.GetProduct(PRODUCT.TYPE2);
            Console.WriteLine(product.Description);

            LazyObject.Get("first");
            LazyObject.Get("second");
            LazyObject.ShowAll();
            LazyObject.Get("third");
            LazyObject.Get("first");
            LazyObject.ShowAll();

            Person personClient = new Client()
            {
                FirstName = "Ivan", SecondName = "Ivanov", OrdersCount = 5
            };
            Person personEmployee = new Employee()
            {
                FirstName = "Petr", SecondName = "Petrov", Salary = 1000
            };
            ToStringVisitor visitor = new ToStringVisitor();

            Console.WriteLine(visitor.DynamicVisit(personClient));
            Console.WriteLine(visitor.DynamicVisit(personEmployee));

            Console.WriteLine("Complete");
            Console.ReadKey();
        }
示例#24
0
        public void TestDecompilesTo(IManagedMethod method, IEnumerable <string> patterns)
        {
            var decompiled = Decompile(method);

            var parameterNames = decompiled.Parameters.Select(p => p.Name).ToArray();
            var expected       = patterns.Select(
                p => p.Contains("{0}") ? string.Format(p, parameterNames) : p
                ).ToList();

            if (expected.Count <= 1)
            {
                Assert.AreEqual(expected.Single(), ToStringVisitor.ToString(decompiled));
            }
            else
            {
                Assert.Contains(expected, ToStringVisitor.ToString(decompiled));
            }
        }
示例#25
0
        public void VisitOr()
        {
            var valueExpr1 =
                new ValueExpression(
                    new FuzzyVariable("MyFuzzyVariable1", new NumericVariable("MyNumVariable1")),
                    new FuzzyTerm("MyTerm1", new MembershipFunction()));
            var valueExpr2 =
                new ValueExpression(
                    new FuzzyVariable("MyFuzzyVariable2", new NumericVariable("MyNumVariable2")),
                    new FuzzyTerm("MyTerm2", new MembershipFunction()));

            var orExpr = new OrExpression(valueExpr1, valueExpr2);

            var sut = new ToStringVisitor();

            var result = sut.Visit(orExpr);
            Assert.AreEqual("MyFuzzyVariable1=MyTerm1 || MyFuzzyVariable2=MyTerm2", result);

            result = orExpr.Accept(sut);
            Assert.AreEqual("MyFuzzyVariable1=MyTerm1 || MyFuzzyVariable2=MyTerm2", result);
        }
示例#26
0
        public static string Compile(string input)
        {
            Console.Write("# Parsing {0}: ", input);
            FunctionDecl main;
            using (var file = new FileStream(input, FileMode.Open)) {
                var scanner = new Scanner(file);
                var parser = new Parser(scanner);
                if (!parser.Parse()) {
                    Console.WriteLine("Not OK :(");
                    throw new ArgumentException("Input is not valid...");
                }
                Console.WriteLine("OK");
                main = parser.Prog;
            }

            Console.Write("# Type checking {0}: ", input);
            var tcv = new TypecheckVisitor();
            main.Accept(tcv);
            Console.WriteLine("OK");

            Console.Write("# Return checking {0}: ", input);
            var rcv = new ReturnCheckVisitor();
            main.Accept(rcv);
            Console.WriteLine("OK");

            Console.WriteLine("# Contents of {0}:", input);
            var toStringVisitor = new ToStringVisitor();
            main.Accept(toStringVisitor);
            Console.Write(toStringVisitor.Result);

            var prefix = input.Substring(0, input.LastIndexOf('.'));
            Console.Write("# Compiling {0} into {1}: ", input, prefix + ".exe");
            var cecilVisitor = new CecilVisitor(tcv.Assembly, tcv.Module);
            main.Accept(cecilVisitor);
            cecilVisitor.Write(prefix);
            Console.WriteLine("OK");

            Console.Out.Flush();
            return prefix + ".exe";
        }
示例#27
0
        private string QueryToString(Query query)
        {
            try
            {
                var visitor = new ToStringVisitor();
                visitor.Visit(query);
                return(visitor.ToString());
            }
            catch (Exception e)
            {
                Logger.WriteException(e);

                var c = query.ToString().ToCharArray();
                for (int i = 0; i < c.Length; i++)
                {
                    if (c[i] < ' ')
                    {
                        c[i] = '.';
                    }
                }
                return(new String(c));
            }
        }
示例#28
0
 public void TestToStringVisitor()
 {
     var source = new Source("{\n  node(id: 4) {\n    id,\n    name\n  }\n}\n");
     var result = Parser.Parse(source);
     var visitor = new ToStringVisitor(_output);
     visitor.Visit(result);
 }
示例#29
0
 void IterateWithApprove()
 {
     using (var tr = _db.StartTransaction())
     {
         var fastVisitor = new ToStringFastVisitor();
         var visitor = new ToStringVisitor();
         var iterator = new ODBIterator(tr, fastVisitor);
         iterator.Iterate();
         iterator = new ODBIterator(tr, visitor);
         iterator.Iterate();
         var text = visitor.ToString();
         Approvals.Verify(text);
         Assert.Equal(fastVisitor.Keys.ToByteArray(), visitor.Keys.ToByteArray());
     }
 }
示例#30
0
 public override sealed string ToString()
 {
     var tsv = new ToStringVisitor();
     Accept(tsv);
     return tsv.Result;
 }
示例#31
0
        static void Main(string[] args)
        {
            var opt       = CliParser.StrictParse <Options>(args);
            var stopwatch = new Stopwatch();

            XDocument leftDoc  = null;
            XDocument rightDoc = null;

            if (opt.Verbose)
            {
                Console.WriteLine("Loading \"{0}\"...", opt.LeftFile);
            }
            leftDoc = XDocument.Load(opt.LeftFile);
            if (opt.Verbose)
            {
                Console.WriteLine("Loading \"{0}\"...", opt.RightFile);
            }
            rightDoc = XDocument.Load(opt.RightFile);
            if (opt.Verbose)
            {
                Console.WriteLine("Comparing differences...");
            }
            stopwatch.Start();

            var comparer = new XmlComparer();
            var diff     = comparer.Compare(leftDoc.Root, rightDoc.Root);

            if (!diff.IsChanged && opt.Verbose)
            {
                Console.WriteLine("No changes detected!");
            }

            if (opt.Verbose)
            {
                Console.WriteLine("Compared in {0} ms.", stopwatch.ElapsedMilliseconds);
            }

            if (!string.IsNullOrEmpty(opt.OutputHtmlFile))
            {
                if (opt.Verbose)
                {
                    Console.WriteLine("Creating HTML output...");
                    stopwatch.Restart();
                }

                var visitor = new HtmlVisitor();
                visitor.Visit(diff);

                if (opt.Verbose)
                {
                    Console.WriteLine("Writing HTML output to \"{0}\"...", opt.OutputHtmlFile);
                }
                File.WriteAllText(opt.OutputHtmlFile, visitor.Result);

                if (opt.Verbose)
                {
                    Console.WriteLine("HTML output file created in {0} ms.", stopwatch.ElapsedMilliseconds);
                }
            }

            if (!string.IsNullOrEmpty(opt.OutputXdtFile))
            {
                if (opt.Verbose)
                {
                    Console.WriteLine("Creating XDT output...");
                    stopwatch.Restart();
                }

                var visitor = new XdtVisitor();
                visitor.Visit(diff);

                if (opt.Verbose)
                {
                    Console.WriteLine("Writing XDT output to \"{0}\"...", opt.OutputXdtFile);
                }
                File.WriteAllText(opt.OutputXdtFile, visitor.Result);

                if (opt.Verbose)
                {
                    Console.WriteLine("XDT output file created in {0} ms.", stopwatch.ElapsedMilliseconds);
                }
            }
            stopwatch.Stop();

            if (opt.Verbose)
            {
                Console.WriteLine("\nShowing text diff:");
            }
            if (opt.Verbose || (string.IsNullOrEmpty(opt.OutputHtmlFile) && string.IsNullOrEmpty(opt.OutputXdtFile)))
            {
                var vistor = new ToStringVisitor();
                vistor.Visit(diff);
                Console.WriteLine(vistor.Result);
            }
        }
示例#32
0
		/// <summary>
		///   Returns a string that represents the current object.
		/// </summary>
		public override string ToString()
		{
			var visitor = new ToStringVisitor();
			visitor.Visit(this);
			return visitor.FormulaString;
		}
示例#33
0
        public void ComplexExpression()
        {
            var A = new FuzzyVariable("A", new NumericVariable("a"));
            var B = new FuzzyVariable("B", new NumericVariable("b"));
            var C = new FuzzyVariable("C", new NumericVariable("c"));

            var x = new FuzzyTerm("x", new MembershipFunction());
            var y = new FuzzyTerm("y", new MembershipFunction());
            var z = new FuzzyTerm("z", new MembershipFunction());


            var ruleExpr = new FuzzyImplication(
                new OrExpression(
                    new NotExpression(
                        new AndExpression(
                            new ValueExpression(A, x),
                            new ValueExpression(B, y)
                        )
                    ),
                    new AndExpression(
                        new ValueExpression(A, y),
                        new ValueExpression(B, x)
                    )
                ),
                new ValueExpression(C, z)
            );

            var sut = new ToStringVisitor();

            var result = sut.Visit(ruleExpr);
            Assert.AreEqual("!( A=x && B=y ) || ( A=y && B=x ) => C=z", result);

            result = ruleExpr.Accept(sut);
            Assert.AreEqual("!( A=x && B=y ) || ( A=y && B=x ) => C=z", result);
        }
示例#34
0
        public void TestInliningOfBasicProperty()
        {
            Expression <Func <ClassWithNames, bool> > predicate = c => c.FullNameSimple.Contains("Test"); // not a recommended database scenario
            var inliner = new Inliner(ExpressiveEngine.GetDecompiler());

            var inlined = inliner.Inline(predicate, p => p.Name == "FullNameSimple");

            Assert.AreEqual("c => String.Concat(c.FirstName, \" \", c.LastName).Contains(\"Test\")", ToStringVisitor.ToString(inlined));
        }
示例#35
0
 public void WriteTo(TextWriter writer)
 {
     var buildStringVisitor = new ToStringVisitor(writer);
     Accept(buildStringVisitor);
 }