/// <summary> /// Ensures that pair value is either Alias or Parameter. /// Validates string concatenation. /// </summary> /// <param name="pair"></param> private void CheckPairValue(Pair pair) { if (pair.Delimiter == DelimiterEnum.CE) { if (pair.PairValue == null || !(pair.PairValue is DOM.Alias) && !(pair.PairValue is DOM.Parameter)) { var mappedPair = pair.PairValue as IMappedPair; Context.AddError(mappedPair != null ? CompilerErrorFactory.AliasOrParameterExpected(mappedPair.NameInterval, _currentModule.FileName) : CompilerErrorFactory.AliasOrParameterExpected(((IMappedPair)pair).NameInterval, _currentModule.FileName)); } else { Visit(pair.PairValue); } } else if (pair.Delimiter == DelimiterEnum.EC) { CheckStringConcatenation(pair); } if (pair.PairValue is DOM.Parameter) { var aliasContext = AliasContext.Peek(); if (aliasContext != null) { ValidateParameter((Parameter)pair.PairValue, aliasContext.Alias, _currentModule.FileName); } } else if (pair.PairValue is DOM.Alias) { Alias alias = (Alias)pair.PairValue; CheckAliasIsDefined(alias); var aliasDef = alias.AliasDefinition; //Do not resolve alias without AliasDef or having circular reference if (aliasDef == null || aliasDef.HasCircularReference) { return; } AliasContext.Push(new AliasContext() { AliasDefinition = aliasDef, Alias = alias, AliasNsInfo = GetContextNsInfo() }); CheckForUnexpectedArguments(alias, aliasDef, _currentModule.FileName); CheckInterpolation(aliasDef); CheckPairValue(aliasDef); if (CheckStartOfChoiceContainer(alias, aliasDef.Entities, aliasDef)) { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); EndChoiceContainer(/*aliasDef, aliasDef.Entities*/); } else { Visit(aliasDef.Entities.Where(e => !(e is DOM.Attribute))); } AliasContext.Pop(); } }
private void CheckInterpolation(IPairWithInterpolation pair) { if (((Pair)pair).ValueQuotesType != 2) { return; } foreach (var item in pair.InterpolationItems) { var alias = item as Alias; if (alias != null) { CheckAliasIsDefined(alias); continue; } var param = item as DOM.Parameter; if (param != null) { var aliasContext = AliasContext.Peek(); if (aliasContext != null) { ValidateParameter((Parameter)param, aliasContext.Alias, _currentModule.FileName); } } } }
public override void Visit(DOM.Parameter parameter) { CheckPairValue(parameter); var aliasContext = AliasContext.Peek(); if (aliasContext != null) { ValidateParameter((Parameter)parameter, aliasContext.Alias, _currentModule.FileName); } base.Visit(parameter); }