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


C# Parsing.ParseTree类代码示例

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


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

示例1: TryParse

        public bool TryParse(string sourceText, out MarkupExtension graph)
        {
            graph = null;

            try
            {
                ParseTree tree = _parser.Parse(sourceText);
            #if DEBUG
                // Save result tree for debugging purposes
                LastParseTree = tree;
                LastException = null;
            #endif
                if (tree.Status == ParseTreeStatus.Parsed)
                {
                    graph = MarkupExtension.Create(tree.Root);
                    return true;
                }
            }
            #if DEBUG
            catch (Exception ex)
            {
                LastParseTree = null;
                LastException = ex;
            }
            #else
            catch
            {
                // ignored
            }
            #endif
            return false;
        }
开发者ID:NicoVermeir,项目名称:XamlStyler,代码行数:32,代码来源:MarkupExtensionParser.cs

示例2: BuildAst

 public override void BuildAst(LanguageData language, ParseTree parseTree) {
   var opHandler = new OperatorHandler(language.Grammar.CaseSensitive);
   Util.Check(!parseTree.HasErrors(), "ParseTree has errors, cannot build AST.");
   var astContext = new InterpreterAstContext(language, opHandler);
   var astBuilder = new AstBuilder(astContext);
   astBuilder.BuildAst(parseTree);
 }
开发者ID:androdev4u,项目名称:XLParser,代码行数:7,代码来源:InterpretedLanguageGrammar.cs

示例3: BuildAst

 public virtual void BuildAst(LanguageData language, ParseTree parseTree)
 {
     if (!LanguageFlags.IsSet(LanguageFlags.CreateAst))
         return;
     var astContext = new AstContext(language);
     var astBuilder = new AstBuilder(astContext);
     astBuilder.BuildAst(parseTree);
 }
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:8,代码来源:Grammar.cs

示例4: NormalizeParseTree

 private string NormalizeParseTree(ParseTree tree) {
     StringBuilder fullString = new StringBuilder();
     foreach (ParseTreeNode node in tree.Root.ChildNodes) {
         fullString.Append(node.Token.Value);
     }
     fullString = fullString.Replace("\r\n", "\\n");
     fullString = fullString.Replace("\n", "\\n");
     return fullString.ToString();
 }
开发者ID:Rezura,项目名称:LiveSplit,代码行数:9,代码来源:HeredocTerminalTests.cs

示例5: BuildAst

 public virtual void BuildAst(ParseTree parseTree) {
   if (parseTree.Root == null)
     return; 
   Context.Messages = parseTree.ParserMessages;
   if (!Context.Language.AstDataVerified)
     VerifyLanguageData();
   if (Context.Language.ErrorLevel == GrammarErrorLevel.Error)
     return; 
   BuildAst(parseTree.Root);
 }
开发者ID:androdev4u,项目名称:XLParser,代码行数:10,代码来源:AstBuilder.cs

示例6: ParseString

 public Block ParseString(string Chunk)
 {
     var parseTree = parser.Parse(Chunk);
     curParseTree = parseTree;
     var root = parseTree.Root;
     if (root == null)
     {
         var msg = parseTree.ParserMessages[0];
         throw new LuaException("", msg.Location.Line, msg.Location.Column, msg.Message);
     }
     return (ParseBlock(root));
 }
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:12,代码来源:Parser.cs

示例7: GetParserMessages

 private string GetParserMessages(ParseTree parseTree)
 {
     var sb = new StringBuilder();
     foreach (var message in parseTree.ParserMessages)
     {
         sb.AppendFormat("{0} at line {1}, column {2}", message.Message, message.Location.Line, message.Location.Column);
     }
     sb.AppendLine();
     sb.AppendLine("Source Code:");
     sb.AppendLine();
     sb.Append(parseTree.SourceText);
     return sb.ToString();
 }
开发者ID:mayurshkl,项目名称:NCicode,代码行数:13,代码来源:CicodeFileTests.cs

示例8: ParseFile

 public Block ParseFile(string Filename)
 {
     var source = File.ReadAllText(Filename);
     var parseTree = parser.Parse(source, Filename);
     curParseTree = parseTree;
     var root = parseTree.Root;
     if (root == null)
     {
         var msg = parseTree.ParserMessages[0];
         throw new LuaException(Filename, msg.Location.Line, msg.Location.Column, msg.Message);
     }
     return (ParseBlock(root));
 }
开发者ID:HyperSharp,项目名称:Hyperspace.DotLua,代码行数:13,代码来源:Parser.cs

示例9: Refresh

        public void Refresh(ParseTree tree)
        {
            var root = tree.Root;
            if (root != null)
            {
                File = new LuaFile(FileManager.Instance.CurrentFile.File, tree.Tokens); ;

                RefreshTree(root);

                FileManager.Instance.CurrentFile = File;

                System.Diagnostics.Debug.Print("file refreshed.");
            }
        }
开发者ID:peterdocter,项目名称:BabeLua,代码行数:14,代码来源:TreeParser.cs

