private static ICaptureTokenStructure BuildStructureFor(InlinedTokenEntry entry, ITokenExpressionSeries expressionSeries, ITokenExpression expression, IOilexerGrammarFile source)
        {
            ICaptureTokenStructure result = new CaptureTokenStructure();

            foreach (var item in expression)
            {
                var current = BuildStructureFor(entry, expressionSeries, expression, item, source);
                result = result.Concat(current);
            }
            return(result);
        }
Ejemplo n.º 2
0
 public ICaptureTokenStructuralItem Union(ICaptureTokenStructuralItem rightElement)
 {
     if (rightElement is CaptureTokenStructure)
     {
         return(this.Union((CaptureTokenStructure)rightElement));
     }
     else
     {
         var rightElementStructure = new CaptureTokenStructure();
         rightElementStructure.Concat(rightElement);
         return(this.Union(rightElementStructure));
     }
 }
Ejemplo n.º 3
0
        public ICaptureTokenStructure Union(ICaptureTokenStructure second)
        {
            if (this.Count == 0)
            {
                return(second);
            }
            else if (second.Count == 0)
            {
                return(this);
            }
            var tokenGrpSource =
                (ITokenGroupItem)second.Sources.Where(k => k is ITokenGroupItem).FirstOrDefault();
            var result = new CaptureTokenStructure();
            var left   = this.Keys.Except(second.Keys).ToArray();
            var middle = this.Keys.Intersect(second.Keys).ToArray();
            var right  = second.Keys.Except(this.Keys).ToArray();

            foreach (var element in left)
            {
                result._Add(element, this[element]);
            }
            foreach (var element in middle)
            {
                var leftElement   = this[element];
                var rightElement  = second[element];
                var middleElement = leftElement.Union(rightElement);
                result._Add(element, middleElement);
            }
            foreach (var element in right)
            {
                var rStructure = second[element];
                result._Add(element, rStructure);
            }

            if (this.ResultType == second.ResultType)
            {
                result.ResultType = this.ResultType;
            }
            else
            {
                result.ResultType = ResultedDataType.ComplexType;
            }
            result.ResultedTypeName = this.ResultedTypeName ?? second.ResultedTypeName;
            ((ControlledCollection <ITokenSource>)(result.Sources)).AddRange(this.Sources.ToArray());
            ((ControlledCollection <ITokenSource>)(result.Sources)).AddRange(second.Sources.ToArray());
            result.Optional = this.Optional || second.Optional;

            return(result);
        }
Ejemplo n.º 4
0
        public ICaptureTokenStructure Concat(ICaptureTokenStructuralItem item)
        {
            var k = (from s in item.Sources
                     let sN = s as INamedFiniteAutomataSource
                              where sN != null && !string.IsNullOrEmpty(sN.Name)
                              select sN).FirstOrDefault();

            if (item.ResultType == ResultedDataType.PassThrough)
            {
                return(this.Union((ICaptureTokenStructure)item));
            }
            else if (k == null)
            {
                return(this);
            }

            var result      = new CaptureTokenStructure();
            int?offsetIndex = null;

            foreach (var element in this)
            {
                if (k.Name == element.Value.Name)
                {
                    if (element.Value.BucketIndex == null)
                    {
                        element.Value.BucketIndex = offsetIndex = 1;
                    }
                    else
                    {
                        offsetIndex = element.Value.BucketIndex;
                    }
                    result._Add(element.Value.BucketName, element.Value);
                }
                else
                {
                    result._Add(element.Key, element.Value);
                }
            }
            if (!result.ContainsKey(k.Name))
            {
                if (offsetIndex == null)
                {
                    result._Add(k.Name, item);
                }
                else
                {
                    item.BucketIndex = offsetIndex + 1;
                    result._Add(item.BucketName, item);
                }
            }
            var first = this.Values.FirstOrDefault();

            if (this.Count > 0 && first != null && (first.ResultType == ResultedDataType.FlagEnumerationItem || first.ResultType == ResultedDataType.EnumerationItem))
            {
                if (first.ResultType == ResultedDataType.EnumerationItem)
                {
                    first.ResultType = ResultedDataType.FlagEnumerationItem;
                }
                if (item.ResultType == ResultedDataType.EnumerationItem)
                {
                    item.ResultType = ResultedDataType.FlagEnumerationItem;
                }
            }
            ResultedDataType resultDataType = ResultedDataType.Enumeration;

            foreach (var value in result.Values)
            {
                if (resultDataType == ResultedDataType.Enumeration &&
                    !(value.ResultType == ResultedDataType.EnumerationItem ||
                      value.ResultType == ResultedDataType.FlagEnumerationItem))
                {
                    resultDataType = ResultedDataType.ComplexType;
                }
            }
            result.ResultedTypeName = this.ResultedTypeName;
            result.ResultType       = resultDataType;
            return(result);
        }