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


C# Lexer.CurrentSource方法代码示例

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


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

示例1: Parse

        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "Pattern " + Type.Name);
            
            int start = lexer.Position;
            
            if (state.Excluded.Contains(this))
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.CurrentSource(), "Excluded");
                return ParseTree.No;
            }
            
		    Precedence oldCurrentPrecedence = state.CurrentPrecedence;
		    
		    if (Precedence.Overwrites(state.CurrentPrecedence))
		        state.CurrentPrecedence = Precedence;

            ParseTree tree = ParseGraph.Parse(lexer, state);
            
            state.CurrentPrecedence = oldCurrentPrecedence;

            if (tree == ParseTree.No)
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start));
                return ParseTree.No;
            }

            state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
            
            return tree;
        }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:31,代码来源:AbstractPattern.cs

示例2: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     lexer.Whitespace(state.RuntimeState);
     
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), range.ToString());
     
     char character = lexer.Peek();
     
     if (!range.Contains(character))
     {
         lexer.ErrorStrings[start].Add(range.ToString());
         
         state.RuntimeState.Runtime.ParseTrace.No(this,
             lexer.SourceFrom(start), TextEscape.Quote(character));
         
         return ParseTree.No;
     }
     
     lexer.Read();
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this,
         lexer.SourceFrom(start), TextEscape.Quote(character));
     
     if (state.BuildTextNodes)
         return new ParseTree(Convert.ToString(character));
     else
         return ParseTree.Yes;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:30,代码来源:CharNode.cs

示例3: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     lexer.Whitespace(state.RuntimeState);
     
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "[]");
     
     char character = lexer.Peek();
     
     if (character == '\0')
     {
         state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "End of source");
         return ParseTree.No;
     }
     
     lexer.Read();
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start), TextEscape.Quote(character));
     
     if (state.BuildTextNodes)
         return new ParseTree(Convert.ToString(character));
     else
         return ParseTree.Yes;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:25,代码来源:AnyNode.cs

示例4: Parse

        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(),
                "precedence alt, current = " + state.CurrentPrecedence
                + ", can equal current = " + state.PrecedenceCanEqualCurrent);

            int start = lexer.Position;
            
            ParseGraphNode oldLeftRecursiveAlts = state.LeftRecursiveAlts;
            
			foreach (PrecedenceAltGroup group in groups)
			{
			    if (state.CurrentPrecedence != null)
			    {
			        if (group.Precedence != null)
			        {
    			        if (state.CurrentPrecedence.Group == group.Precedence.Group)
    			        {
    			            if (group.Precedence.IsLowerThan(state.CurrentPrecedence,
    			                !state.PrecedenceCanEqualCurrent))
    			                    continue;
    			        }
		            }
			    }
			    
			    state.LeftRecursiveAlts = group.LeftRecursiveParseGraph;
			    
				ParseTree tree = group.ParseGraph.Parse(lexer, state);

				if (tree != ParseTree.No)
				{
			        state.LeftRecursiveAlts = oldLeftRecursiveAlts;
                    
				    state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
					return tree;
				}
			}
			
	        state.LeftRecursiveAlts = oldLeftRecursiveAlts;

			state.RuntimeState.Runtime.ParseTrace.No(this, lexer.CurrentSource(), "No alts matched");
            
			return ParseTree.No;
        }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:44,代码来源:PrecedenceAlt.cs

示例5: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     lexer.Whitespace(state.RuntimeState);
     
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(
         this,
         lexer.CurrentSource(),
         TextEscape.Quote(text));
     
     for (int n = 0; n < text.Length; n++)
     {
         char character = lexer.Peek(n);
         
         if (character != text[n])
         {
             string stoppedString;
             
             if (character == '\0')
                 stoppedString = "end";
             else
                 stoppedString = TextEscape.Quote(character);
             
             lexer.ErrorStrings[start + n].Add(TextEscape.Quote(text));
             
             if (n > 0)
                 state.RuntimeState.Runtime.ParseTrace.No(
                     this,
                     lexer.SourceFrom(start),
                     TextEscape.Quote(lexer.Text.Substring(start, n))
                         + "..." + stoppedString);
             else
                 state.RuntimeState.Runtime.ParseTrace.No(
                     this,
                     lexer.SourceFrom(start),
                     stoppedString);
             
             return ParseTree.No;
         }
     }
     
     lexer.Skip(text.Length);
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this,
         lexer.SourceFrom(start));
     
     if (state.BuildTextNodes)
         return new ParseTree(text);
     else
         return ParseTree.Yes;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:52,代码来源:TextNode.cs

