protected override ICaptureTokenStructuralItem PerformUnion(ICaptureTokenStructuralItem rightElement)
 {
     if (rightElement is ICaptureTokenLiteralStructuralItem)
     {
         var rightLiteral = (ICaptureTokenLiteralStructuralItem)rightElement;
         CaptureTokenLiteralStructuralItem result = new CaptureTokenLiteralStructuralItem(this.sources.First());
         result.sources.AddRange(this.sources.Skip(1).ToArray());
         result.sources.AddRange(rightLiteral.Sources.ToArray());
         result.ResultType = this.ResultType;
         if (result.ResultType == ResultedDataType.Character && rightElement.ResultType == ResultedDataType.String)
         {
             result.ResultType = ResultedDataType.String;
         }
         result.Optional = this.Optional || rightElement.Optional;
         return(result);
     }
     else
     {
         return(new CaptureTokenGeneralStructuralItem(this.sources.Concat(rightElement.Sources).ToArray()));
     }
 }
        private static ICaptureTokenStructuralItem BuildStructureFor(InlinedTokenEntry entry, ITokenExpressionSeries expressionSeries, ITokenExpression expression, ITokenItem item, IOilexerGrammarFile source)
        {
            ICaptureTokenStructuralItem result = null;

            if (item is ITokenGroupItem)
            {
                var tokenGroup = ((ITokenGroupItem)(item));
                result = BuildStructureFor(entry, tokenGroup, source);
                if (result.ResultType == ResultedDataType.None && !string.IsNullOrEmpty(item.Name))
                {
                    if (tokenGroup.Count == 1 && tokenGroup[0].Count == 1)
                    {
                        var singleItem = tokenGroup[0][0];
                        if (singleItem is ILiteralCharTokenItem || singleItem is ILiteralCharReferenceTokenItem)
                        {
                            if (singleItem.RepeatOptions == ScannableEntryItemRepeatInfo.None && tokenGroup.RepeatOptions == ScannableEntryItemRepeatInfo.None)
                            {
                                result.ResultType = ResultedDataType.Character;
                            }
                            else
                            {
                                result.ResultType = ResultedDataType.String;
                            }
                        }
                        else
                        {
                            result.ResultType = ResultedDataType.String;
                        }
                    }
                    else
                    {
                        result.ResultType = ResultedDataType.String;
                    }
                }
                bool groupOptional = tokenGroup != null &&
                                     ((tokenGroup.RepeatOptions.Options & ScannableEntryItemRepeatOptions.ZeroOrMore) == ScannableEntryItemRepeatOptions.ZeroOrMore ||
                                      (tokenGroup.RepeatOptions.Options & ScannableEntryItemRepeatOptions.ZeroOrOne) == ScannableEntryItemRepeatOptions.ZeroOrOne ||
                                      (((tokenGroup.RepeatOptions.Options & ScannableEntryItemRepeatOptions.Specific) == ScannableEntryItemRepeatOptions.Specific) &&
                                       (!tokenGroup.RepeatOptions.Min.HasValue || tokenGroup.RepeatOptions.Min.Value == 0)));
                if (groupOptional)
                {
                    result.GroupOptional = groupOptional;
                }
                if (item.Name.IsEmptyOrNull())
                {
                    result.ResultType = ResultedDataType.PassThrough;

                    /*
                     * if ((item.RepeatOptions.Options & ScannableEntryItemRepeatOptions.ZeroOrMore) == ScannableEntryItemRepeatOptions.ZeroOrMore ||
                     *  (item.RepeatOptions.Options & ScannableEntryItemRepeatOptions.ZeroOrOne) == ScannableEntryItemRepeatOptions.ZeroOrOne ||
                     *  ((item.RepeatOptions.Options & ScannableEntryItemRepeatOptions.Specific) == ScannableEntryItemRepeatOptions.Specific &&
                     *  (!item.RepeatOptions.Min.HasValue || item.RepeatOptions.Min.Value == 0)))
                     *  foreach (var element in ((ICaptureTokenStructure)result).Values)
                     *      element.Optional = true;*/
                }

                ((ControlledCollection <ITokenSource>)(result.Sources)).baseList.Add(item);
            }
            else if (item is ILiteralTokenItem)
            {
                result = new CaptureTokenLiteralStructuralItem((ILiteralTokenItem)item);
                if (entry.CaptureKind == RegularCaptureType.Transducer)
                {
                    result.ResultType = ResultedDataType.EnumerationItem;
                }
                else if (entry.CaptureKind == RegularCaptureType.ContextfulTransducer)
                {
                    result.ResultType = ResultedDataType.FlagEnumerationItem;
                }
            }
            else if (item is ICharRangeTokenItem)
            {
                result = new CaptureTokenCharRangeStructuralItem((ICharRangeTokenItem)item);
                if (entry.CaptureKind == RegularCaptureType.Transducer)
                {
                    result.ResultType = ResultedDataType.EnumerationItem;
                }
                else if (entry.CaptureKind == RegularCaptureType.ContextfulTransducer)
                {
                    result.ResultType = ResultedDataType.FlagEnumerationItem;
                }
            }

            Deform(item, result, expression);

            return(result);
        }