void PopulateUsings()
        {
            var usingLookup = new Dictionary <string, ConfigUsing>();

            foreach (var cUsing in _config.Usings)
            {
                var label = cUsing.Label.Text;

                if (!usingLookup.ContainsKey(label))
                {
                    usingLookup.Add(label, cUsing);
                }
                else
                {
                    ReporterHelper.AddError(_reporter, cUsing.Label, "Type reference already defined.");
                }
            }

            {
                var label = _config.Manager.TokenType;

                if (!string.IsNullOrEmpty(label) && usingLookup.TryGetValue(label, out var terminalType))
                {
                    _config.TerminalType = terminalType;
                }
            }

            var pending = new List <Segment>();

            foreach (var cProduction in _config.Productions)
            {
                var name    = cProduction.Target.Text;
                var segment = GetNonTerminal(name);
                cProduction.Segment = segment;

                if (cProduction.TypeRef == null)
                {
                    pending.Add(segment);
                }
                else
                {
                    if (!usingLookup.TryGetValue(cProduction.TypeRef.Text, out var cUsing))
                    {
                        ReporterHelper.AddError(_reporter, cProduction.TypeRef, "Unknown type reference.");
                    }
                    else if (!_ntTypes.TryGetValue(segment, out var cExistingUsing))
                    {
                        _ntTypes.Add(segment, cUsing);
                    }
                    else if (cUsing != cExistingUsing)
                    {
                        ReporterHelper.AddError(_reporter, cProduction.TypeRef, "This type conflicts with a previous definition of <{0}>.", name);
                    }
                }
            }

            ConfigUsing defaultUsing = null;

            if (_config.TerminalType == null)
            {
                defaultUsing = CreateDefaultUsing(usingLookup);
                _config.Usings.Add(defaultUsing);
                _config.TerminalType = defaultUsing;
            }

            foreach (var segment in pending)
            {
                if (_ntTypes.ContainsKey(segment))
                {
                    continue;
                }

                if (defaultUsing == null)
                {
                    defaultUsing = CreateDefaultUsing(usingLookup);
                    _config.Usings.Add(defaultUsing);
                }

                _ntTypes.Add(segment, defaultUsing);
            }
        }
Example #2
0
 protected override Config Reduce_ConfigSettings_2(Config configSettingsSeg, ConfigUsing usingSeg)
 {
     configSettingsSeg.Usings.Add(usingSeg);
     return(configSettingsSeg);
 }