当前位置: 首页>>代码示例>>C#>>正文


C# Parser.Parse方法代码示例

本文整理汇总了C#中Parser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Parse方法的具体用法?C# Parser.Parse怎么用?C# Parser.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestComplex

        public void TestComplex()
        {
            Parser p = new Parser();
            var cplx = new Ast.ComplexNumberNode() {
                Real = 4.2,
                Imaginary = 3.2
            };
            var cplx2 = new Ast.ComplexNumberNode() {
                Real = 4.2,
                Imaginary = 99
            };
            Assert.AreNotEqual(cplx, cplx2);
            cplx2.Imaginary = 3.2;
            Assert.AreEqual(cplx, cplx2);

            Assert.AreEqual(cplx, p.Parse("(4.2+3.2j)").Root);
            cplx.Real = 0;
            Assert.AreEqual(cplx, p.Parse("(0+3.2j)").Root);
            Assert.AreEqual(cplx, p.Parse("3.2j").Root);
            Assert.AreEqual(cplx, p.Parse("+3.2j").Root);
            cplx.Imaginary = -3.2;
            Assert.AreEqual(cplx, p.Parse("-3.2j").Root);
            cplx.Real = -9.9;
            Assert.AreEqual(cplx, p.Parse("(-9.9-3.2j)").Root);

            cplx.Real = 2;
            cplx.Imaginary = 3;
            Assert.AreEqual(cplx, p.Parse("(2+3j)").Root);
            cplx.Imaginary = -3;
            Assert.AreEqual(cplx, p.Parse("(2-3j)").Root);
            cplx.Real = 0;
            Assert.AreEqual(cplx, p.Parse("-3j").Root);
        }
开发者ID:pombredanne,项目名称:Serpent,代码行数:33,代码来源:ParserTest.cs

示例2: TestBasic

 public void TestBasic()
 {
     Parser p = new Parser();
     Assert.IsNull(p.Parse((string)null).Root);
     Assert.IsNull(p.Parse("").Root);
     Assert.IsNotNull(p.Parse("# comment\n42\n").Root);
 }
开发者ID:pombredanne,项目名称:Serpent,代码行数:7,代码来源:ParserTest.cs

示例3: run

        static void run(IEnumerable<String> filePaths)
        {
            var p = new Parser();
            var modules = new Dictionary<String, IReadOnlyList<IClassItem>>();
            foreach (var path in filePaths.Reverse())
            {
                Contract.Assume(path != null);
                var txt = File.ReadAllText(path);
                var items = p.Parse(txt, ValidationList);
                modules.Add(Path.GetFileNameWithoutExtension(path), items.Cast<IClassItem>().ToList());
            }

            var preludeTxt = File.ReadAllText(libPath + "prelude.ef");
            var preludeTxtItems = p.Parse(preludeTxt, ValidationList);

            var rw = new Rewriter();
            var prog = rw.MakeProgram(preludeTxtItems.Cast<Declr>().ToList(), modules);

            var n = new Namer();
            n.Name(prog, ValidationList);

            var ti = new TypeInferer();
            ti.VisitDeclr(prog.GlobalModule);

            var i = new Interpreter();
            var res = i.Run(prog, ValidationList);
            Console.Write("Result: ");
            Console.WriteLine(res.Accept(DefaultPrinter));
        }
开发者ID:michal-minich,项目名称:Efekt-CS,代码行数:29,代码来源:Program.cs

示例4: TestAstEquals

 public void TestAstEquals()
 {
     Parser p = new Parser ();
     byte[] ser = File.ReadAllBytes ("testserpent.utf8.bin");
     Ast ast = p.Parse(ser);
     Ast ast2 = p.Parse(ser);
     Assert.AreEqual(ast.Root, ast2.Root);
 }
开发者ID:pombredanne,项目名称:Serpent,代码行数:8,代码来源:ParserTest.cs

示例5: repeated_parsing_yields_different_values

 public void repeated_parsing_yields_different_values()
 {
     var parser = new Parser();
     var result1 = parser.Parse("now");
     Thread.Sleep(100);
     var result2 = parser.Parse("now");
     Assert.NotEqual(result1.ToTime(), result2.ToTime());
 }
开发者ID:acsteitz,项目名称:nChronic,代码行数:8,代码来源:NowTests.cs