示例6: Parse

        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            state.RuntimeState.Runtime.ParseTrace.Enter(this,
                lexer.CurrentSource(), "longest alt");

            int start = lexer.Position;
            
            ParseTree longestTree = null;
            int longestTreeEnd = -1;
            
			foreach (IParseable alt in alts)
			{
				ParseTree tree = alt.Parse(lexer, state);
				
				if (tree != ParseTree.No)
				{
					if (lexer.Position > longestTreeEnd)
					{
					    longestTree = tree;
					    longestTreeEnd = lexer.Position;
					}
				}
				
				lexer.Position = start;
			}
            
            if (longestTree == null)
            {
			    state.RuntimeState.Runtime.ParseTrace.No(this,
			        lexer.CurrentSource(), "No alts matched");
			    
			    return ParseTree.No;
			}
			
			lexer.Position = longestTreeEnd;
			
			state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
			return longestTree;
        }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:39,代码来源:LongestAlt.cs

示例7: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     int start = lexer.Position;
     
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "options");
     
     bool oldBuildTextNodes = state.BuildTextNodes;
     Pattern oldWhitespace = lexer.WhitespacePattern;
     Precedence oldCurrentPrecedence = state.CurrentPrecedence;
     bool oldPrecedenceCanEqualCurrent = state.PrecedenceCanEqualCurrent;
     
     if (buildTextNodes.HasValue)
         state.BuildTextNodes = buildTextNodes.Value;
     
     if (whitespace.HasValue)
     {
         lexer.Whitespace(state.RuntimeState);
         lexer.WhitespacePattern = whitespace.Value;
     }
     
     if (exclude.HasValue)
         state.Excluded.Add(exclude.Value);
     
     if (dropPrecedence.HasValue && dropPrecedence.Value)
     {
         state.CurrentPrecedence = null;
         state.PrecedenceCanEqualCurrent = false;
     }
     
     ParseTree tree = body.Parse(lexer, state);
     
     state.BuildTextNodes = oldBuildTextNodes;
     lexer.WhitespacePattern = oldWhitespace;
 
     if (exclude.HasValue)
         state.Excluded.Remove(exclude.Value);
     
     state.CurrentPrecedence = oldCurrentPrecedence;
     state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent;
     
     if (tree == ParseTree.No)
     {
         state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start));
         return ParseTree.No;
     }
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
     
     return tree;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:50,代码来源:OptionsNode.cs

示例8: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     int start = lexer.Position;
     
     if (type == null)
         throw new Exception();
     
     if (state.RuntimeState.Runtime.TraceParser)
         state.RuntimeState.Runtime.ParseTrace.Enter(this,
             lexer.CurrentSource(),
             "User defined node " + TypeNames.GetName(type));
     
     object instance = NewNode.New(state.RuntimeState, type, null);
     object parseMethod = MemberNode.GetMember(instance, "Parse", true);
     object result = CallNode.Call(state.RuntimeState, parseMethod,
         new object[]{lexer});
     
     if (result == null)
         result = ParseTree.Yes;
     else if (result is bool)
     {
         if ((bool) result)
             result = ParseTree.Yes;
         else
             result = ParseTree.No;
     }
     
     if (state.RuntimeState.Runtime.TraceParser)
     {
         if (result == ParseTree.No)
             state.RuntimeState.Runtime.ParseTrace.No(this,
                 lexer.SourceFrom(start));
         else
             state.RuntimeState.Runtime.ParseTrace.Yes(this,
                 lexer.SourceFrom(start));
     }
     
     return (ParseTree) result;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:39,代码来源:UserDefinedNode.cs

示例9: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "token");
     
     int start = lexer.Position;
     
     ParseTree bodyTree = body.Parse(lexer, state);
     
     if (bodyTree == ParseTree.No)
     {
         state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start));
         return ParseTree.No;
     }
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
     
     ParseTree tokenTree = new ParseTree(
         lexer.Text.Substring(start, lexer.Position - start));
     
     tokenTree = tokenTree.ExtendFields(bodyTree);
     
     return tokenTree;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:23,代码来源:TokenNode.cs

