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


C# Parsing.Parser类代码示例

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


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


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