public override void Visit(DOM.Scope scope)
        {
            _namespaceResolver.ProcessNsPrefix((IMappedPair)scope);
            if (!string.IsNullOrEmpty(scope.Name))
            {
                var mapped = (Scope)scope;
                var pair   = new Element
                             (
                    scope.Name,
                    nameQuotesType: mapped.NameQuotesType,
                    nameInterval: mapped.NameInterval,
                    assignment: scope.Assignment,
                    assignmentInterval: mapped.AssignmentInterval,
                    value: scope.Value,
                    valueQuotesType: mapped.ValueQuotesType,
                    valueInterval: mapped.ValueInterval,
                    interpolationItems: mapped.InterpolationItems,
                    valueIndent: mapped.ValueIndent,
                    valueType: mapped.ValueType
                             );

                pair.Entities.AddRangeOverrideParent(scope.Entities);
                scope.Entities.Clear();
                scope.Entities.Add(pair);
                ((Scope)scope).OverrideName(null);
            }
            base.Visit(scope);
            Visit(scope.PairValue);
        }
示例#2
0
 /// <summary>
 /// Checks that XML element doesn't have empty name unless it is ValueNode inside the element (mixed content).
 /// </summary>
 /// <param name="node"></param>
 private void CheckArrayItem(Element node)
 {
     if (!string.IsNullOrEmpty(node.Name))
     {
         return;                                   //not an array item
     }
     if (_currentModule.TargetFormat != Module.TargetFormats.Xml)
     {
         return;                                                          //don't check if s4j
     }
     if (node.IsChoice)
     {
         return;                //don't check if node is choice
     }
     if (node.Assignment == AssignmentEnum.CC)
     {
         return;                                       //Empty name is allowed for choice containers
     }
     if (node.Parent.Assignment == AssignmentEnum.CCC)
     {
         return;                                           //Empty name if parent is an explicit array
     }
     if (!node.IsValueNode || node.Parent is DOM.Document) //Empty name is allowed for value (text) nodes
     {
         Context.AddError(CompilerErrorFactory.InvalidXmlElementName(node.NameInterval, _currentModule.FileName));
     }
 }
示例#3
0
 public Pair ProcessBrackets(Pair pair, int bracket, Interval interval)
 {
     if (bracket == '{' || bracket == '[')
     {
         var newPair = new Mapped.Element(((char)bracket).ToString(), nameInterval: interval);
         AppendChild(pair, newPair);
         return(newPair);
     }
     return(pair);
 }
示例#4
0
 /// <inheritdoc />
 public Pair ProcessBrackets(Pair pair, int bracket, Interval interval)
 {
     if (bracket == '{' || bracket == '[')
     {
         if (!(pair is IContainer) && !(pair is Module))
         {
             _context.Errors.Add(CompilerErrorFactory.InvalidInlineJsonDeclaration(interval, _module.FileName));
             return(pair);
         }
         var newPair = new Element(assignmentInterval: interval)
         {
             BlockType = bracket == '{' ? BlockType.JsonObject : BlockType.JsonArray
         };
         AppendChild(pair, newPair);
         return(newPair);
     }
     return(pair);
 }
示例#5
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);
        }
