• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Parsing.Parser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Irony.Parsing.Parser的典型用法代码示例。如果您正苦于以下问题:C# Parser类的具体用法?C# Parser怎么用?C# Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Parser类属于Irony.Parsing命名空间,在下文中一共展示了Parser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ShouldNotParseCaseElseWhenNotAtTheEnd

        public void ShouldNotParseCaseElseWhenNotAtTheEnd()
        {
            // Arrange
            var grammar = new CicodeGrammar();
            var parser = new Parser(grammar);
            var sourceCode =
            @"
            FUNCTION A()

            SELECT CASE a
            CASE 1
            A();
            CASE ELSE
            A();
            CASE 1
            A();
            END SELECT

            END
            ";
            // Act
            var parseTree = parser.Parse(sourceCode);

            // Assert
            Assert.IsNotNull(parseTree);
            Assert.IsTrue(parseTree.HasErrors());
            // A parser error is expected at line 7 because of the CASE ELSE clause which is not at then end of the case list
            Assert.AreEqual<int>(1, parseTree.ParserMessages.Where(m => m.Location.Line == 7).Count());
        }
开发者ID:mayurshkl,项目名称:NCicode,代码行数:29,代码来源:SelectCaseStatementTests.cs


示例2: Read

        public override object Read(string path)
        {
            string txt;
            using (var reader = new StreamReader(path))
            {
                txt = reader.ReadToEnd();
            }

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(txt);
            var d = new Vertice();

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                switch (identifier)
                {
                    case "value":
                        d.X = rootEntryNode.GetDictArrayBody().GetArrayOfDecimal()[0];
                        d.Y = rootEntryNode.GetDictArrayBody().GetArrayOfDecimal()[1];
                        d.Z = rootEntryNode.GetDictArrayBody().GetArrayOfDecimal()[2];
                        break;
                }
            }
            return d;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:27,代码来源:OmegaHandler.cs


示例3: Read

        public override object Read(string path)
        {
            var rawData = new FvSolutionData();
            string txt;
            using (var reader = new StreamReader(path))
            {
                txt = reader.ReadToEnd();
            }

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(txt);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                switch (identifier)
                {
                    case "options":
                        ParseOptions(rootEntryNode.ChildNodes[2], rawData);
                        break;
                    case "solvers":
                        ParseSolvers(rootEntryNode.ChildNodes[2], rawData);
                        break;
                }
            }
            return rawData;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:28,代码来源:FvSolutionHandler.cs


示例4: TestConflictGrammarWithHintsOnRules

        public void TestConflictGrammarWithHintsOnRules()
        {
            var grammar = new ConflictGrammarWithHintsInRules();
            var parser = new Parser(grammar);
            Assert.True(parser.Language.Errors.Count == 0);
            // Field sample
            var sample = FieldSample;
            var tree = parser.Parse(sample);
            Assert.NotNull(tree);
            Assert.False(tree.HasErrors());

            Assert.NotNull(tree.Root);
            var term = tree.Root.Term as NonTerminal;
            Assert.NotNull(term);
            Assert.Equal("definition", term.Name);

            Assert.Equal(1, tree.Root.ChildNodes.Count);
            var modNode = tree.Root.ChildNodes[0].ChildNodes[0];
            Assert.Equal("fieldModifier", modNode.Term.Name);

            //Property 
            sample = PropertySample;
            tree = parser.Parse(sample);
            Assert.NotNull(tree);
            Assert.False(tree.HasErrors());

            Assert.NotNull(tree.Root);
            term = tree.Root.Term as NonTerminal;
            Assert.NotNull(term);
            Assert.Equal("definition", term.Name);

            Assert.Equal(1, tree.Root.ChildNodes.Count);
            modNode = tree.Root.ChildNodes[0].ChildNodes[0];
            Assert.Equal("propModifier", modNode.Term.Name);
        }
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:35,代码来源:ConflictResolutionTests.cs


示例5: ExpressionEvaluator

 //Default constructor, creates default evaluator 
 public ExpressionEvaluator(ExpressionEvaluatorGrammar grammar) {
   Grammar = grammar;
   Language = new LanguageData(Grammar);
   Parser = new Parser(Language);
   Runtime = Grammar.CreateRuntime(Language);
   App = new ScriptApp(Runtime);
 }
开发者ID:Rezura,项目名称:LiveSplit,代码行数:8,代码来源:ExpressionEvaluator.cs