示例6: RequiredArgumentsWork

 public void RequiredArgumentsWork()
 {
     var strategy = new Parser();
     strategy.AddDescription(new NamedArgumentDescription<string>("required") { IsRequired = true });
     var actual = strategy.Parse("--notrequired=mmmm");
     Assert.That(actual.IsValid, Is.False);
     var actual2 = strategy.Parse("--required=aaa");
     Assert.That(actual2.IsValid);
 }
开发者ID:davidsidlinger,项目名称:saccharin,代码行数:9,代码来源:ParserFixture.cs

示例7: PositionedArgumentValidation

 public void PositionedArgumentValidation()
 {
     var strategy = new Parser();
     strategy.AddDescription(new PositionedArgumentDescription<string>(0) { MatchPattern = "^\\d+$" });
     var actual = strategy.Parse("ab112d", "111333442");
     Assert.That(actual.IsValid, Is.False);
     var actual2 = strategy.Parse("111333442", "ab112d");
     Assert.That(actual2.IsValid);
 }
开发者ID:davidsidlinger,项目名称:saccharin,代码行数:9,代码来源:ParserFixture.cs

示例8: PatternMatchingWorks

 public void PatternMatchingWorks()
 {
     var strategy = new Parser();
     strategy.AddDescription(new NamedArgumentDescription<string>("numbers") { MatchPattern = "^\\d+$" });
     var actual = strategy.Parse("--numbers=ab112d");
     Assert.That(actual.IsValid, Is.False);
     var actual2 = strategy.Parse("--numbers=12345");
     Assert.That(actual2.IsValid);
 }
开发者ID:davidsidlinger,项目名称:saccharin,代码行数:9,代码来源:ParserFixture.cs

示例9: Main

        public static void Main(string[] args)
        {
            var parser = new Parser(new Worm.WormFactory());
            string workingDir = Directory.GetCurrentDirectory();

            DirectoryInfo libRoot = Directory.GetParent(workingDir).Parent.Parent.GetDirectories("fullflow-lib")[0];
            string modelProjectFile = String.Format("{0}/fullflow-lib.csproj", libRoot.FullName);

            PocoModel model = parser.Parse(modelProjectFile);

            foreach (PocoEntity entity in model.Entities)
            {
                Console.WriteLine("DbFactory: {0}", entity.DbFactory.GetType().Name);
                Console.WriteLine("PocoClassName: {0}", entity.PocoClassName);
                Console.WriteLine("PocoFilename: {0}", entity.PocoFilename);
                Console.WriteLine("PocoNamespace: {0}", entity.PocoNamespace);
                Console.WriteLine("TableName: {0}", entity.TableName);
                Console.WriteLine();

                foreach (PocoField field in entity.Fields)
                {
                    Console.WriteLine("AccessModifier: {0}", field.AccessModifier);
                    Console.WriteLine("AllowNull: {0}", field.AllowNull);
                    Console.WriteLine("ColumnName: {0}", field.ColumnName);
                    Console.WriteLine("HasGetter: {0}", field.HasGetter);
                    Console.WriteLine("HasSetter: {0}", field.HasSetter);
                    Console.WriteLine("IdGenerator: {0}", field.IdGenerator);
                    Console.WriteLine("IsEnum: {0}", field.IsEnum);
                    Console.WriteLine("IsPrimaryKey: {0}", field.IsPrimaryKey);
                    Console.WriteLine("Name: {0}", field.Name);
                    Console.WriteLine("StorageType: {0}", field.StorageType);
                    Console.WriteLine("Type: {0}", field.Type);
                    Console.WriteLine();
                }

                Console.WriteLine();
            }

            Engine eng = new Engine();
            Project proj = new Project(eng);
            proj.Load(modelProjectFile);
            BuildItemGroup compileBuildItemGroup = GetCompileIncludeBuildItemGroup(proj);

            var writer = new DbClassWriter(new WormFactory());
            foreach (PocoEntity entity in model.Entities)
            {
                CodeFile cf = writer.Generate(entity);
                //cf.Filename = cf.Filename.Replace("fullflowlib", "fullflow-lib");
                WriteCodeFile(libRoot, cf);
                AddFileToProject(compileBuildItemGroup, cf);
            }

            proj.Save(modelProjectFile);

            // compile the project again
            parser.Parse(modelProjectFile);
        }
