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


C# ISourceStream.CreateToken方法代码示例

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


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

示例1: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   string tokenText = string.Empty;
   while (true) {
     //Find next position
     var newPos = source.Text.IndexOfAny(_stopChars, source.PreviewPosition);
     if(newPos == -1) {
       if(IsSet(FreeTextOptions.AllowEof)) {
         source.PreviewPosition = source.Text.Length;
         return source.CreateToken(this.OutputTerminal);
       }  else
         return null;
     }
     if (newPos == source.PreviewPosition)   // DC
     {
         context.AddParserError("(DC) in TryMatch, newPos == source.PreviewPosition", new object[] {});
         break;                              // DC
     }
     tokenText += source.Text.Substring(source.PreviewPosition, newPos - source.PreviewPosition);
     source.PreviewPosition = newPos;
     //if it is escape, add escaped text and continue search
     if (CheckEscape(source, ref tokenText)) 
       continue;
     //check terminators
     if (CheckTerminators(source, ref tokenText))
       break; //from while (true)        
   }
   return source.CreateToken(this.OutputTerminal, tokenText);
 }
开发者ID:pusp,项目名称:o2platform,代码行数:28,代码来源:FreeTextLiteral.cs

示例2: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   bool isEscape = source.PreviewChar == EscapeChar && EscapeChar != NoEscape;
   if(isEscape) {
     //return a token containing only escaped char
     var value = source.NextPreviewChar.ToString(); 
     source.PreviewPosition += 2; 
     return source.CreateToken(this.OutputTerminal, value);  
   }
   var stopIndex = source.Text.IndexOfAny(_stopChars, source.Location.Position + 1);
   if (stopIndex == source.Location.Position) return null; 
   if (stopIndex < 0) stopIndex = source.Text.Length; 
   source.PreviewPosition = stopIndex;
   return source.CreateToken(this.OutputTerminal);
 }//method
开发者ID:androdev4u,项目名称:XLParser,代码行数:14,代码来源:WikiTextTerminal.cs

示例3: MatchQuoted

        private Token MatchQuoted(ParsingContext context, ISourceStream source)
        {
            char quoteChar = source.PreviewChar;
            if ((quoteChar != '\'') && (quoteChar != '"'))
            {
                return null;
            }

            source.PreviewPosition++;
            while (!source.EOF())
            {
                if (source.PreviewChar == quoteChar)
                {
                    source.PreviewPosition++;
                    return source.CreateToken(this.OutputTerminal);
                }

                // Escaped?
                if (source.PreviewChar == '\\')
                {
                    // Consume next
                    ++source.PreviewPosition;
                }

                source.PreviewPosition++;
            }

            return context.CreateErrorToken("Unbalanced quoted string");
        }
开发者ID:tmatz,项目名称:XamlStyler,代码行数:29,代码来源:MemberNameOrStringTerminal.cs

示例4: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   Match m = _expression.Match(source.Text, source.PreviewPosition);
   if (!m.Success || m.Index != source.PreviewPosition) 
     return null;
   source.PreviewPosition += m.Length;
   return source.CreateToken(this.OutputTerminal); 
 }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:7,代码来源:RegExBasedTerminal.cs

示例5: CreateIncompleteToken

 private Token CreateIncompleteToken(ParsingContext context, ISourceStream source) {
   source.PreviewPosition = source.Text.Length;
   Token result = source.CreateToken(this.OutputTerminal);
   result.Flags |= TokenFlags.IsIncomplete;
   context.VsLineScanState.TerminalIndex = this.MultilineIndex;
   return result; 
 }
开发者ID:kayateia,项目名称:climoo,代码行数:7,代码来源:CommentTerminal.cs

示例6: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   char current = source.PreviewChar;
   if (!LineTerminators.Contains(current)) return null;
   //Treat \r\n as a single terminator
   bool doExtraShift = (current == '\r' && source.NextPreviewChar == '\n');
   source.PreviewPosition++; //main shift
   if (doExtraShift)
     source.PreviewPosition++;
   Token result = source.CreateToken(this.OutputTerminal);
   return result;
 }
开发者ID:androdev4u,项目名称:XLParser,代码行数:11,代码来源:NewLineTerminal.cs

示例7: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   try {
     var textValue = ReadBody(context, source);
     if (textValue == null) return null; 
     var value = ConvertValue(context, textValue);
     return source.CreateToken(this.OutputTerminal, value);
   } catch(Exception ex) {
     //we throw exception in DsvLiteral when we cannot find a closing quote for quoted value
     return source.CreateErrorToken(ex.Message);
   }
 }//method
开发者ID:cg123,项目名称:xenko,代码行数:11,代码来源:DataLiteralBase.cs

示例8: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   if (!source.MatchSymbol(OpenTag, true)) return null;
   source.PreviewPosition += OpenTag.Length;
   var endPos = source.Text.IndexOf(CloseTag, source.PreviewPosition);
   string content; 
   if(endPos > 0) {
     content = source.Text.Substring(source.PreviewPosition, endPos - source.PreviewPosition); 
     source.PreviewPosition = endPos + CloseTag.Length;
   } else {
     content = source.Text.Substring(source.PreviewPosition, source.Text.Length - source.PreviewPosition); 
     source.PreviewPosition = source.Text.Length;
   }
   var token = source.CreateToken(this.OutputTerminal, content); 
   return token;      
 }
