private void AssertNoRestrictedMetaIdentifierUsed() { const string meta = "__meta__"; if (FieldsMap.Keys.Select(x => x.Split('.').First()).Contains(meta) || EnumsMap.Keys.Select(x => x.Split('.').First()).Contains(meta) || ConstsMap.Keys.Select(x => x.Split('.').First()).Contains(meta) || MethodsList.Contains(meta)) { throw new InvalidOperationException( $"{meta} identifier is restricted for internal client-side purposes, please use different name."); } }
private List <StiToken> PostProcessTokensList(List <StiToken> tokensList) { List <StiToken> newList = new List <StiToken>(); tokenPos = 0; while (tokenPos < tokensList.Count) { StiToken token = tokensList[tokenPos]; tokenPos++; if (token.Type == StiTokenType.Identifier) { StiDataSource ds = report.Dictionary.DataSources[token.Value]; StiBusinessObject bos = report.Dictionary.BusinessObjects[token.Value]; #region check for DataSource field if (ds != null) { StringBuilder fieldPath = new StringBuilder(StiNameValidator.CorrectName(token.Value)); while (tokenPos + 1 < tokensList.Count && tokensList[tokenPos].Type == StiTokenType.Dot) { token = tokensList[tokenPos + 1]; string nextName = StiNameValidator.CorrectName(token.Value); StiDataRelation dr = GetDataRelationByName(nextName, ds); if (dr != null) { ds = dr.ParentSource; tokenPos += 2; fieldPath.Append("."); fieldPath.Append(dr.NameInSource); continue; } if (ds.Columns.Contains(nextName)) { tokenPos += 2; fieldPath.Append("."); fieldPath.Append(nextName); break; } foreach (StiDataColumn column in ds.Columns) { if (StiNameValidator.CorrectName(column.Name) == nextName) { tokenPos += 2; fieldPath.Append("."); fieldPath.Append(column.NameInSource); break; } } CheckDataSourceField(ds.Name, nextName); tokenPos += 2; fieldPath.Append("."); fieldPath.Append(nextName); //token = tokensList[tokenPos - 1]; break; } token.Type = StiTokenType.DataSourceField; //надо оптимизировать и сохранять сразу массив строк !!!!! token.Value = fieldPath.ToString(); } #endregion #region check for BusinessObject field else if (bos != null) { StringBuilder fieldPath = new StringBuilder(token.Value); while (tokenPos + 1 < tokensList.Count && tokensList[tokenPos].Type == StiTokenType.Dot) //while (inputExpression[pos2] == '.') { token = tokensList[tokenPos + 1]; string nextName = token.Value; if (bos.Columns.Contains(nextName)) { tokenPos += 2; fieldPath.Append("."); fieldPath.Append(nextName); break; } bos = bos.BusinessObjects[nextName]; if (bos != null) { tokenPos += 2; fieldPath.Append("."); fieldPath.Append(bos.Name); continue; } break; } token.Type = StiTokenType.BusinessObjectField; //надо оптимизировать и сохранять сразу массив строк !!!!! token.Value = fieldPath.ToString(); } #endregion else if ((newList.Count > 0) && (newList[newList.Count - 1].Type == StiTokenType.Dot)) { if (MethodsList.Contains(token.Value)) { token.Type = StiTokenType.Method; } else if (PropertiesList.Contains(token.Value)) { token.Type = StiTokenType.Property; } else { ThrowError(ParserErrorCode.FieldMethodOrPropertyNotFound, token, token.Value); } } else if (TypesList.Contains(token.Value)) { token.Type = StiTokenType.Cast; if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot)) { string tempName = token.Value + "." + tokensList[tokenPos + 1].Value; if (FunctionsList.Contains(tempName)) { token.Type = StiTokenType.Function; token.Value = tempName; tokenPos += 2; } if (SystemVariablesList.Contains(tempName)) { token.Type = StiTokenType.SystemVariable; token.Value = tempName; tokenPos += 2; } } } else if (ComponentsList.Contains(token.Value)) { token.Type = StiTokenType.Component; if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Colon) && ComponentsList.Contains(tokensList[tokenPos + 1].Value)) { StiComponent comp = (StiComponent)ComponentsList[tokensList[tokenPos + 1].Value]; if (comp != null && comp is StiDataBand) { token.Value = (comp as StiDataBand).DataSourceName; token.Type = StiTokenType.DataSourceField; tokenPos += 2; } } } else if (FunctionsList.Contains(token.Value)) { while ((StiFunctionType)FunctionsList[token.Value] == StiFunctionType.NameSpace) { if (tokenPos + 1 >= tokensList.Count) { ThrowError(ParserErrorCode.UnexpectedEndOfExpression); } token.Value += "." + tokensList[tokenPos + 1].Value; tokenPos += 2; if (!FunctionsList.Contains(token.Value)) { ThrowError(ParserErrorCode.FunctionNotFound, token, token.Value); } } token.Type = StiTokenType.Function; } else if (SystemVariablesList.Contains(token.Value) && (token.Value != "value" || component is Stimulsoft.Report.CrossTab.StiCrossCell)) { token.Type = StiTokenType.SystemVariable; } //else if (token.Value.ToLowerInvariant() == "true" || token.Value.ToLowerInvariant() == "false") //{ // if (token.Value.ToLowerInvariant() == "true") // token.ValueObject = true; // else // token.ValueObject = false; // token.Type = StiTokenType.Number; //} //else if (token.Value.ToLowerInvariant() == "null") //{ // token.ValueObject = null; // token.Type = StiTokenType.Number; //} else if (ConstantsList.Contains(token.Value)) { while (ConstantsList[token.Value] == namespaceObj) { if (tokenPos + 1 >= tokensList.Count) { ThrowError(ParserErrorCode.UnexpectedEndOfExpression); } string oldTokenValue = token.Value; token.Value += "." + tokensList[tokenPos + 1].Value; tokenPos += 2; if (!ConstantsList.Contains(token.Value)) { ThrowError(ParserErrorCode.ItemDoesNotContainDefinition, token, oldTokenValue, tokensList[tokenPos + 1].Value); } } token.ValueObject = ConstantsList[token.Value]; token.Type = StiTokenType.Number; } else if (report.Dictionary.Variables.Contains(token.Value)) { token.Type = StiTokenType.Variable; } else if (token.Value == "or" || token.Value == "and" || token.Value == "not") { if (token.Value == "or") { token.Type = StiTokenType.DoubleOr; } if (token.Value == "and") { token.Type = StiTokenType.DoubleAnd; } if (token.Value == "not") { token.Type = StiTokenType.Not; } } else { if ((tokenPos < tokensList.Count) && (tokensList[tokenPos].Type != StiTokenType.Dot) || (tokenPos == tokensList.Count)) { CheckDataSourceField(defaultDataSourceName, token.Value); token.Type = StiTokenType.DataSourceField; token.Value = defaultDataSourceName + "." + token.Value; } else { if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot)) { CheckDataSourceField(token.Value, tokensList[tokenPos + 1].Value); token.Type = StiTokenType.DataSourceField; token.Value = token.Value + "." + tokensList[tokenPos + 1].Value; tokenPos += 2; } else { ThrowError(ParserErrorCode.NameDoesNotExistInCurrentContext, token, token.Value); } } } } newList.Add(token); } return(newList); }
private List <StiToken> PostProcessTokensList(List <StiToken> tokensList) { List <StiToken> newList = new List <StiToken>(); tokenPos = 0; while (tokenPos < tokensList.Count) { StiToken token = tokensList[tokenPos]; tokenPos++; if (token.Type == StiTokenType.Identifier) { if ((newList.Count > 0) && (newList[newList.Count - 1].Type == StiTokenType.Dot)) { if (MethodsList.Contains(token.Value)) { token.Type = StiTokenType.Method; } //Proryv else if (Equals(token.Value, "Value") || ProryvPropertiesList.Contains(token.Value) || PropertiesList.Contains(token.Value)) { token.Type = StiTokenType.Property; } else { ThrowError(ParserErrorCode.FieldMethodOrPropertyNotFound, token, token.Value); } } else if (TypesList.Contains(token.Value)) { token.Type = StiTokenType.Cast; if ((tokenPos + 1 < tokensList.Count) && (tokensList[tokenPos].Type == StiTokenType.Dot)) { string tempName = token.Value + "." + tokensList[tokenPos + 1].Value; if (FunctionsList.Contains(tempName)) { token.Type = StiTokenType.Function; token.Value = tempName; tokenPos += 2; } //Proryv else if (ProryvFunctionsList.Contains(tempName)) { token.Type = StiTokenType.ProryvFunction; token.Value = tempName; tokenPos += 2; } if (SystemVariablesList.Contains(tempName)) { token.Type = StiTokenType.SystemVariable; token.Value = tempName; tokenPos += 2; } } } //Proryv else if (ProryvFunctionsList.Contains(token.Value)) { token.Type = StiTokenType.ProryvFunction; } else if (_proryvSpreadsheetProperties != null && _proryvSpreadsheetProperties.ContainsKey(token.Value.ToLowerInvariant())) { token.Type = StiTokenType.ProryvSpreadsheetProperties; } else if (_proryvFreeHierarchyBalanceSignature != null && _proryvFreeHierarchyBalanceSignature.ContainsKey(token.Value.ToLowerInvariant())) { token.Type = StiTokenType.ProryvFreeHierarchyBalanceSignature; } else if (FunctionsList.Contains(token.Value)) { while ((ProryvFunctionType)FunctionsList[token.Value] == ProryvFunctionType.NameSpace) { if (tokenPos + 1 >= tokensList.Count) { ThrowError(ParserErrorCode.UnexpectedEndOfExpression); } var np = tokensList[tokenPos + 1].Value; token.Value += "." + np; tokenPos += 2; if (!FunctionsList.Contains(token.Value)) { if (FunctionsList.Contains(np)) { token.Value = np; } else { ThrowError(ParserErrorCode.FunctionNotFound, token, token.Value); } } } token.Type = StiTokenType.Function; } else if (SystemVariablesList.Contains(token.Value) && (token.Value != "value")) { token.Type = StiTokenType.SystemVariable; } //else if (token.Value.ToLowerInvariant() == "true" || token.Value.ToLowerInvariant() == "false") //{ // if (token.Value.ToLowerInvariant() == "true") // token.ValueObject = true; // else // token.ValueObject = false; // token.Type = StiTokenType.Number; //} //else if (token.Value.ToLowerInvariant() == "null") //{ // token.ValueObject = null; // token.Type = StiTokenType.Number; //} else if (ConstantsList.Contains(token.Value)) { while (ConstantsList[token.Value] == namespaceObj) { if (tokenPos + 1 >= tokensList.Count) { ThrowError(ParserErrorCode.UnexpectedEndOfExpression); } string oldTokenValue = token.Value; token.Value += "." + tokensList[tokenPos + 1].Value; tokenPos += 2; if (!ConstantsList.Contains(token.Value)) { ThrowError(ParserErrorCode.ItemDoesNotContainDefinition, token, oldTokenValue, tokensList[tokenPos + 1].Value); } } token.ValueObject = ConstantsList[token.Value]; token.Type = StiTokenType.Number; } else if (UserFunctionsList.Contains(token.Value)) { token.Type = StiTokenType.Function; } else { ThrowError(ParserErrorCode.NameDoesNotExistInCurrentContext, token, token.Value); } } newList.Add(token); } return(newList); }