开发者ID:pingvinen,项目名称:worm,代码行数:57,代码来源:Program.cs

示例10: Parser_Reads_Character_Sets_Strings

        public void Parser_Reads_Character_Sets_Strings()
        {
            var parser = new Parser();
            var css = parser.Parse("@charset 'utf-8';");
            var charset = css.CharsetDirectives;

            Assert.AreEqual("@charset 'utf-8';", charset[0].ToString());

            css = parser.Parse("@charset \"utf-8\";");
            charset = css.CharsetDirectives;

            Assert.AreEqual("@charset 'utf-8';", charset[0].ToString());
        }
开发者ID:harsimranb,项目名称:ExCSS,代码行数:13,代码来源:AtRuleFixture.cs

示例11: ParseEmpty

        public void ParseEmpty()
        {
            Parser parser = new Parser();
            ExpressionQueue result = parser.Parse(null);
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);

            result = parser.Parse(string.Empty);
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);

            result = parser.Parse("     \t");
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count);
        }
开发者ID:ChadBurggraf,项目名称:raspy,代码行数:15,代码来源:ParserTests.cs

示例12: Main

 public static void Main(string[] args)
 {
     while (true)
     {
         try
         {
             string s = Console.ReadLine();
             Lexer l = new Lexer();
             Parser p = new Parser(l.Lex(s));
             Ast.Chunk c = p.Parse();
             Compiler.Compiler cplr = new SharpLua.Compiler.Compiler();
             LuaFile proto = cplr.Compile(c, "<stdin>");
             Console.WriteLine("compiled!");
             FileStream fs = File.Open("out.sluac", FileMode.Create);
             foreach (char ch in proto.Compile())
             {
                 //Console.WriteLine(ch + " " + (int)ch);
                 fs.WriteByte((byte)ch);
             }
             fs.Close();
             Console.WriteLine("written to out.sluac!");
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
     }
     Console.Write("Press any key to continue . . . ");
     Console.ReadKey(true);
 }
开发者ID:chenzuo,项目名称:SharpLua,代码行数:30,代码来源:Program.cs

示例13: Functions

        public void Functions()
        {
            var parser = new Parser(new Scanner("../../sources/for_unit_tests/functions.exs"));
            parser.DoPostParseProcessing = true;
            parser.Parse();

            var ast = parser.TopmostAst;
            var options = new ExpressoCompilerOptions{
                LibraryPaths = new List<string>{""},
                OutputPath = "../../test_executable",
                BuildType = BuildType.Debug | BuildType.Executable
            };
            var emitter = new CSharpEmitter(parser, options);
            ast.AcceptWalker(emitter, null);

            var asm = emitter.AssemblyBuilder;
            var main_method = asm.GetModule("main.exe")
                .GetType("ExsMain")
                .GetMethod("Main", BindingFlags.NonPublic | BindingFlags.Static);
            Assert.AreEqual(main_method.Name, "Main");
            Assert.IsTrue(main_method.IsStatic);
            Assert.AreEqual(typeof(int), main_method.ReturnType);
            Assert.AreEqual(0, main_method.GetParameters().Length);
            //Assert.IsTrue(main_method.GetParameters().SequenceEqual(new []{typeof(string[])}));
            Console.Out.WriteLine("テスト実行");
            Console.Out.WriteLine(main_method.ToString());

            //main_method.Invoke(null, new object[]{});
        }
开发者ID:hazama-yuinyan,项目名称:Expresso,代码行数:29,代码来源:EmitterTests.cs

示例14: Stylesheet_Renders_Friendly_Format

        public void Stylesheet_Renders_Friendly_Format()
        {
            var parser = new Parser();
            var css = parser.Parse(Resources.Css3);

            Assert.AreEqual(Resources.Css3Friendly, css.ToString(true));
        }
开发者ID:harsimranb,项目名称:ExCSS,代码行数:7,代码来源:RenderFormatFixture.cs

示例15: Main

 public static void Main(string[] arg)
 {
     Scanner scanner = new Scanner(arg[0]);
     Parser parser = new Parser(scanner);
     parser.Parse();
     Console.Write(parser.errors.count + " errors detected");
 }
开发者ID:ravneetoxyent,项目名称:FortisNICU,代码行数:7,代码来源:Compile.cs


注:本文中的Parser.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。