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


C# Tokenizer.Peek方法代码示例

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


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

示例1: Parse

        // Returns list of 2-element arrays, element 0 is field name (or null), element 1 is term/phrase
        public List<NuGetSearchTerm> Parse(string searchTerm)
        {
            var terms = new List<NuGetSearchTerm>();
            _tokenizer = new Tokenizer(searchTerm);
            while (_tokenizer.Peek() != TokenType.Eof)
            {
                var term = new NuGetSearchTerm();
                if (_tokenizer.Peek() == TokenType.Field)
                {
                    if (ParseField(term))
                    {
                        terms.Add(term);
                    }
                }
                else
                {
                    if (ParseTermOrPhrase(term))
                    {
                        terms.Add(term);
                    }
                }
            }

            return terms;
        }
开发者ID:ZhiYuanHuang,项目名称:NuGetGallery,代码行数:26,代码来源:NuGetQueryParser.cs

示例2: CompileLayout

        internal static LayoutRenderer[] CompileLayout(ConfigurationItemFactory configurationItemFactory, Tokenizer sr, bool isNested, out string text)
        {
            var result = new List<LayoutRenderer>();
            var literalBuf = new StringBuilder();

            int ch;

            int p0 = sr.Position;

            while ((ch = sr.Peek()) != -1)
            {
                if (isNested && (ch == '}' || ch == ':'))
                {
                    break;
                }

                sr.Read();

                if (ch == '$' && sr.Peek() == '{')
                {
                    if (literalBuf.Length > 0)
                    {
                        result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                        literalBuf.Length = 0;
                    }

                    LayoutRenderer newLayoutRenderer = ParseLayoutRenderer(configurationItemFactory, sr);
                    if (CanBeConvertedToLiteral(newLayoutRenderer))
                    {
                        newLayoutRenderer = ConvertToLiteral(newLayoutRenderer);
                    }

                    // layout renderer
                    result.Add(newLayoutRenderer);
                }
                else
                {
                    literalBuf.Append((char)ch);
                }
            }

            if (literalBuf.Length > 0)
            {
                result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                literalBuf.Length = 0;
            }

            int p1 = sr.Position;

            MergeLiterals(result);
            text = sr.Substring(p0, p1);

            return result.ToArray();
        }
开发者ID:ChadBurggraf,项目名称:NLog,代码行数:54,代码来源:LayoutParser.cs