示例6: Read

        public override object Read(string path)
        {
            var obj = new AirfoilPropertiesInstance();
            string text = Load(path);

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(text);
            obj.row = new List<Vertice>();

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var id = rootEntryNode.GetEntryIdentifier();
                if (id == "airfoilData")
                {
                    var dict = rootEntryNode.GetDictContent().ChildNodes[1];
                    foreach (ParseTreeNode t in dict.ChildNodes)
                    {
                        var array_head = t.ChildNodes[0].ChildNodes[1].ChildNodes;
                        var v = new Vertice
                                    {
                                        X = Convert.ToDecimal(array_head[0].ChildNodes[0].Token.Value),
                                        Y = Convert.ToDecimal(array_head[1].ChildNodes[0].Token.Value),
                                        Z = Convert.ToDecimal(array_head[2].ChildNodes[0].Token.Value)
                                    };
                        obj.row.Add( v );
                    }
                }
            }
            obj.airfoilName = FileName;
            return obj;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:32,代码来源:AirfoilPropertiesHandler.cs


示例7: Read

        public override object Read(string path)
        {
            var obj = new RefineMeshDictData();
            string txt;
            using (var reader = new StreamReader(path))
            {
                txt = reader.ReadToEnd();
            }
            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(txt);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                string patch;
                switch ( identifier )
                {
                    case "set":
                        obj.setvalue = rootEntryNode.GetBasicValString();
                        break;
                    case "coordinateSystem":
                        obj.coordsys = rootEntryNode.GetBasicValEnum<CoordinateSystem>();
                        break;
                    case "globalCoeffs":
                        {
                            var dict = rootEntryNode.GetDictContent();
                            obj.globalCoeffs = GetCoeffs(ref dict, out patch);
                        }
                        break;
                    case "patchLocalCoeffs":
                        {
                            var dict = rootEntryNode.GetDictContent();
                            obj.patchLocalCoeffs = GetCoeffs(ref dict, out patch);
                            obj.patch = patch;
                        }
                        break;
                    case "directions":
                        {
                            obj.direction = new List<DirectionType>();
                            var s = rootEntryNode.ChildNodes[2].ChildNodes[1].GetArrayOfString();
                            foreach (string t in s)
                            {
                                obj.direction.Add(t.ToEnum<DirectionType>());
                            }
                        }
                        break;
                    case "useHexTopology":
                        obj.useHexTopology = rootEntryNode.GetBasicValBool();
                        break;
                    case "geometricCut":
                        obj.geometricCut = rootEntryNode.GetBasicValBool();
                        break;
                    case "writeMesh":
                        obj.writeMesh = rootEntryNode.GetBasicValBool();
                        break;
                }
            }
            return obj;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:60,代码来源:RefineMeshDictHandler.cs


示例8: FSharpParser

        public FSharpParser()
            : base()
        {
            grammar = new FSharpGrammar();
            parser = new Parser(new LanguageData(grammar));

        }
开发者ID:jijo-paulose,项目名称:bistro-framework,代码行数:7,代码来源:FSharpParser.cs


示例9: Read

        public override object Read(string path)
        {
            var obj = new DecomposeParDictData();
            string txt = Load(path);

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(txt);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                switch (identifier)
                {
                    case "numberOfSubdomains":
                        obj.numberOfSubdomains = rootEntryNode.GetBasicValInt();
                        break;
                    case "method":
                        obj.method = rootEntryNode.GetBasicValEnum<DecompositionMethod>();
                        break;
                    case "hierarchicalCoeffs":
                        obj.hCoefs = GetHierarchicalCoeffs(rootEntryNode.GetDictContent());
                        break;
                }
            }
            return obj;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:27,代码来源:DecomposeParDictHandler.cs


示例10: Read

        public override object Read(string path)
        {
            var obj = new AirfoilPropertiesData();
            string text;
            using (var reader = new StreamReader(path))
            {
                text = reader.ReadToEnd();
            }
            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(text);
            obj.airfoilData = new List<Vertice>();

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var id = rootEntryNode.GetEntryIdentifier();
                if (id == "airfoilData")
                {
                    var dict = rootEntryNode.GetDictContent().ChildNodes[1];
                    for (int i = 0; i < dict.ChildNodes.Count; i++)
                    {
                        var array_head = dict.ChildNodes[i].ChildNodes[0].ChildNodes[1].ChildNodes;
                        var v = new Vertice();
                        v.X = Convert.ToDecimal(array_head[0].ChildNodes[0].Token.Value);
                        v.Y = Convert.ToDecimal(array_head[1].ChildNodes[0].Token.Value);
                        v.Z = Convert.ToDecimal(array_head[2].ChildNodes[0].Token.Value);
                        obj.airfoilData.Add( v );
                    }
                }
            }
            return obj;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:32,代码来源:AirfoilPropertiesHandler.cs