示例#6
0
        public Pair CreateMappedPair(ICharStream input, int nameQuotesType, Interval nameInterval, DelimiterEnum delimiter,
                                     Interval delimiterInterval, int valueQuotesType, Interval valueInterval, int valueIndent)
        {
            Pair pair;
            var  name  = PairFactoryForXml.GetNameText(input, nameQuotesType, nameInterval);
            var  value = PairFactoryForXml.GetValue(input, delimiter, valueQuotesType, valueInterval,
                                                    valueIndent, _context, (Module)_module);

            if (nameQuotesType > 0)
            {
                if (delimiter == DelimiterEnum.None)
                {
                    value = PairFactoryForXml.GetValue(input, delimiter, nameQuotesType, nameInterval,
                                                       0, _context, (Module)_module);
                    valueQuotesType = nameQuotesType;
                }
                pair = new Element
                {
                    Name               = name,
                    NameQuotesType     = nameQuotesType,
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };

                SetValueType((Element)pair, delimiter, value.Item1, valueQuotesType);
            }
            else if (name.StartsWith("@"))
            {
                pair = new DOM.Mapped.Attribute()
                {
                    Name               = name.Substring(1),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
            }
            else if (name.StartsWith("!$"))
            {
                pair = new DOM.Mapped.AliasDefinition
                {
                    Name               = VerifyName(name.Substring(2), nameInterval, _module),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
            }
            else if (name.StartsWith("!#"))
            {
                pair = new DOM.Mapped.NamespaceDefinition
                {
                    Name               = VerifyNsName(name.Substring(2), nameInterval, _module),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
            }
            else if (name.StartsWith("!%"))
            {
                pair = new DOM.Mapped.Parameter
                {
                    Name               = VerifyNsName(name.Substring(2), nameInterval, _module),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
            }
            else if (name.StartsWith("!"))
            {
                pair = new DOM.Mapped.Document
                {
                    Name               = VerifyName(name.Substring(1), nameInterval, _module),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
            }
            else if (name.StartsWith("$"))
            {
                pair = new DOM.Mapped.Alias()
                {
                    Name               = VerifyName(name.Substring(1), nameInterval, _module),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
            }
            else if (name.StartsWith("%"))
            {
                pair = new DOM.Mapped.Argument()
                {
                    Name               = VerifyName(name.Substring(1), nameInterval, _module),
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };

                SetValueType((IMappedPair)pair, delimiter, value.Item1, valueQuotesType);
            }
            else if (name.StartsWith("#"))
            {
                pair = new DOM.Mapped.Scope
                {
                    NsPrefix          = VerifyScopeName(name.Substring(1), nameInterval, _module),
                    NameInterval      = nameInterval,
                    Delimiter         = delimiter,
                    DelimiterInterval = delimiterInterval
                };
                SetValueType((IMappedPair)pair, delimiter, value.Item1, valueQuotesType);
            }
            else
            {
                pair = new Element
                {
                    Name               = name,
                    NameQuotesType     = nameQuotesType,
                    NameInterval       = nameInterval,
                    Delimiter          = delimiter,
                    DelimiterInterval  = delimiterInterval,
                    Value              = value.Item1,
                    ValueQuotesType    = valueQuotesType,
                    ValueInterval      = valueInterval,
                    InterpolationItems = value.Item2,
                    ValueIndent        = valueIndent
                };
                if (delimiter == DelimiterEnum.None)
                {
                    value = PairFactoryForXml.GetValue(input, delimiter, nameQuotesType, nameInterval,
                                                       0, _context, (Module)_module);
                    valueQuotesType = nameQuotesType;
                }
            }
            SetValueType((IMappedPair)pair, delimiter, value.Item1, valueQuotesType);
            return(pair);
        }
示例#7
0
        /// <inheritdoc />
        public Pair CreateMappedPair(ITextSource textSource, int nameQuotesType, Interval nameInterval, AssignmentEnum assignment,
                                     Interval assignmentInterval, int valueQuotesType, Interval valueInterval, int valueIndent)
        {
            Pair pair;
            var  name  = PairFactoryForXml.GetNameText(textSource, nameQuotesType, nameInterval);
            var  value = PairFactoryForXml.GetValue(textSource, assignment, valueQuotesType, valueInterval,
                                                    valueIndent, _context, (Module)_module);

            if (nameQuotesType > 0)
            {
                if (assignment == AssignmentEnum.None)
                {
                    value = PairFactoryForXml.GetValue(textSource, assignment, nameQuotesType, nameInterval,
                                                       0, _context, (Module)_module);
                    valueQuotesType = nameQuotesType;
                }
                pair = new Element(
                    name,
                    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 (name.StartsWith("@"))
            {
                pair = new DOM.Mapped.Attribute(
                    name.Substring(1),
                    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 (name.StartsWith("!$"))
            {
                pair = new DOM.Mapped.AliasDefinition
                       (
                    VerifyName(name.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 (name.StartsWith("!#"))
            {
                pair = new DOM.Mapped.NamespaceDefinition
                       (
                    VerifyNsName(name.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 (name.StartsWith("!%"))
            {
                pair = new DOM.Mapped.Parameter
                       (
                    VerifyNsName(name.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 (name.StartsWith("!"))
            {
                pair = new DOM.Mapped.Document
                       (
                    VerifyName(name.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 (name.StartsWith("$"))
            {
                pair = new DOM.Mapped.Alias
                       (
                    VerifyName(name.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 (name.StartsWith("%"))
            {
                pair = new DOM.Mapped.Argument
                       (
                    VerifyName(name.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 (name.StartsWith("#"))
            //{
            //    pair = new DOM.Mapped.Scope
            //    {
            //        NsPrefix = VerifyScopeName(name.Substring(1), nameInterval, _module),
            //        NameInterval = nameInterval,
            //        Assignment = assignment,
            //        AssignmentInterval = assignmentInterval
            //    };
            //    SetValueType((IMappedPair) pair, assignment, value.Item1, valueQuotesType);
            //}
            else
            {
                pair = new Element
                       (
                    name,
                    nameInterval: nameInterval,
                    assignment: assignment,
                    assignmentInterval: assignmentInterval,
                    value: value.Item1,
                    valueQuotesType: valueQuotesType,
                    valueInterval: valueInterval,
                    interpolationItems: value.Item2,
                    valueIndent: valueIndent,
                    valueType: GetValueType(assignment,
                                            (assignment == AssignmentEnum.None? PairFactoryForXml.GetValue(textSource, assignment, nameQuotesType, nameInterval,
                                                                                                           0, _context, (Module)_module).Item1:value.Item1),
                                            assignment == AssignmentEnum.None ? nameQuotesType: valueQuotesType)
                       );
            }

            return(pair);
        }