示例10: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), Reps.Name);
     
     int start = lexer.Position;
     bool matched = false;
     
     ParseTree tree = ParseTree.Yes;
     
     while (true)
     {
         ParseTree repTree = body.Parse(lexer, state);
         
         if (repTree == ParseTree.No)
             break;
         
         tree = tree.Extend(repTree);
         
         if (reps.MaximumOfOne)
             break;
         
         matched = true;
     }
     
     if ((reps.Minimum > 0) && !matched)
     {
         state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "Not enough reps");
         
         lexer.Position = start;
         return ParseTree.No;
     }
     
     state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start));
     
     return tree;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:36,代码来源:RepNode.cs

示例11: Parse

        public override ParseTree Parse(Lexer lexer, ParserState state)
        {
            int start = lexer.Position;
            
            state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "Pattern " + Type.Name);
            
            /*state.RuntimeState.Runtime.ParseTrace.Enter(this, lexer.CurrentSource(), "Excluded:");
            
            foreach (Pattern excluded in state.Excluded)
                state.RuntimeState.Runtime.ParseTrace.Single(excluded.Type.Name);
            
            state.RuntimeState.Runtime.ParseTrace.Leave(this);*/
            
            if (state.Excluded.Contains(this))
            {
                state.RuntimeState.Runtime.ParseTrace.No(this, lexer.CurrentSource(), "Excluded");
                return ParseTree.No;
            }
            
            ParserMemoryKey key = new ParserMemoryKey(this, start);
            
            bool oldSkipMemoryForLeftRecursion = state.SkipMemoryForLeftRecursion;
            
            if (state.SkipMemoryForLeftRecursion)
            {
                state.SkipMemoryForLeftRecursion = false;
            }
            else
            {
                ParserMemoryEntry entry;
                
                if (state.Memory.TryGetValue(key, out entry))
                {
                    state.RuntimeState.Runtime.ParseTrace.LinkNext(entry.Tag);

                    if (entry.Tree == ParseTree.No)
                    {
                        state.RuntimeState.Runtime.ParseTrace.No(this, lexer.SourceFrom(start), "From memory");
                    }
                    else
                    {
                        state.RuntimeState.Runtime.ParseTrace.Yes(this, lexer.SourceFrom(start), "From memory");
                        lexer.Position = entry.End;
                    }

                    return entry.Tree;
                }
            }
            
            ConcretePattern oldRecursionExclude = state.RecursionExclude;
            
            if (RecursionBehaviour != RecursionBehaviour.Recursive)
            {
                if (state.RecursionExclude != null)
                    state.Excluded.Remove(state.RecursionExclude);
                
                state.RecursionExclude = this;
                
                state.Excluded.Add(this);
            }
            
            RecursionBehaviour oldRecursionBehaviour = state.RecursionBehaviour;
            state.RecursionBehaviour = RecursionBehaviour;
            
            Precedence oldCurrentPrecedence = state.CurrentPrecedence;
            
            if (Precedence.Overwrites(state.CurrentPrecedence))
                state.CurrentPrecedence = Precedence;

            bool oldPrecedenceCanEqualCurrent = state.PrecedenceCanEqualCurrent;
            state.PrecedenceCanEqualCurrent = RecursionBehaviour == RecursionBehaviour.Recursive;
            
            ParseTree tree = ParseGraph.Parse(lexer, state);
            
            state.CurrentPrecedence = oldCurrentPrecedence;
            state.PrecedenceCanEqualCurrent = oldPrecedenceCanEqualCurrent;
            state.RecursionBehaviour = oldRecursionBehaviour;
            state.RecursionExclude = oldRecursionExclude;
            state.SkipMemoryForLeftRecursion = oldSkipMemoryForLeftRecursion;
            
            if (RecursionBehaviour != RecursionBehaviour.Recursive)
            {
                if (oldRecursionExclude != null)
                    state.Excluded.Add(oldRecursionExclude);
                
                state.Excluded.Remove(this);
            }
            
            if (tree != ParseTree.No)
            {
                lexer.Whitespace(state.RuntimeState);
                tree = Instantiate(lexer, state, start, tree);
            }
            
            object nextTag = new object();
        
            state.RuntimeState.Runtime.ParseTrace.TagNext(nextTag);
            
            if (tree == ParseTree.No)
            {
//.........这里部分代码省略.........
开发者ID:KevinKelley,项目名称:katahdin,代码行数:101,代码来源:ConcretePattern.cs

示例12: Parse

 public override ParseTree Parse(Lexer lexer, ParserState state)
 {
     state.RuntimeState.Runtime.ParseTrace.Single(lexer.CurrentSource(), message);
     
     return ParseTree.No;
 }
开发者ID:KevinKelley,项目名称:katahdin,代码行数:6,代码来源:FailNode.cs


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