开发者ID:mtashkinov,项目名称:YaccConstructor,代码行数:15,代码来源:WikiBlockTerminal.cs

示例9: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   bool isHeadingOrList = TermType == WikiTermType.Heading || TermType == WikiTermType.List;
   if(isHeadingOrList) {
       bool isAfterNewLine = (context.PreviousToken == null || context.PreviousToken.Terminal == Grammar.NewLine);
       if(!isAfterNewLine)  return null;
   }
   if(!source.MatchSymbol(OpenTag)) return null;
   source.PreviewPosition += OpenTag.Length;
   //For headings and lists require space after
   if(TermType == WikiTermType.Heading || TermType == WikiTermType.List) {
     const string whitespaces = " \t\r\n\v";
     if (!whitespaces.Contains(source.PreviewChar)) return null; 
   }
   var token = source.CreateToken(this.OutputTerminal);
   return token; 
 }
开发者ID:kayateia,项目名称:climoo,代码行数:16,代码来源:WikiTagTerminal.cs

示例10: CreateToken

        protected Token CreateToken(ISourceStream source, int lastNonWhitespacePosition)
        {
            if (lastNonWhitespacePosition > source.Position)
            {
                // Remember position
                var pos = source.PreviewPosition;

                // Move position back to last non whitespace (or significant whitespace)
                source.PreviewPosition = lastNonWhitespacePosition;
                var token = source.CreateToken(this.OutputTerminal);

                // Restore position
                source.PreviewPosition = pos;
                return token;
            }
            return null;
        }
开发者ID:NicoVermeir,项目名称:XamlStyler,代码行数:17,代码来源:MemberNameOrStringTerminal.cs

示例11: MatchCodeTerminal

 Token MatchCodeTerminal(Terminal terminal, ParsingContext context, ISourceStream source)
 {
     var remaining = source.Text.Substring(source.Location.Position);
     var stack = 1;
     var token = "";
     while (stack > 0)
     {
         var index = remaining.IndexOf('}') + 1;
         var cut = remaining.Substring(0, index);
         token += cut;
         remaining = remaining.Substring(index);
         stack += cut.Count(x => x == '{');
         stack--;
     }
     token = token.Substring(0, token.Length - 1);
     source.PreviewPosition += token.Length;
     return source.CreateToken(terminal.OutputTerminal);
 }
开发者ID:Dchapz,项目名称:LiveSplit.ScriptableAutoSplit,代码行数:18,代码来源:ASLGrammar.cs

示例12: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source) {
   Token result;
   if (context.VsLineScanState.Value != 0) {
     // we are continuing in line mode - restore internal env (none in this case)
     context.VsLineScanState.Value = 0;
   } else {
     //we are starting from scratch
     if (!BeginMatch(context, source)) return null;
   }
   result = CompleteMatch(context, source);
   if (result != null) return result;
   //if it is LineComment, it is ok to hit EOF without final line-break; just return all until end.
   if (_isLineComment)
     return source.CreateToken(this.OutputTerminal);
   if (context.Mode == ParseMode.VsLineScan)
     return CreateIncompleteToken(context, source);
   return context.CreateErrorToken(Resources.ErrUnclosedComment);
 }
开发者ID:kayateia,项目名称:climoo,代码行数:18,代码来源:CommentTerminal.cs

示例13: TryMatch

        public override Token TryMatch(ParsingContext context, ISourceStream source)
        {
            while (!source.EOF())
            {
                switch (source.PreviewChar)
                {
                    case '\n':
                    case '\r':
                    case ' ':
                    case '}':
                        if (source.PreviewPosition > source.Position)
                            return source.CreateToken(this.OutputTerminal);
                        return context.CreateErrorToken(Name + " was expected");
                }
                source.PreviewPosition++;
            }

            return context.CreateErrorToken("Unbalanced " + Name);
        }
开发者ID:NicoVermeir,项目名称:XamlStyler,代码行数:19,代码来源:TypeNameTerminal.cs

示例14: TryMatchContentSimple

 private Token TryMatchContentSimple(ParsingContext context, ISourceStream source)
 {
     var startPos = source.PreviewPosition;
       int p = source.Text.IndexOf(_singleTerminator, startPos, Grammar.StringComparisonMode);
       if (p < 0 && IsSet(FreeTextOptions.AllowEof))
     p = source.Text.Length;
       if (p < 0)
     return source.CreateErrorToken(Resources.ErrFreeTextNoEndTag, _singleTerminator);
       var tokenText = source.Text.Substring(startPos, p - startPos);
       return source.CreateToken(this.OutputTerminal, tokenText);
 }
开发者ID:guillaume86,项目名称:vsLua,代码行数:11,代码来源:FreeTextLiteral.cs

示例15: TryMatch

 public override Token TryMatch(ParsingContext context, ISourceStream source)
 {
     var Match = MatchRegex.Match(source.Text, source.PreviewPosition);
     if (!Match.Success || Match.Index != source.PreviewPosition) return null;
     source.PreviewPosition += Match.Length;
     return source.CreateToken(this.OutputTerminal);
 }
开发者ID:soywiz,项目名称:llvm-to-msil,代码行数:7,代码来源:LLVMGrammar.cs


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