示例11: NoGrammarConflicts

        // Ensure that the grammar has no conflicts
        public void NoGrammarConflicts()
        {
            /* Conflict either indicate an ambiguity in the grammar or an error in the rules
             * In case of an ambiguity Irony will choose an action itself, which is not always the correct one
             * Rewrite the grammar rules untill there are no conflicts, and the parses are corrent 
             * As a very last resort, you can manually specify shift with a grammar hint like PreferShiftHere() or ReduceHere()
             * However, this should only be done if one of the two is always correct, otherwise the grammar will need to be written differently
             */

            /* An example:
             * (A1) can be parsed both as an union and a bracketed reference
             * This is an ambiguity, and thus must be solved by precedence or a grammar hint
             */
            
            /* An example:
             * Functioncall.Rule =
             *   Prefix + Formula           // Prefix unop
             * | Formula + infix + Formula  // Binop
             * | Formula + Formula          // Intersection
             * 
             * With this 1+1 can be parsed as both 1-1 and 1 (-1)
             * This is obviously erroneous as there is only 1 correct interpertation, so the rules had to be rewritten.
             */

            var parser = new Parser(new ExcelFormulaGrammar());
            Assert.IsTrue(parser.Language.Errors.Count == 0, "Grammar has {0} error(s) or conflict(s)", parser.Language.Errors.Count);
        }
开发者ID:codedecay,项目名称:XLParser,代码行数:28,代码来源:ParserTests.cs


示例12: Read

        public override object Read(string path)
        {
            var rawData = new DecomposeParDictData();
            string txt;
            using (var reader = new StreamReader(path))
            {
                txt = reader.ReadToEnd();
            }

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(txt);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                switch (identifier)
                {
                    case "numberOfSubdomains":
                        rawData.numberOfSubdomains = rootEntryNode.GetBasicValInt();
                        break;
                }
            }
            return rawData;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:25,代码来源:DecomposeParDictHandler.cs


示例13: LoadBnfFile

        private static void LoadBnfFile(string fileName, Builder mainBuilder)
        {
            Console.WriteLine("Parse BNF file: {0}", fileName);

            var bnf = File.ReadAllText(fileName);

            var metaParser = new MetaParser();
            var meta = metaParser.Parse(bnf);

            var oprimizedBnf = Optimize(bnf);

            var parser = new Parser(new BnfGrammar(meta.Mode));
            var tree = parser.Parse(oprimizedBnf, fileName);
            if (tree.Status == ParseTreeStatus.Error)
            {
                throw new Exception((tree.ParserMessages.Count > 0)
                    ? string.Format("{0}, in {3} file at line {1}, column {2}", tree.ParserMessages[0].Message, tree.ParserMessages[0].Location.Line, tree.ParserMessages[0].Location.Column, fileName)
                    : string.Format(@"Unknow error in BNF file {0}", fileName));
            }

            var builder = new Builder(tree, mainBuilder);
            builder.BuildExpressions();

            foreach (var @using in meta.Usings)
                LoadBnfFile(@using, mainBuilder);
        }
开发者ID:vf1,项目名称:bnf2dfa,代码行数:26,代码来源:Program.cs


示例14: ShouldNotParseWithoutCases

        public void ShouldNotParseWithoutCases()
        {
            // Arrange
            var grammar = new CicodeGrammar();
            var parser = new Parser(grammar);
            var sourceCode =
            @"
            FUNCTION A()

            SELECT CASE a
            END SELECT

            END
            ";
            // Act
            var parseTree = parser.Parse(sourceCode);

            // Assert
            Assert.IsNotNull(parseTree);
            Assert.IsTrue(parseTree.HasErrors());
            // A parser error is expected at the end of line 4 because the expected list of cases which is missing
            Assert.AreEqual<int>(1, parseTree.ParserMessages
                .Where(m => m.Location.Line == 4)
                .Where(m => m.ParserState.ExpectedTerminals.First().Name == "CASE")
                .Count());
        }
开发者ID:mayurshkl,项目名称:NCicode,代码行数:26,代码来源:SelectCaseStatementTests.cs


