Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisValueIntermediateResultWithFunction"/> class.
 /// </summary>
 /// <param name="function">Function</param>
 /// <param name="argument">Argument</param>
 /// <param name="rowContext">Row context</param>
 /// <param name="valueContext">Value context</param>
 public AnalysisValueIntermediateResultWithFunction(AnalysisFunctionFunc function, AnalysisValueIntermediateResult argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
     : base(null, new System.Collections.Generic.List <object> {
     argument
 }, rowContext, valueContext)
 {
     this.Func = function;
 }
Beispiel #2
0
        private AnalysisFunctionFormulaParseResult ParseVariable(AnalysisParserString parserString)
        {
            if (!parserString.CurrentString.StartsWith("$"))
            {
                return(new AnalysisFunctionFormulaParseResult("invalid function token"));
            }

            parserString.SkipChar();
            bool isTextFunction = false;

            if (parserString.NextCharacter() == '!')
            {
                isTextFunction = true;
                parserString.SkipChar();
            }

            string functionName = parserString.NextWord();

            parserString.SkipBlanks();
            if (!isTextFunction)
            {
                AnalysisFunction func = AnalysisFunction.FunctionWithName(functionName);
                if (func != null)
                {
                    if (parserString.NextCharacter() == '(')
                    {
                        parserString.SkipCharWithBlanks();
                        AnalysisFunctionFormulaParseResult parseResult = this.Parse(parserString);
                        if (parseResult.Result != null)
                        {
                            AnalysisFunctionFunc f = new AnalysisFunctionFunc(func, parseResult.Result, this.Analysis);
                            if (parserString.NextCharacter() == ')')
                            {
                                parserString.SkipCharWithBlanks();
                                return(new AnalysisFunctionFormulaParseResult(f));
                            }
                            else
                            {
                                return(new AnalysisFunctionFormulaParseResult("invalid function end"));
                            }
                        }
                    }
                }
            }

            string indexPart0 = parserString.IndexString();
            string indexPart1 = null;

            if (indexPart0 != null)
            {
                indexPart1 = parserString.IndexString();
            }

            int occurrence = 0;

            if (indexPart1?.Length > 0)
            {
                occurrence = indexPart0.ToInt();
                indexPart0 = indexPart1;
            }

            bool record      = false;
            int  fieldNumber = -1;

            if (indexPart0 != null)
            {
                if (indexPart0 == "r")
                {
                    record = true;
                }

                fieldNumber = indexPart0.ToInt();
            }
            else
            {
                record = true;
            }

            AnalysisTable table = this.Analysis.TableWithInfoAreaIdOccurrence(functionName, occurrence);

            if (table == null)
            {
                return(new AnalysisFunctionFormulaParseResult($"unknown table {functionName}/{occurrence}"));
            }

            if (record)
            {
                AnalysisFunctionInfoAreaField f = new AnalysisFunctionInfoAreaField(table.CountField(), this.Analysis);
                return(new AnalysisFunctionFormulaParseResult(f));
            }

            AnalysisSourceField sourceField = table.FieldWithIndex(fieldNumber);

            if (sourceField == null)
            {
                return(new AnalysisFunctionFormulaParseResult($"unknown field {functionName}/{occurrence}.{fieldNumber}"));
            }

            AnalysisFunctionSimpleField functionField;

            if (isTextFunction)
            {
                functionField = new AnalysisFunctionSimpleTextField(sourceField, this.Analysis);
            }
            else
            {
                functionField = new AnalysisFunctionSimpleNumberField(sourceField, this.Analysis);
            }

            return(new AnalysisFunctionFormulaParseResult(functionField));
        }