Esempio n. 1
0
        /// <summary>
        /// Resolves namespace and prefix for <see cref="INsNode"/>.
        /// </summary>
        /// <param name="node">Target <see cref="INsNode"/>.</param>
        /// <param name="document">Current <see cref="Document"/>.</param>
        /// <param name="currentModuleMember">Current module member.</param>
        /// <param name="scope">Current <see cref="Scope"/>.</param>
        /// <param name="prefix">Output namespace prefix parameter.</param>
        /// <param name="ns">Output namespace parameter.</param>
        public void GetPrefixAndNs(INsNode node, DOM.Document document, ModuleMember currentModuleMember, Scope scope, out string prefix,
                                   out string ns)
        {
            prefix = null;
            ns     = null;

            var nsPrefix = node.NsPrefix;

            if (nsPrefix == null)
            {
                if (scope == null)
                {
                    return;
                }
                nsPrefix = scope.NsPrefix;
            }
            GetPrefixAndNs(nsPrefix, node, document, currentModuleMember, out prefix, out ns);
        }
Esempio n. 2
0
        /// <inheritdoc />
        public Pair CreateMappedPair(ITextSource textSource, int nameQuotesType, Interval nameInterval,
                                     AssignmentEnum assignment,
                                     Interval assignmentInterval, int valueQuotesType, Interval valueInterval, int valueIndent)
        {
            IMappedPair pair;
            var         nameText = GetNameText(textSource, nameQuotesType, nameInterval);
            var         value    = GetValue(textSource, assignment, valueQuotesType, valueInterval, valueIndent, _context, _module);

            if (nameQuotesType > 0)
            {
                pair = new Element
                       (
                    VerifyElementName(nameText, nameInterval, _module),
                    nameQuotesType: nameQuotesType,
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("@"))
            {
                var tuple = Element.GetNameAndNs(nameText.Substring(1), nameQuotesType);
                var ns    = string.IsNullOrEmpty(tuple.Item1) ? null : tuple.Item1;
                pair = new Attribute
                       (
                    VerifyName(tuple.Item2, nameInterval, _module),
                    ns,
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("!$"))
            {
                pair = new AliasDefinition
                       (
                    VerifyName(nameText.Substring(2), nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("!#"))
            {
                pair = new NamespaceDefinition
                       (
                    VerifyNsName(nameText.Substring(2), nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("!%"))
            {
                pair = new Parameter
                       (
                    VerifyNsName(nameText.Substring(2), nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("!"))
            {
                pair = new Document
                       (
                    VerifyName(nameText.Substring(1), nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("$"))
            {
                pair = new Alias
                       (
                    VerifyName(nameText.Substring(1), nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            else if (nameText.StartsWith("%"))
            {
                pair = new Argument
                       (
                    VerifyName(nameText.Substring(1), nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            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 Scope
                           (
                        null,
                        VerifyScopeName(nameText.Substring(1), nameInterval, _module),
                        nameInterval: nameInterval,
                        assignment: assignment,
                        assignmentInterval: assignmentInterval,
                        value: value.Item1,
                        valueQuotesType: valueQuotesType,
                        valueInterval: valueInterval,
                        interpolationItems: value.Item2,
                        valueIndent: valueIndent,
                        valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                           );
                }
                else
                {
                    pair = new Scope
                           (
                        VerifyElementName(tuple.Item2, nameInterval, _module),
                        VerifyScopeName(ns, nameInterval, _module),
                        nameInterval: nameInterval,
                        assignment: assignment,
                        assignmentInterval: assignmentInterval,
                        value: value.Item1,
                        valueQuotesType: valueQuotesType,
                        valueInterval: valueInterval,
                        interpolationItems: value.Item2,
                        valueIndent: valueIndent,
                        valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                           );
                }
            }
            else
            {
                var tuple = Element.GetNameAndNs(nameText, nameQuotesType);
                var ns    = string.IsNullOrEmpty(tuple.Item1) ? null : tuple.Item1;

                pair = new Element
                       (
                    VerifyElementName(tuple.Item2, nameInterval, _module),
                    VerifyScopeName(ns, nameInterval, _module),
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment, value.Item1, valueQuotesType)
                       );
            }
            return((Pair)pair);
        }