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


C# Scanner.GetNext方法代码示例

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


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

示例1: GetBatches

        /// <summary>
        /// Generates Transact-SQL batches, suitable for execution, from the text of a 
        /// Transact-SQL script.
        /// </summary>
        /// <param name="scriptSql">Transact-SQL script text</param>
        /// <returns>Collection of Batch objects for each batch in the supplied script</returns>
        public static IEnumerable<Batch> GetBatches(string scriptSql)
        {
            /* This method could be rewritten to use the new `Parser.ParseSql` class method. */

            ParseOptions parseOptions = new ParseOptions();
            Scanner scanner = new Scanner(parseOptions);

            int state = 0,
                start,
                end,
                lastTokenEnd = -1,
                token;

            bool isPairMatch, isExecAutoParamHelp;

            List<Batch> batches = new List<Batch>();
            StringBuilder nextBatchSql = new StringBuilder();

            scanner.SetSource(scriptSql, 0);

            while ((token = scanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != (int)Tokens.EOF)
            {
                if ((Tokens)token == Tokens.LEX_BATCH_SEPERATOR)
                {
                    nextBatchSql.Append(scriptSql.Substring(lastTokenEnd + 1, start - lastTokenEnd + 1 - 1 - 1));
                    batches.Add(new Batch(nextBatchSql.ToString()));
            #if NET35
                    nextBatchSql = new StringBuilder();
            #else
                    nextBatchSql.Clear();
            #endif
                }
                else
                {
                    nextBatchSql.Append(scriptSql.Substring(lastTokenEnd + 1, end - lastTokenEnd + 1 - 1));
                }

                lastTokenEnd = end;
            }

            #if NET35
            if (!String.IsNullOrEmpty(nextBatchSql.ToString().Trim()))
            #else
            if (!String.IsNullOrWhiteSpace(nextBatchSql.ToString()))
            #endif
                batches.Add(new Batch(nextBatchSql.ToString()));

            return batches;
        }
开发者ID:kenny-evitt,项目名称:Transact-SQL-Helpers,代码行数:55,代码来源:Scripts.cs

示例2: ParseSql

        public static IEnumerable<TokenInfo> ParseSql(string sql)
        {
            ParseOptions parseOptions = new ParseOptions();
            Scanner scanner = new Scanner(parseOptions);

            int state = 0,
                start,
                end,
                lastTokenEnd = -1,
                token;

            bool isPairMatch, isExecAutoParamHelp;

            List<TokenInfo> tokens = new List<TokenInfo>();
            StringBuilder nextBatchSql = new StringBuilder();

            scanner.SetSource(sql, 0);

            while ((token = scanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != (int)Tokens.EOF)
            {
                TokenInfo tokenInfo =
                    new TokenInfo()
                    {
                        Start = start,
                        End = end,
                        IsPairMatch = isPairMatch,
                        IsExecAutoParamHelp = isExecAutoParamHelp,
                        Sql = sql.Substring(start, end - start + 1),
                        Token = (Tokens)token,
                    };

                tokens.Add(tokenInfo);

                lastTokenEnd = end;
            }

            return tokens;
        }
开发者ID:kenny-evitt,项目名称:Transact-SQL-Helpers,代码行数:38,代码来源:Parser.cs

示例3: ParseItems

 private void ParseItems()
 {
     Scanner scanner = new Scanner();
     scanner.SetSource(source, 0);
     int state=0,start,end;
     int tokenType = -1;
     while (tokenType != ((int)Tokens.EOF)) {
         tokenType = scanner.GetNext(ref state, out start, out end);
         if (tokenType == (int)Tokens.LCASEIDENT || tokenType == (int)Tokens.OUTACTION) {
             string channel = scanner.yytext.Replace("_", "");
             if (!channels.Contains(channel)) {
                 channels.Add(channel);
             }
         } else if (tokenType == (int)Tokens.PROC) {
             if (!processes.Contains(scanner.yytext)) {
                 processes.Add(scanner.yytext);
             }
         } else if (tokenType == (int)Tokens.FULLCLASS) {
             if (!importedClasses.Contains(scanner.yytext)) {
                 importedClasses.Add(scanner.yytext);
             }
         }
     }
 }
开发者ID:einaregilsson,项目名称:Process-Language-Runtime,代码行数:24,代码来源:Resolver.cs

示例4: ValidateBreakpointLocation

        public override int ValidateBreakpointLocation(IVsTextBuffer buffer, int line, int col, TextSpan[] pCodeSpan)
        {
            if (pCodeSpan != null) {
                pCodeSpan[0].iStartLine = line;
                pCodeSpan[0].iEndLine = line;
                List<TokenInfo> tokens = new List<TokenInfo>();
                if (buffer != null) {
                    int length;
                    buffer.GetLengthOfLine(line, out length);
                    IVsTextLines lines = (IVsTextLines)buffer;
                    string text;
                    lines.GetLineText(line, 0, line, length, out text);

                    Scanner scanner = new Scanner();
                    scanner.SetSource(text, 0);
                    int state = 0, start, end;
                    int tokenType = -1;
                    while (tokenType != ((int)Tokens.EOF)) {
                        tokenType = scanner.GetNext(ref state, out start, out end);
                        tokens.Add(new TokenInfo(start, end, tokenType, scanner.yytext));
                    }

                    for (int i = 0; i < tokens.Count; i++) {
                        TokenInfo t = tokens[i];
                        if (t.type == (int)Tokens.OUTACTION
                            || t.type == (int)Tokens.METHOD
                            || t.type == (int)Tokens.LCASEIDENT
                            || (t.type == (int)Tokens.NUMBER && t.text == "0")) {
                            pCodeSpan[0].iStartIndex = t.start;
                            pCodeSpan[0].iEndIndex = t.end + 1;
                            return Microsoft.VisualStudio.VSConstants.S_OK;
                        } else if (t.type == (int)Tokens.PROC) {
                            //Just a heuristic, if there is a '=' somewhere after this, then we don't want it
                            //Most likely it is Foo = proc or Foo(x,y,z) = proc and we don't want to highlight that
                            bool canUseProc = true;
                            for (int j = i + 1; j < tokens.Count; j++) {
                                if (tokens[j].type == (int)'=') {
                                    i = j;
                                    canUseProc = false;
                                    break;
                                }
                            }
                            if (canUseProc) {
                                pCodeSpan[0].iStartIndex = t.start;
                                pCodeSpan[0].iEndIndex = t.end + 1;
                                return Microsoft.VisualStudio.VSConstants.S_OK;
                            }
                        }

                    }
                }
            }
            return Microsoft.VisualStudio.VSConstants.S_FALSE;
        }
开发者ID:einaregilsson,项目名称:Process-Language-Runtime,代码行数:54,代码来源:CCSLanguage.cs

示例5: ReplaceNonBreakingSpaces

        public static string ReplaceNonBreakingSpaces(string scriptSql)
        {
            /* This method could be rewritten to use the new `Parser.ParseSql` class method. */

            ParseOptions parseOptions = new ParseOptions();
            Scanner scanner = new Scanner(parseOptions);

            int state = 0,
                start,
                end,
                lastTokenEnd = -1,
                token;

            bool isPairMatch, isExecAutoParamHelp;

            StringBuilder newScriptSql = new StringBuilder();

            scanner.SetSource(scriptSql, 0);

            while ((token = scanner.GetNext(ref state, out start, out end, out isPairMatch, out isExecAutoParamHelp)) != (int)Tokens.EOF)
            {
                newScriptSql.Append(scriptSql.Substring(lastTokenEnd + 1, start - lastTokenEnd - 1));

                string tokenSubstring = scriptSql.Substring(start, end - start + 1);

                if ((Tokens)token != Tokens.TOKEN_STRING)
                {
                    newScriptSql.Append(tokenSubstring.Replace('\xA0', '\x20'));
                }
                else
                {
                    newScriptSql.Append(tokenSubstring);
                }

                lastTokenEnd = end;
            }

            if (lastTokenEnd + 1 < scriptSql.Length)
                newScriptSql.Append(scriptSql.Substring(lastTokenEnd + 1));

            return newScriptSql.ToString();
        }
开发者ID:kenny-evitt,项目名称:Transact-SQL-Helpers,代码行数:42,代码来源:Scripts.cs


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