示例3: ParseParameterName

        private static string ParseParameterName(Tokenizer sr)
        {
            int ch;
            int nestLevel = 0;

            StringBuilder nameBuf = new StringBuilder();
            while ((ch = sr.Peek()) != -1)
            {
                if ((ch == '=' || ch == '}' || ch == ':') && nestLevel == 0)
                    break;
                if (ch == '$')
                {
                    sr.Read();
                    nameBuf.Append('$');
                    if (sr.Peek() == '{')
                    {
                        nameBuf.Append('{');
                        nestLevel++;
                        sr.Read();
                    }
                    continue;
                }
                if (ch == '}')
                {
                    nestLevel--;
                }
                if (ch == '\\')
                {
                    // skip the backslash
                    sr.Read();

                    // append next character
                    nameBuf.Append((char)sr.Read());
                    continue;
                }
                nameBuf.Append((char)ch);
                sr.Read();
            }

            return nameBuf.ToString();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:41,代码来源:LayoutParser.cs

示例4: ParseLayoutRendererName

        private static string ParseLayoutRendererName(Tokenizer sr)
        {
            int ch;

            StringBuilder nameBuf = new StringBuilder();
            while ((ch = sr.Peek()) != -1)
            {
                if (ch == ':' || ch == '}')
                    break;
                nameBuf.Append((char)ch);
                sr.Read();
            }

            return nameBuf.ToString();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:15,代码来源:LayoutParser.cs

示例5: Comma

        private void Comma(Tokenizer.Tokenizer tokenizer, Boolean optional = false)
        {
            AbstractToken token = tokenizer.Peek();

            if (token.GetType() == typeof(Comma))
            {
                tokenizer.NextToken();
                return;
            }

            if (optional)
            {
                return;
            }

            throw new ParseException("Expected type Comma but found: " + token.GetType() + " after " + tokenizer.GetPreviousCharacters(25));
        }
开发者ID:MaikelH,项目名称:BibtexLibrary,代码行数:17,代码来源:BibtexParser.cs

示例6: CompileLayout

        internal static LayoutRenderer[] CompileLayout(Tokenizer sr, bool isNested, out string text)
        {
            List<LayoutRenderer> result = new List<LayoutRenderer>();
            StringBuilder literalBuf = new StringBuilder();

            int ch;

            int p0 = sr.Position;

            while ((ch = sr.Peek()) != -1)
            {
                if (isNested && (ch == '}' || ch == ':'))
                {
                    break;
                }
                sr.Read();

                if (ch == '$' && sr.Peek() == '{')
                {
                    if (literalBuf.Length > 0)
                    {
                        result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                        literalBuf.Length = 0;
                    }

                    LayoutRenderer newLayoutRenderer = ParseLayoutRenderer(sr);
                    if (newLayoutRenderer.IsAppDomainFixed())
                        newLayoutRenderer = ConvertToLiteral(newLayoutRenderer);
                    result.Add(newLayoutRenderer);
                    // layout renderer
                }
                else
                {
                    literalBuf.Append((char)ch);
                }
            }

            if (literalBuf.Length > 0)
            {
                result.Add(new LiteralLayoutRenderer(literalBuf.ToString()));
                literalBuf.Length = 0;
            }
            int p1 = sr.Position;

            MergeLiterals(result);
            text = sr.Substring(p0, p1);

            return result.ToArray();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:49,代码来源:LayoutParser.cs

示例7: ParseLayoutRenderer

        private static LayoutRenderer ParseLayoutRenderer(Tokenizer sr)
        {
            int ch;

            ch = sr.Read();
            if (ch != '{')
                throw new NLogConfigurationException("'{' expected in layout specification");

            string name = ParseLayoutRendererName(sr);
            LayoutRenderer lr = LayoutRendererFactory.CreateLayoutRenderer(name, null);

            ch = sr.Read();
            while (ch != -1 && ch != '}')
            {
                string parameterName = ParseParameterName(sr).Trim();
                if (sr.Peek() == '=')
                {
                    sr.Read(); // skip the '='
                    PropertyInfo pi = PropertyHelper.GetPropertyInfo(lr, parameterName);
                    if (pi == null)
                    {
                        ParseParameterValue(sr);
                    }
                    else
                    {
                        if (typeof(Layout) == pi.PropertyType)
                        {
                            Layout nestedLayout = new Layout();
                            string txt;
                            LayoutRenderer[] renderers = CompileLayout(sr, true, out txt);

                            nestedLayout.SetRenderers(renderers, txt);
                            pi.SetValue(lr, nestedLayout, null);
                        }
                        else
                        {
                            string value = ParseParameterValue(sr);
                            PropertyHelper.SetPropertyFromString(lr, parameterName, value, null);
                        }
                    }
                }
                else
                {
                    // what we've just read is not a parameterName, but a value
                    // assign it to a default property (denoted by empty string)

                    PropertyInfo pi = PropertyHelper.GetPropertyInfo(lr, "");
                    if (pi != null)
                    {
                        if (typeof(Layout) == pi.PropertyType)
                        {
                            pi.SetValue(lr, new Layout(parameterName), null);
                        }
                        else
                        {
                            string value = parameterName;
                            PropertyHelper.SetPropertyFromString(lr, pi.Name, value, null);
                        }
                    }
                    else
                    {
                        InternalLogger.Warn("{0} has no default property", lr.GetType().FullName);
                    }
                }
                ch = sr.Read();
            }
            return lr;
        }
开发者ID:pallmall,项目名称:WCell,代码行数:68,代码来源:LayoutParser.cs

示例8: ParseParameterValue

        private static string ParseParameterValue(Tokenizer sr)
        {
            int ch;

            StringBuilder nameBuf = new StringBuilder();
            while ((ch = sr.Peek()) != -1)
            {
                if (ch == ':' || ch == '}')
                    break;
                if (ch == '\\')
                {
                    // skip the backslash
                    sr.Read();

                    // append next character
                    nameBuf.Append((char)sr.Read());
                    continue;
                }
                nameBuf.Append((char)ch);
                sr.Read();
            }

            return nameBuf.ToString();
        }
开发者ID:pallmall,项目名称:WCell,代码行数:24,代码来源:LayoutParser.cs

示例9: NextValue

 private object NextValue(Tokenizer tokenizer) {
   if (tokenizer.Peek() == tokenizer.SeparatorToken || tokenizer.Peek() == tokenizer.NewlineToken) return string.Empty;
   Token current = tokenizer.Next();
   if (current.type == TokenTypeEnum.Separator) {
     return double.NaN;
   } else if (current.type == TokenTypeEnum.String) {
     return current.stringValue;
   } else if (current.type == TokenTypeEnum.Double) {
     return current.doubleValue;
   } else if (current.type == TokenTypeEnum.DateTime) {
     return current.dateTimeValue;
   }
   // found an unexpected token => throw error 
   Error("Unexpected token.", current.stringValue, tokenizer.CurrentLineNumber);
   // this line is never executed because Error() throws an exception
   throw new InvalidOperationException();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:17,代码来源:TableFileParser.cs

示例10: AreColumnNamesInFirstLine

 public bool AreColumnNamesInFirstLine(Stream stream, NumberFormatInfo numberFormat,
                                       DateTimeFormatInfo dateTimeFormatInfo, char separator) {
   using (StreamReader reader = new StreamReader(stream)) {
     tokenizer = new Tokenizer(reader, numberFormat, dateTimeFormatInfo, separator);
     return tokenizer.Peek().type != TokenTypeEnum.Double;
   }
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:TableFileParser.cs

示例11: Tags

        /// <summary>
        /// Retrieves the tag values from the input. 
        /// </summary>
        /// <param name="tokenizer"></param>
        /// <returns></returns>
        /// 
        private ICollection<Tag> Tags(Tokenizer.Tokenizer tokenizer)
        {
            // This function needs some refactoring.
            List<Tag> tags = new List<Tag>();

            while (tokenizer.Peek().GetType() != typeof (ClosingBrace))
            {
                Tag tag = new Tag {Key = Text(tokenizer)};
                Equals(tokenizer);
                AbstractToken startToken = ValueStart(tokenizer);

                List<AbstractToken> tokens = new List<AbstractToken>();

                bool keepProcessing = true;
                int balance = 1;

                while (keepProcessing)
                {
                    Type nextTokenType = tokenizer.Peek().GetType();

                    if (nextTokenType == typeof (OpeningBrace))
                    {
                        balance++;
                    }

                    if ( (startToken.GetType() == typeof(OpeningBrace) &&  nextTokenType == typeof (ClosingBrace)))
                    {
                        if (balance == 1)
                        {
                            keepProcessing = false;
                            ValueStop(tokenizer);
                        }
                    }

                    if (nextTokenType == typeof(ClosingBrace))
                    {
                        if (balance > 1)
                        {
                            balance--;
                        }
                    }

                    // Double quotes are much more difficult to handle then the braces. The problem is that there is no distinction between
                    // start and stop quotes. This means we need to look forward to see what is behind the quote to see if it is a quote @ the end
                    // or the start of a new quote.
                    if (nextTokenType == typeof (ValueQuote))
                    {
                        AbstractToken quote = tokenizer.NextToken();

                        Type nextType = tokenizer.Peek().GetType();
                        if ((nextType == typeof(ClosingBrace) && balance == 1) ||
                             nextType == typeof(Comma))
                        {
                            // end of line found.
                            keepProcessing = false;
                        }
                        else
                        {
                            tokens.Add(quote);
                            continue;
                        }
                    }

                    if (keepProcessing)
                    {
                        tokens.Add(tokenizer.NextToken());
                    }
                }

                tag.Value = tokens.Aggregate("", (s, token) => s + token.RawValue);

                Comma(tokenizer, true);
                NewLine(tokenizer, true);

                tags.Add(tag);
            }

            return tags;
        }
开发者ID:MaikelH,项目名称:BibtexLibrary,代码行数:85,代码来源:BibtexParser.cs

示例12: ParseLayoutRenderer

        private static LayoutRenderer ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, Tokenizer sr)
        {
            int ch = sr.Read();
            Debug.Assert(ch == '{', "'{' expected in layout specification");

            string name = ParseLayoutRendererName(sr);
            LayoutRenderer lr = configurationItemFactory.LayoutRenderers.CreateInstance(name);

            var wrappers = new Dictionary<Type, LayoutRenderer>();
            var orderedWrappers = new List<LayoutRenderer>();

            ch = sr.Read();
            while (ch != -1 && ch != '}')
            {
                string parameterName = ParseParameterName(sr).Trim();
                if (sr.Peek() == '=')
                {
                    sr.Read(); // skip the '='
                    PropertyInfo pi;
                    LayoutRenderer parameterTarget = lr;

                    if (!PropertyHelper.TryGetPropertyInfo(lr, parameterName, out pi))
                    {
                        Type wrapperType;

                        if (configurationItemFactory.AmbientProperties.TryGetDefinition(parameterName, out wrapperType))
                        {
                            LayoutRenderer wrapperRenderer;

                            if (!wrappers.TryGetValue(wrapperType, out wrapperRenderer))
                            {
                                wrapperRenderer = configurationItemFactory.AmbientProperties.CreateInstance(parameterName);
                                wrappers[wrapperType] = wrapperRenderer;
                                orderedWrappers.Add(wrapperRenderer);
                            }

                            if (!PropertyHelper.TryGetPropertyInfo(wrapperRenderer, parameterName, out pi))
                            {
                                pi = null;
                            }
                            else
                            {
                                parameterTarget = wrapperRenderer;
                            }
                        }
                    }

                    if (pi == null)
                    {
                        ParseParameterValue(sr);
                    }
                    else
                    {
                        if (typeof(Layout).IsAssignableFrom(pi.PropertyType))
                        {
                            var nestedLayout = new SimpleLayout();
                            string txt;
                            LayoutRenderer[] renderers = CompileLayout(configurationItemFactory, sr, true, out txt);

                            nestedLayout.SetRenderers(renderers, txt);
                            pi.SetValue(parameterTarget, nestedLayout, null);
                        }
                        else
                        {
                            string value = ParseParameterValue(sr);
                            PropertyHelper.SetPropertyFromString(parameterTarget, parameterName, value);
                        }
                    }
                }
                else
                {
                    // what we've just read is not a parameterName, but a value
                    // assign it to a default property (denoted by empty string)
                    PropertyInfo pi;

                    if (PropertyHelper.TryGetPropertyInfo(lr, string.Empty, out pi))
                    {
                        if (typeof(SimpleLayout) == pi.PropertyType)
                        {
                            pi.SetValue(lr, new SimpleLayout(parameterName), null);
                        }
                        else
                        {
                            string value = parameterName;
                            PropertyHelper.SetPropertyFromString(lr, pi.Name, value);
                        }
                    }
                    else
                    {
                        InternalLogger.Warn("{0} has no default property", lr.GetType().FullName);
                    }
                }

                ch = sr.Read();
            }

            lr = ApplyWrappers(configurationItemFactory, lr, orderedWrappers);

            return lr;
        }
开发者ID:ChadBurggraf,项目名称:NLog,代码行数:100,代码来源:LayoutParser.cs


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