internal static Tuple <string, List <object> > GetValue(ICharStream input, DOM.DelimiterEnum delimiter, int valueQuotesType, DOM.Interval valueInterval, int valueIndent, CompilerContext context, Module module) { if (valueInterval == null) { if (delimiter == DOM.DelimiterEnum.E || delimiter == DOM.DelimiterEnum.EE) { return(new Tuple <string, List <object> >(string.Empty, null)); } return(new Tuple <string, List <object> >(null, null)); } if (valueInterval.Begin.Index == -1) { return(new Tuple <string, List <object> >(string.Empty, null)); } if (valueQuotesType == (int)DOM.QuotesEnum.Single) { if (!ValueIsMissingQuote(input, valueQuotesType, valueInterval)) { return(new Tuple <string, List <object> >(GetValueFromValueInterval((ITextSource)input, delimiter, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index - 1, valueIndent), null)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval((ITextSource)input, delimiter, valueQuotesType, valueInterval.Begin.Index + 1, valueInterval.End.Index, valueIndent), null)); } if (valueQuotesType == (int)QuotesEnum.Double) { var ii = GetInterpolationItems((ITextSource)input, valueInterval, context, module); string value = (string)(ii.Count == 1 && ii[0] is string?ii[0] : string.Empty); return(new Tuple <string, List <object> >(value, ii)); } return(new Tuple <string, List <object> >(GetValueFromValueInterval((ITextSource)input, delimiter, valueQuotesType, valueInterval.Begin.Index, valueInterval.End.Index, valueIndent), null)); }
internal static string GetNameText(ICharStream input, int nameQuotesType, DOM.Interval nameInterval) { if (nameQuotesType == 0) { return(((ITextSource)input).GetText(nameInterval.Begin.Index, nameInterval.End.Index)); } var c = ((ITextSource)input).GetChar(nameInterval.End.Index); if (nameQuotesType == 1) { return(c == '\'' ? ((ITextSource)input).GetText(nameInterval.Begin.Index + 1, nameInterval.End.Index - 1) : ((ITextSource)input).GetText(nameInterval.Begin.Index + 1, nameInterval.End.Index)); } return(c == '"' ? ((ITextSource)input).GetText(nameInterval.Begin.Index + 1, nameInterval.End.Index - 1) : ((ITextSource)input).GetText(nameInterval.Begin.Index + 1, nameInterval.End.Index)); }
public DOM.Pair CreateMappedPair(ICharStream input, int nameQuotesType, DOM.Interval nameInterval, DOM.DelimiterEnum delimiter, Interval delimiterInterval, int valueQuotesType, DOM.Interval valueInterval, int valueIndent) { DOM.Mapped.IMappedPair pair; var nameText = GetNameText(input, nameQuotesType, nameInterval); var value = GetValue(input, delimiter, valueQuotesType, valueInterval, valueIndent, _context, _module); if (nameQuotesType > 0) { pair = new Element { Name = VerifyElementName(nameText, nameInterval, _module), NameQuotesType = nameQuotesType, NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("@")) { var tuple = Element.GetNameAndNs(nameText.Substring(1), nameQuotesType); var ns = string.IsNullOrEmpty(tuple.Item1) ? null : tuple.Item1; pair = new DOM.Mapped.Attribute { NsPrefix = ns, Name = VerifyName(tuple.Item2, nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("!$")) { pair = new DOM.Mapped.AliasDefinition { Name = VerifyName(nameText.Substring(2), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("!#")) { pair = new DOM.Mapped.NamespaceDefinition { Name = VerifyNsName(nameText.Substring(2), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("!%")) { pair = new Parameter { Name = VerifyNsName(nameText.Substring(2), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("!")) { pair = new DOM.Mapped.Document { Name = VerifyName(nameText.Substring(1), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("$")) { pair = new DOM.Mapped.Alias() { Name = VerifyName(nameText.Substring(1), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("%")) { pair = new DOM.Mapped.Argument() { Name = VerifyName(nameText.Substring(1), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else if (nameText.StartsWith("#")) { var tuple = Element.GetNameAndNs(nameText.Substring(1), nameQuotesType); var ns = string.IsNullOrEmpty(tuple.Item1) ? null : tuple.Item1; if (ns == null) { pair = new DOM.Mapped.Scope { NsPrefix = VerifyScopeName(nameText.Substring(1), nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } else { pair = new DOM.Mapped.Scope { NsPrefix = VerifyScopeName(ns, nameInterval, _module), Name = VerifyElementName(tuple.Item2, nameInterval, _module), NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } } else { var tuple = Element.GetNameAndNs(nameText, nameQuotesType); var ns = string.IsNullOrEmpty(tuple.Item1) ? null : tuple.Item1; pair = new Element { NsPrefix = VerifyScopeName(ns, nameInterval, _module), Name = VerifyElementName(tuple.Item2, nameInterval, _module), NameQuotesType = nameQuotesType, NameInterval = nameInterval, Delimiter = delimiter, DelimiterInterval = delimiterInterval, Value = value.Item1, ValueQuotesType = valueQuotesType, ValueInterval = valueInterval, InterpolationItems = value.Item2, ValueIndent = valueIndent }; } SetValueType(pair, delimiter, value.Item1, valueQuotesType); return((Pair)pair); }