/// <summary> /// For the Namespace Prefix of the Node: /// - reports error if it is not defined /// - finds Namespace DOM object in the Module or ModuleMember and adds it to NsINFo of the current ModuleMember /// if the namespace is not added yet /// </summary> /// <param name="pair"></param> internal void ProcessNsPrefix(IMappedPair pair) { var nsPrefix = ((DOM.INsNode)pair).NsPrefix; if (!string.IsNullOrEmpty(nsPrefix) && !nsPrefix.StartsWith("xml", StringComparison.OrdinalIgnoreCase)) { var ns = LookupNamespace(nsPrefix); if (ns == null) { _context.AddError(CompilerErrorFactory.NsPrefixNotDefined(pair.NameInterval, nsPrefix, _currentModule.FileName)); return; } var foundNs = CurrentModuleMemberNsInfo.Namespaces.FirstOrDefault(n => n.Value == ns.Value); if (foundNs == null) { CurrentModuleMemberNsInfo.Namespaces.Add(ns); } else //If namespace is already defined with different prefix then changing prefix on pair if (foundNs.Name != nsPrefix) { ((INsNode)pair).NsPrefix = foundNs.Name; } var attribute = pair as Attribute; if (attribute != null && attribute.Name == "type" && nsPrefix == "xsi") { var typeInfo = attribute.Value?.Split(':'); if (typeInfo?.Length > 1) { nsPrefix = typeInfo[0]; ns = LookupNamespace(nsPrefix); if (ns == null) { _context.AddError(CompilerErrorFactory.NsPrefixNotDefined(pair.ValueInterval, nsPrefix, _currentModule.FileName)); return; } foundNs = CurrentModuleMemberNsInfo.Namespaces.FirstOrDefault(n => n.Value == ns.Value); if (foundNs == null) { CurrentModuleMemberNsInfo.Namespaces.Add(ns); } else if (foundNs.Name != nsPrefix) { attribute.Value = $"{foundNs.Name}:{typeInfo[1]}"; } } } } }
private static CharLocation GetPairEnd(IMappedPair child) { if (child.ValueInterval != null) { return(child.ValueInterval.End); } if (child.AssignmentInterval != null) { return(child.AssignmentInterval.End); } return(child.NameInterval.End); }
protected string ResolveNodeValue(IMappedPair pair, out ValueType valueType) { if (pair.ValueType != ValueType.DoubleQuotedString && pair.ValueType != ValueType.Concatenation) { if (((Pair)pair).PairValue != null) { return(ResolvePairValue(((Pair)pair).PairValue, out valueType)); } valueType = pair.ValueType; return(((Pair)pair).Delimiter != DelimiterEnum.None ? ((Pair)pair).Value : ((Pair)pair).Name); } return(ResolveValueInInterpolation(pair, out valueType)); }
private void SetValueType(IMappedPair pair, DelimiterEnum delimiter, string value, int valueQuotesType) { switch (delimiter) { case DelimiterEnum.CE: pair.ValueType = ValueType.PairValue; return; case DelimiterEnum.EC: pair.ValueType = ValueType.Concatenation; return; case DelimiterEnum.ECC: pair.ValueType = ValueType.LiteralChoice; return; case DelimiterEnum.C: case DelimiterEnum.CC: case DelimiterEnum.CCC: pair.ValueType = ValueType.Object; return; } if (value == null) { return; } if (valueQuotesType == 1) { pair.ValueType = ValueType.SingleQuotedString; return; } if (valueQuotesType == 2) { pair.ValueType = ValueType.DoubleQuotedString; return; } if (delimiter == DelimiterEnum.E) { pair.ValueType = GetJsonValueType(value, ValueType.FreeOpenString); } if (delimiter == DelimiterEnum.EE || delimiter == DelimiterEnum.None) { pair.ValueType = GetJsonValueType(value, ValueType.OpenString); } }
/// <summary> /// Resolves literal value of the pair. /// </summary> /// <param name="pair"><see cref="Pair"/> with the literal value.</param> /// <param name="valueType">Calculated type of the value.</param> /// <returns>String representing literal value of the pair.</returns> protected string ResolveValue(IMappedPair pair, out ValueType valueType) { if (pair.ValueType != ValueType.DoubleQuotedString && pair.ValueType != ValueType.Concatenation) { if (((Pair)pair).PairValue != null) { return(ResolvePairValue(((Pair)pair).PairValue, out valueType)); } if (((Pair)pair).Assignment.IsObjectAssignment() && pair.IsValueNode) //JSONObject block type. Value is defined by the first child { return(ResolveValue((IMappedPair)((IContainer)pair).Entities.First(), out valueType)); } valueType = pair.ValueType; return(((Pair)pair).Assignment != AssignmentEnum.None ? ((Pair)pair).Value : ((Pair)pair).Name); } return(ResolveValueInInterpolation(pair, out valueType)); }
protected virtual void AddLocationMapRecord(string fileName, IMappedPair pair) { LocationMap.Add(new LexicalInfo(fileName, pair.NameInterval.Begin.Line, pair.NameInterval.Begin.Column, pair.NameInterval.Begin.Index)); }
public static CompilerError UnexpectedDefaultBlockArgument(IMappedPair entity, string fileName) { return(Instantiate("MCE0025", new LexicalInfo(fileName, entity.NameInterval.Begin.Line, entity.NameInterval.Begin.Column, entity.NameInterval.Begin.Index), false)); }
public static CompilerError PropertyIsExpected(IMappedPair node, string fileName) { return(Instantiate("MCE0020", new LexicalInfo(fileName, node.NameInterval.Begin.Line, node.NameInterval.Begin.Column, node.NameInterval.Begin.Index), false)); }
internal static CompilerError ArrayItemIsExpected(IMappedPair node, string fileName) { return(Instantiate("MCE0019", new LexicalInfo(fileName, node.NameInterval.Begin.Line, node.NameInterval.Begin.Column, node.NameInterval.Begin.Index), false)); }
private string ResolveValueInInterpolation(IMappedPair node, out ValueType valueType) { var sb = new StringBuilder(); object previousLine = null; int eolCount = 0; valueType = node.ValueType; //default value if (((IPairWithInterpolation)node).InterpolationItems != null) { foreach (var item in ((IPairWithInterpolation)node).InterpolationItems) { if (item is EscapeMatch escapeMatch) { if (escapeMatch is EolEscapeMatch match) { ResolveDqsEol(match, sb, node.ValueIndent, previousLine); eolCount++; } else { if (eolCount == 1) { sb.Append(" "); } ResolveDqsEscape(escapeMatch, sb); eolCount = 0; } previousLine = item; continue; } if (eolCount == 1) { sb.Append(" "); } eolCount = 0; if (item is Alias alias) { sb.Append(ResolveValueAlias(alias, out valueType)); previousLine = item; continue; } if (item is Parameter param) { sb.Append(ResolveValueParameter(param, out valueType)); previousLine = item; continue; } if (item is Element element) { sb.Append(ResolveValue(element, out valueType)); previousLine = item; continue; } sb.Append(item); previousLine = item; } if (((IPairWithInterpolation)node).InterpolationItems.Count > 1) { valueType = node.ValueType; //restore default value if there are more then 1 interpolation items } } return(sb.ToString()); }