示例10: Analyze

        private Expression Analyze(ParseTree tree, CompilerState state)
        {
            if (tree == null)
            {
                throw new ArgumentNullException("tree");
            }

            if (tree.Status != ParseTreeStatus.Parsed)
            {
                throw new ArgumentException("Cannot build expression on incomplete tree");
            }

            var root = tree.Root;
            return Analyze(root, state);
        }
开发者ID:adrobyazko-softheme,项目名称:PQL,代码行数:15,代码来源:ExpressionEvaluatorRuntime(Compiler).cs

示例11: Read

        /// <summary>
        /// Reads a Dql query into an abstract syntax tree.
        /// </summary>
        /// <param name="query">Dql query.</param>
        /// <param name="node">The current abstract syntax tree to construct.</param>
        /// <returns>Time taken to build the abstract syntax tree in milliseconds.</returns>
        public long Read(string query, out ParseTree node)
        {
            var parser = new Parser(language);
            var tree = parser.Parse(query);

            if (tree.HasErrors())
            {
                // TODO: Throw LQL errors.
                throw new InvalidOperationException();
            }

#if DEBUG
            this.DisplayTree(tree.Root, 0);
#endif
            node = tree;
            return tree.ParseTimeMilliseconds;
        }
开发者ID:kellabyte,项目名称:Dazzle.NET,代码行数:23,代码来源:DqlQueryReader.cs

示例12: ParseSample

 public void ParseSample(string code)
 {
     if (parser == null || !parser.Language.CanParse()) return;
     ParseTree = null;
     GC.Collect(); //to avoid disruption of perf times with occasional collections
     parser.Context.TracingEnabled = false;//parsetrace not needed for us
     try {
         parser.Parse(code, "<source>");
     }
     catch (Exception ex) {
         Console.WriteLine(ex.Message);
         throw;
     }
     finally {
         ParseTree = parser.Context.CurrentParseTree;
     }
 }
开发者ID:zackszhu,项目名称:ZodiacLanguage,代码行数:17,代码来源:GrammarAnalysizer.cs

示例13: GenerateCode

        public CodeCompileUnit GenerateCode(ParseTree tree)
        {
            var generator = new RuleCodeGenerator();
            var unit = new CodeCompileUnit();
            var ns = new CodeNamespace(GetType().Namespace);
            ns.Imports.Add(new CodeNamespaceImport(GetType().Namespace));

            var rules = tree.Root.ChildNodes[0].ChildNodes;
            var count = 1;
            foreach (var rule in rules)
            {
                ns.Types.Add(generator.GenerateRuleClass("Rule" + count, rule));
                count++;
            }

            unit.Namespaces.Add(ns);
            return unit;
        }
开发者ID:ByteCarrot,项目名称:Masslog,代码行数:18,代码来源:RulesCodeGenerator.cs

示例14: ConvertParseTreeToModel

        public static LPModel ConvertParseTreeToModel(ParseTree tree)
        {
            string modelName = "";
            var lpGoal = new LPGoal();
            var lpConstraints = new List<LPConstraint>();

            if (tree.Root.ToString() == "lpApp")
            {
                foreach (ParseTreeNode node in tree.Root.ChildNodes)
                {
                    switch (node.ToString())
                    {
                        case "lpAppName":
                            modelName = ParseModelName(node);
                            break;
                        case "lpModel":
                            foreach (ParseTreeNode subNodes in node.ChildNodes)
                            {
                                switch (subNodes.ToString())
                                {
                                    case "lpGoal":
                                        lpGoal = ParseGoal(subNodes);
                                        break;
                                    case "lpConstraints":
                                        lpConstraints = ParseConstraints(subNodes);
                                        break;
                                }
                            }
                            break;
                    }
                }
            }
            else
            {
                throw new Exception("The Root element is not Correct");
            }

            return new LPModel(modelName.Replace("(appIdentifier)", "").Replace(" ", ""), lpGoal, lpConstraints);
        }
开发者ID:taesiri,项目名称:lpSolver,代码行数:39,代码来源:Modeler.cs

示例15: Generate

        public void Generate(ParseTree parseTree) {
            if (parseTree == null) return;
            GeneratedOK = true;
            defaultClass = ag.Public.Class("Default");
            typeTable.Add("Default", defaultClass);
            mainMethod = defaultClass.Public.Static.Method(typeof(void), "Main");

            //generator stack
            typeStack.Push(defaultClass);
            funcStack.Push(mainMethod);

            //InitIO();
            InitRequiredType();
            PushScope();
            var ioOperand = mainMethod.Local(exp.New(typeTable["IO"]));

            ParseNode(parseTree.Root);
            
            if (GeneratedOK) {
                ag.Save();
                AppDomain.CurrentDomain.ExecuteAssembly(name + ".exe");
            }
        }
开发者ID:zackszhu,项目名称:ZodiacLanguage,代码行数:23,代码来源:CodeGenerator.cs


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