private static void Deform(IProductionRuleItem item, IProductionRuleCaptureStructuralItem structuralItem, IProductionRule owner)
        {
            /* *
             * Items reduced to their max are for recognizer sections..
             * */
            if (!(item is IProductionRuleGroupItem))
            {
                if ((item.RepeatOptions.Options & ScannableEntryItemRepeatOptions.MaxReduce) == ScannableEntryItemRepeatOptions.MaxReduce && string.IsNullOrEmpty(item.Name))
                {
                    return;
                }

                switch (item.RepeatOptions.Options & (ScannableEntryItemRepeatOptions.OneOrMore | ScannableEntryItemRepeatOptions.ZeroOrMore | ScannableEntryItemRepeatOptions.ZeroOrOne))
                {
                case ScannableEntryItemRepeatOptions.ZeroOrOne:
                    structuralItem.Optional = true;
                    break;

                case ScannableEntryItemRepeatOptions.ZeroOrMore:
                case ScannableEntryItemRepeatOptions.OneOrMore:
                    switch (structuralItem.ResultType)
                    {
                    case ResultedDataType.ImportType:
                        structuralItem.ResultType = ResultedDataType.ImportTypeList;
                        break;
                    }
                    structuralItem.Optional = true;
                    break;
                }
            }
            else
            {
                IProductionRuleCaptureStructure structure = (IProductionRuleCaptureStructure)structuralItem;
                var groupItem = (IProductionRuleGroupItem)item;
                switch (item.RepeatOptions.Options & (ScannableEntryItemRepeatOptions.OneOrMore | ScannableEntryItemRepeatOptions.ZeroOrMore | ScannableEntryItemRepeatOptions.ZeroOrOne))
                {
                case ScannableEntryItemRepeatOptions.ZeroOrOne:
                    structuralItem.Optional = true;
                    break;

                case ScannableEntryItemRepeatOptions.ZeroOrMore:
                case ScannableEntryItemRepeatOptions.OneOrMore:
                    foreach (var subItem in structure.Values)
                    {
                        switch (subItem.ResultType)
                        {
                        case ResultedDataType.ImportType:
                            subItem.ResultType = ResultedDataType.ImportTypeList;
                            break;
                        }
                    }
                    structuralItem.Optional = true;
                    break;
                }
            }
        }
Example #2
0
     protected override IProductionRuleCaptureStructuralItem PerformUnion(IProductionRuleCaptureStructuralItem rightElement)
     {
         if (rightElement is IProductionRuleTokenReferenceStructuralItem)
         {
             return new ProductionRuleTokenReferenceStructuralItem(this.References.Concat(rightElement.Sources.Cast <ITokenReferenceProductionRuleItem>()).ToArray(), this.Rule)
                    {
                        ResultType = UnionResultTypes(rightElement),
                    }
         }
         ;
         return(new ProductionRuleCaptureGeneralStructuralItem(this.Sources.Concat(rightElement.Sources).ToArray(), this.Rule, this.ResultType));
     }
 }
 internal static void ObtainReplacements(IProductionRuleCaptureStructuralItem target, Dictionary <IProductionRuleSource, IProductionRuleCaptureStructuralItem> result)
 {
     foreach (var source in target.Sources)
     {
         if (!result.ContainsKey(source))
         {
             result.Add(source, target);
         }
     }
     if (target is IProductionRuleCaptureStructure)
     {
         ObtainReplacements((IProductionRuleCaptureStructure)target, result);
     }
 }
        internal ResultedDataType UnionResultTypes(IProductionRuleCaptureStructuralItem rightElement)
        {
            switch (this.ResultType)
            {
            case ResultedDataType.None:
                return(rightElement.ResultType);

            case ResultedDataType.EnumerationItem:
                if (rightElement.ResultType == ResultedDataType.FlagEnumerationItem)
                {
                    return(rightElement.ResultType);
                }
                break;

            case ResultedDataType.ImportType:
                if (rightElement.ResultType == ResultedDataType.ImportTypeList)
                {
                    return(ResultedDataType.ImportTypeList);
                }
                break;
            }
            return(this.ResultType);
        }
 protected override IProductionRuleCaptureStructuralItem PerformUnion(IProductionRuleCaptureStructuralItem rightElement)
 {
     return(new ProductionRuleCaptureGeneralStructuralItem(this.Sources.Concat(rightElement.Sources).ToArray(), this.Rule, this.ResultType));
 }
 private static IEnumerable <Tuple <IProductionRuleCaptureStructuralItem, bool> > YieldValue(IProductionRuleCaptureStructuralItem item, bool value)
 {
     yield return(Tuple.Create(item, value));
 }
        private static IProductionRuleCaptureStructuralItem BuildStructureFor(OilexerGrammarProductionRuleEntry entry, IProductionRuleSeries expressionSeries, IProductionRule expression, IProductionRuleItem item, IOilexerGrammarFile source)
        {
            IProductionRuleCaptureStructuralItem result = null;

            if (item is IProductionRuleGroupItem)
            {
                var ruleGroup = ((IProductionRuleGroupItem)(item));
                if (!ruleGroup.Name.IsEmptyOrNull() && AllAreUnnamedEquivalents(ruleGroup))
                {
                    SetAllNames(ruleGroup, ruleGroup.Name);
                }
                result = BuildStructureFor(entry, ruleGroup, source);
                if (result.ResultType == ResultedDataType.None && !item.Name.IsEmptyOrNull())
                {
                    if (ruleGroup.Count == 1 && ruleGroup[0].Count == 1)
                    {
                        var singleItem = ruleGroup[0][0];
                        if (singleItem is ILiteralCharReferenceProductionRuleItem)
                        {
                            if (singleItem.RepeatOptions == ScannableEntryItemRepeatInfo.None && ruleGroup.RepeatOptions == ScannableEntryItemRepeatInfo.None)
                            {
                                result.ResultType = ResultedDataType.Character;
                            }
                            else
                            {
                                result.ResultType = ResultedDataType.String;
                            }
                        }
                        else
                        {
                            result.ResultType = ResultedDataType.String;
                        }
                    }
                    else
                    {
                        result.ResultType = ResultedDataType.String;
                    }
                }
                else if (item.Name.IsEmptyOrNull())
                {
                    result.ResultType = ResultedDataType.PassThrough;
                }
                ((ControlledCollection <IProductionRuleSource>)(result.Sources)).baseList.Add(item);
            }
            else if (item is ILiteralReferenceProductionRuleItem)
            {
                var literalRefItem = (ILiteralReferenceProductionRuleItem)item;
                var inlinedRef     = ((InlinedTokenEntry)(literalRefItem.Source));
                result = new ProductionRuleLiteralTokenItemReferenceStructuralItem(literalRefItem.Source, literalRefItem, entry);
                if (inlinedRef.CaptureKind == RegularCaptureType.Transducer)
                {
                    result.ResultType = ResultedDataType.EnumerationItem;
                }
                else if (inlinedRef.CaptureKind == RegularCaptureType.ContextfulTransducer)
                {
                    result.ResultType = ResultedDataType.FlagEnumerationItem;
                }
            }
            else if (item is ITokenReferenceProductionRuleItem)
            {
                var tokenRefItem = ((ITokenReferenceProductionRuleItem)(item));
                var inlinedRef   = ((InlinedTokenEntry)(tokenRefItem.Reference));
                result = new ProductionRuleTokenReferenceStructuralItem((ITokenReferenceProductionRuleItem)item, entry);
                if (inlinedRef.CaptureKind == RegularCaptureType.Transducer)
                {
                    result.ResultType = ResultedDataType.Enumeration;
                }
                else
                {
                    result.ResultType = ResultedDataType.ImportType;
                }
            }
            else if (item is IRuleReferenceProductionRuleItem)
            {
                var ruleItem = (IRuleReferenceProductionRuleItem)item;
                result = new ProductionRuleCaptureReferenceStructuralItem(ruleItem, entry);
            }
            Deform(item, result, expression);

            return(result);
        }
 protected abstract IProductionRuleCaptureStructuralItem PerformUnion(IProductionRuleCaptureStructuralItem rightElement);
 public IProductionRuleCaptureStructuralItem Union(IProductionRuleCaptureStructuralItem rightElement)
 {
     return(this.PerformUnion(rightElement));
 }