示例15: TestCase

 public void TestCase()
 {
     GLSLGrammar lang = new GLSLGrammar ();
     var compiler = new Irony.Parsing.Parser(lang);
     var tree = compiler.Parse ("void main(void) { float v = vec3(1,1,1); }");
     //CheckNodes (tree.Root, 0);
 }
开发者ID:tgsstdio,项目名称:GLSLSyntax,代码行数:7,代码来源:Test.cs


示例16: ExpandIncludeFiles

            /// <summary>
            /// Insert the string from the include file inside the include directive tag
            /// </summary>
            /// <remarks></remarks>
            private void ExpandIncludeFiles(ParseTreeNode rootNode, T4Grammar grammar, Parser parser)
            {
                var includes = from n in rootNode.ChildNodes
                                   let segmentChild = n.ChildNodes.First()
                                   where segmentChild.Term == grammar.Directive
                                   let dir = segmentChild
                                   let dirName = grammar.GetDirectiveName(dir)
                                   where T4Grammar.IsEqualText(Convert.ToString(dirName), "include")
                                   select dir;
                var includeFiles = from incDir in includes
                                       let filepath = grammar.GetDirectiveAttributes(incDir)["File"]
                                       select new
                                   { DirectiveNode = incDir, File = GetIncludeFile(Convert.ToString(filepath)) };
                foreach (var incFile in includeFiles)
                {
                    //do not expand the same files, in case there's a multiple nested references to the same include files
                    if (_expandedFiles.Contains(incFile.File.FullName)) continue;
                    var text = File.ReadAllText(Convert.ToString(incFile.File.FullName));
                    var content = grammar.GetContentNode(parser.Parse(text));
                    incFile.DirectiveNode.Tag = new TranslationTag { ExpandedParseTreeNode = content };
                    //remember expanded file
                    _expandedFiles.Add(incFile.File.FullName);

                    //recursively process content from include file
                    ExpandIncludeFiles(content, grammar, parser);
                }
            }
开发者ID:Reegenerator,项目名称:Template-T4ToRgenConverterCS,代码行数:31,代码来源:IncludeFileManager.cs


示例17: Read

        public override object Read(string path)
        {
            var rawData = new VelocityData();
            string txt;
            using (var reader = new StreamReader(path))
            {
                txt = reader.ReadToEnd();
            }

            var grammar = new OpenFoamGrammar();
            var parser = new Parser(grammar);
            var tree = parser.Parse(txt);

            foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
            {
                var identifier = rootEntryNode.GetEntryIdentifier();
                switch (identifier)
                {
                    //case "turbineArrayOn":
                    //    rawData.TurbineArrayOn = rootEntryNode.GetBasicValBool();
                    //    break;
                }
            }
            return rawData;
        }
开发者ID:mohsenboojari,项目名称:offwind,代码行数:25,代码来源:VelocityHandler.cs


示例18: Setup

 public void Setup()
 {
     _grammar = new TestGrammar();
       _language = new LanguageData(_grammar);
       _parser = new Parser(_language);
       _context = _parser.Context;
 }
开发者ID:cubean,项目名称:CG,代码行数:7,代码来源:_TerminalTestBase.cs


示例19: HandleFile

        public void HandleFile(string file)
        {
            if (!System.IO.File.Exists(file))
                return;
			try
			{
				FileStream fileStream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

				using (StreamReader reader = new StreamReader(fileStream))
				{
					var parser = new Parser(LuaGrammar.Instance);
					var tree = parser.Parse(reader.ReadToEnd());
					var root = tree.Root;
					if (root != null)
					{
						File = new LuaFile(file, tree.Tokens);
						RefreshTree(root);
						FileManager.Instance.AddFile(File);
					}
					else
					{
						System.Diagnostics.Debug.Print("***********error***********" + file);
					}
				}
			}
			catch(Exception e) 
			{
				BabePackage.Setting.LogError("open file failed:" + e.GetType().FullName);
			}
        }
开发者ID:peterdocter,项目名称:BabeLua,代码行数:30,代码来源:TreeParser.cs


示例20: FileAssembler

 public FileAssembler(Grammar grammar, ISegmentFactory segmentBuilder, IExecutableFactory executableBuilder)
 {
     this.executableBuilder = executableBuilder;
     this.segmentBuilder = segmentBuilder;
     this.ironyGrammar = grammar;
     this.ironyParser = new Parser(ironyGrammar);
 }
开发者ID:gulbanana,项目名称:quasar,代码行数:7,代码来源:FileAssembler.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Parsing.ParsingContext类代码示例发布时间:2022-05-26
下一篇:
C# Parsing.ParseTree类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap