Beispiel #1
0
 protected override ConfigCommand Reduce_CommandExpression_2(ConfigToken nullSeg)
 {
     return(new ConfigCommandNull()
     {
         Value = nullSeg
     });
 }
Beispiel #2
0
 protected override ConfigEntryPoint Reduce_EntryPoint_1(ConfigToken nonTerminalSeg)
 {
     return(new ConfigEntryPoint()
     {
         NonTerminal = nonTerminalSeg,
     });
 }
Beispiel #3
0
 protected override ConfigCommand Reduce_CommandExpression_1(ConfigToken argumentValueSeg)
 {
     return(new ConfigCommandArg()
     {
         Value = argumentValueSeg
     });
 }
Beispiel #4
0
 protected override ConfigSegment Reduce_Segment_1(ConfigToken rawSegmentSeg)
 {
     return(new ConfigSegment()
     {
         Token = rawSegmentSeg,
     });
 }
Beispiel #5
0
 protected override ConfigSegment Reduce_Segment_2(ConfigToken rawSegmentSeg, ConfigToken segmentModifierSeg)
 {
     return(new ConfigSegment()
     {
         Token = rawSegmentSeg,
         Modifier = segmentModifierSeg,
     });
 }
 Segment GetSegment(ConfigToken token)
 {
     if (token.Type == ConfigTokenType.NonTerminal)
     {
         return(GetNonTerminal(token.Text));
     }
     else
     {
         return(GetTerminal(token.Text));
     }
 }
Beispiel #7
0
 void ReportUnexpectedToken(ConfigToken token)
 {
     if (token.Type == ConfigTokenType.Error)
     {
         ReporterHelper.AddError(_reporter, token, token.Text);
     }
     else if (token.Type == ConfigTokenType.EOF)
     {
         ReporterHelper.AddError(_reporter, token, "Unexpected end of file.");
     }
     else
     {
         ReporterHelper.AddError(_reporter, token, "Unexpected Token.");
     }
 }
        Segment GetSegment(ConfigToken token, ConfigToken modifier)
        {
            if (modifier == null)
            {
                return(GetSegment(token));
            }
            else
            {
                switch (modifier.Type)
                {
                case ConfigTokenType.QuestionMark:
                    return(GetOptionalProduction(token));

                case ConfigTokenType.Bang:
                    return(GetSegment(token));

                default:
                    throw new InvalidOperationException();
                }
            }
        }
Beispiel #9
0
 protected override ConfigProduction Reduce_Production_1(ConfigToken nonTerminalSeg, ConfigToken productionTypeDefSeg, ConfigProduction ruleListSeg)
 {
     ruleListSeg.Target  = nonTerminalSeg;
     ruleListSeg.TypeRef = productionTypeDefSeg;
     return(ruleListSeg);
 }
Beispiel #10
0
 protected override ConfigProduction Reduce_Production_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(null);
 }
Beispiel #11
0
 protected override ConfigRule Reduce_SegmentList_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new ConfigRule());
 }
Beispiel #12
0
 protected override ConfigEntryPoint Reduce_EntryPoint_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new ConfigEntryPoint());
 }
Beispiel #13
0
 protected override ConfigUsing Reduce_Using_1(ConfigToken labelSeg, ConfigToken stringSeg)
 {
     return(new ConfigUsing(labelSeg, stringSeg));
 }
Beispiel #14
0
 protected override ConfigUsing Reduce_Using_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new ConfigUsing(null, null));
 }
Beispiel #15
0
 protected override Config Reduce_ConfigSettings_5(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new Config());
 }
Beispiel #16
0
 protected override ConfigSetting Reduce_Setting_1(ConfigToken labelSeg, ConfigToken settingValueSeg)
 {
     return(new ConfigSetting(labelSeg, settingValueSeg));
 }
Beispiel #17
0
 protected override ConfigSetting Reduce_Setting_2(ConfigToken labelSeg, ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(null);
 }
Beispiel #18
0
 protected override ConfigCommand Reduce_Command_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(null);
 }
Beispiel #19
0
 protected override ConfigTokenType GetTokenType(ConfigToken terminal) => terminal.Type;
        Segment GetOptionalProduction(ConfigToken token)
        {
            var subSegment = GetSegment(token);

            if (!_optionalProductions.TryGetValue(subSegment, out var masterSegment))
            {
                ConfigUsing cUsing;

                masterSegment = subSegment.GetOptional();

                if (subSegment.IsTerminal)
                {
                    if ((cUsing = _config.TerminalType) != null)
                    {
                        _ntTypes.Add(masterSegment, cUsing);
                    }
                }
                else if (_ntTypes.TryGetValue(subSegment, out cUsing))
                {
                    _ntTypes.Add(masterSegment, cUsing);
                }

                var rule1 = new ConfigRule()
                {
                    Segments =
                    {
                        new ConfigSegment()
                        {
                            Segment = subSegment,
                            Token   = token,
                        },
                    },
                    Production = new Production(masterSegment, ImmutableArray.Create(subSegment)),
                    Command    = new ConfigCommandArg()
                    {
                        Value   = new ConfigToken(ConfigTokenType.ArgumentValue, token.FromPos, token.ToPos, "0"),
                        Segment = subSegment,
                        Using   = cUsing,
                    },
                    FromPos = token.FromPos,
                    ToPos   = token.ToPos,
                };

                var rule2 = new ConfigRule()
                {
                    Segments =
                    {
                    },
                    Production = new Production(masterSegment, ImmutableArray <Segment> .Empty),
                    Command    = new ConfigCommandNull()
                    {
                        Value   = new ConfigToken(ConfigTokenType.Null, token.FromPos, token.ToPos, "null"),
                        Segment = subSegment,
                        Using   = cUsing,
                    },
                    FromPos = token.FromPos,
                    ToPos   = token.ToPos,
                };

                var cProduction = new ConfigProduction()
                {
                    Segment = masterSegment,
                    Target  = new ConfigToken(ConfigTokenType.NonTerminal, token.FromPos, token.ToPos, masterSegment.Name),
                    Using   = cUsing,
                    Rules   =
                    {
                        rule1,
                        rule2,
                    },
                };

                _config.Productions.Add(cProduction);
                _config.RuleLookup.Add(rule1.Production, rule1);
                _config.RuleLookup.Add(rule2.Production, rule2);

                _optionalProductions.Add(subSegment, masterSegment);
            }

            return(masterSegment);
        }
Beispiel #21
0
 protected override Config Reduce_ConfigSettings_4(Config configSettingsSeg, ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(configSettingsSeg);
 }