public override void SetParams()

in src/Lucene.Net.Benchmark/ByTask/Tasks/AnalyzerFactoryTask.cs [108:369]


        public override void SetParams(string @params)
        {
            base.SetParams(@params);
            ArgType expectedArgType = ArgType.ANALYZER_ARG;

            StreamTokenizer stok = new StreamTokenizer(new StringReader(@params));
            stok.CommentChar('#');
            stok.QuoteChar('"');
            stok.QuoteChar('\'');
            stok.EndOfLineIsSignificant = false;
            stok.OrdinaryChar('(');
            stok.OrdinaryChar(')');
            stok.OrdinaryChar(':');
            stok.OrdinaryChar(',');
            try
            {
                while (stok.NextToken() != StreamTokenizer.TokenType_EndOfStream)
                {
                    switch (stok.TokenType)
                    {
                        case ',':
                            {
                                // Do nothing
                                break;
                            }
                        case StreamTokenizer.TokenType_Word:
                            {
                                if (expectedArgType.Equals(ArgType.ANALYZER_ARG))
                                {
                                    string argName = stok.StringValue;
                                    if (!argName.Equals("name", StringComparison.OrdinalIgnoreCase)
                                        && !argName.Equals("positionIncrementGap", StringComparison.OrdinalIgnoreCase)
                                        && !argName.Equals("offsetGap", StringComparison.OrdinalIgnoreCase))
                                    {
                                        throw RuntimeException.Create
                                            ("Line #" + GetLineNumber(stok) + ": Missing 'name' param to AnalyzerFactory: '" + @params + "'");
                                    }
                                    stok.NextToken();
                                    if (stok.TokenType != ':')
                                    {
                                        throw RuntimeException.Create
                                            ("Line #" + GetLineNumber(stok) + ": Missing ':' after '" + argName + "' param to AnalyzerFactory");
                                    }

                                    stok.NextToken();
                                    string argValue = stok.StringValue;
                                    switch (stok.TokenType)
                                    {
                                        case StreamTokenizer.TokenType_Number:
                                            {
                                                argValue = stok.NumberValue.ToString(CultureInfo.InvariantCulture);
                                                // Drop the ".0" from numbers, for integer arguments
                                                argValue = TRAILING_DOT_ZERO_PATTERN.Replace(argValue, "", 1);
                                                // Intentional fallthrough

                                                if (argName.Equals("name", StringComparison.OrdinalIgnoreCase))
                                                {
                                                    factoryName = argValue;
                                                    expectedArgType = ArgType.ANALYZER_ARG_OR_CHARFILTER_OR_TOKENIZER;
                                                }
                                                else
                                                {
                                                    int intArgValue = 0;
                                                    try
                                                    {
                                                        intArgValue = int.Parse(argValue, CultureInfo.InvariantCulture);
                                                    }
                                                    catch (Exception e) when (e.IsNumberFormatException())
                                                    {
                                                        throw RuntimeException.Create
                                                            ("Line #" + GetLineNumber(stok) + ": Exception parsing " + argName + " value '" + argValue + "'", e);
                                                    }
                                                    if (argName.Equals("positionIncrementGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        positionIncrementGap = intArgValue;
                                                    }
                                                    else if (argName.Equals("offsetGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        offsetGap = intArgValue;
                                                    }
                                                }
                                                break;
                                            }
                                        case '"':
                                        case '\'':
                                        case StreamTokenizer.TokenType_Word:
                                            {
                                                if (argName.Equals("name", StringComparison.OrdinalIgnoreCase))
                                                {
                                                    factoryName = argValue;
                                                    expectedArgType = ArgType.ANALYZER_ARG_OR_CHARFILTER_OR_TOKENIZER;
                                                }
                                                else
                                                {
                                                    int intArgValue = 0;
                                                    try
                                                    {
                                                        intArgValue = int.Parse(argValue, CultureInfo.InvariantCulture);
                                                    }
                                                    catch (Exception e) when (e.IsNumberFormatException())
                                                    {
                                                        throw RuntimeException.Create
                                                            ("Line #" + GetLineNumber(stok) + ": Exception parsing " + argName + " value '" + argValue + "'", e);
                                                    }
                                                    if (argName.Equals("positionIncrementGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        positionIncrementGap = intArgValue;
                                                    }
                                                    else if (argName.Equals("offsetGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        offsetGap = intArgValue;
                                                    }
                                                }
                                                break;
                                            }
                                        case StreamTokenizer.TokenType_EndOfStream:
                                            {
                                                throw RuntimeException.Create("Unexpected EOF: " + stok.ToString());
                                            }
                                        default:
                                            {
                                                throw RuntimeException.Create
                                                    ("Line #" + GetLineNumber(stok) + ": Unexpected token: " + stok.ToString());
                                            }
                                    }
                                }
                                else if (expectedArgType.Equals(ArgType.ANALYZER_ARG_OR_CHARFILTER_OR_TOKENIZER))
                                {
                                    string argName = stok.StringValue;

                                    if (argName.Equals("positionIncrementGap", StringComparison.OrdinalIgnoreCase)
                                        || argName.Equals("offsetGap", StringComparison.OrdinalIgnoreCase))
                                    {
                                        stok.NextToken();
                                        if (stok.TokenType != ':')
                                        {
                                            throw RuntimeException.Create
                                                ("Line #" + GetLineNumber(stok) + ": Missing ':' after '" + argName + "' param to AnalyzerFactory");
                                        }
                                        stok.NextToken();
                                        int intArgValue = (int)stok.NumberValue;
                                        switch (stok.TokenType)
                                        {
                                            case '"':
                                            case '\'':
                                            case StreamTokenizer.TokenType_Word:
                                                {
                                                    intArgValue = 0;
                                                    try
                                                    {
                                                        intArgValue = int.Parse(stok.StringValue.Trim(), CultureInfo.InvariantCulture);
                                                    }
                                                    catch (Exception e) when (e.IsNumberFormatException())
                                                    {
                                                        throw RuntimeException.Create
                                                            ("Line #" + GetLineNumber(stok) + ": Exception parsing " + argName + " value '" + stok.StringValue + "'", e);
                                                    }
                                                    // Intentional fall-through

                                                    if (argName.Equals("positionIncrementGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        positionIncrementGap = intArgValue;
                                                    }
                                                    else if (argName.Equals("offsetGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        offsetGap = intArgValue;
                                                    }
                                                    break;
                                                }
                                            case StreamTokenizer.TokenType_Number:
                                                {
                                                    if (argName.Equals("positionIncrementGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        positionIncrementGap = intArgValue;
                                                    }
                                                    else if (argName.Equals("offsetGap", StringComparison.OrdinalIgnoreCase))
                                                    {
                                                        offsetGap = intArgValue;
                                                    }
                                                    break;
                                                }
                                            case StreamTokenizer.TokenType_EndOfStream:
                                                {
                                                    throw RuntimeException.Create("Unexpected EOF: " + stok.ToString());
                                                }
                                            default:
                                                {
                                                    throw RuntimeException.Create
                                                        ("Line #" + GetLineNumber(stok) + ": Unexpected token: " + stok.ToString());
                                                }
                                        }
                                        break;
                                    }
                                    try
                                    {
                                        Type clazz;
                                        clazz = LookupAnalysisClass(argName, typeof(CharFilterFactory));
                                        CreateAnalysisPipelineComponent(stok, clazz);
                                    }
                                    catch (Exception e) when (e.IsIllegalArgumentException())
                                    {
                                        try
                                        {
                                            Type clazz;
                                            clazz = LookupAnalysisClass(argName, typeof(TokenizerFactory));
                                            CreateAnalysisPipelineComponent(stok, clazz);
                                            expectedArgType = ArgType.TOKENFILTER;
                                        }
                                        catch (Exception e2) when (e2.IsIllegalArgumentException())
                                        {
                                            throw RuntimeException.Create("Line #" + GetLineNumber(stok) + ": Can't find class '"
                                                                       + argName + "' as CharFilterFactory or TokenizerFactory", e2);
                                        }
                                    }
                                }
                                else
                                { // expectedArgType = ArgType.TOKENFILTER
                                    string className = stok.StringValue;
                                    Type clazz;
                                    try
                                    {
                                        clazz = LookupAnalysisClass(className, typeof(TokenFilterFactory));
                                    }
                                    catch (Exception e) when (e.IsIllegalArgumentException())
                                    {
                                        throw RuntimeException.Create
                                            ("Line #" + GetLineNumber(stok) + ": Can't find class '" + className + "' as TokenFilterFactory", e);
                                    }
                                    CreateAnalysisPipelineComponent(stok, clazz);
                                }
                                break;
                            }
                        default:
                            {
                                throw RuntimeException.Create("Line #" + GetLineNumber(stok) + ": Unexpected token: " + stok.ToString());
                            }
                    }
                }
            }
            catch (Exception e) when (e.IsRuntimeException())
            {
                if (e.Message.StartsWith("Line #", StringComparison.Ordinal))
                {
                    throw; // LUCENENET: CA2200: Rethrow to preserve stack details (https://docs.microsoft.com/en-us/visualstudio/code-quality/ca2200-rethrow-to-preserve-stack-details)
                }
                else
                {
                    throw RuntimeException.Create("Line #" + GetLineNumber(stok) + ": ", e);
                }
            }
            catch (Exception t) when (t.IsThrowable())
            {
                throw RuntimeException.Create("Line #" + GetLineNumber(stok) + ": ", t);
            }

            AnalyzerFactory analyzerFactory = new AnalyzerFactory(charFilterFactories, tokenizerFactory, tokenFilterFactories)
            {
                PositionIncrementGap = positionIncrementGap,
                OffsetGap = offsetGap
            };
            RunData.AnalyzerFactories[factoryName] = analyzerFactory;
        }