Пример #1
0
 protected override ConfigCommand Reduce_CommandExpression_2(ConfigToken nullSeg)
 {
     return(new ConfigCommandNull()
     {
         Value = nullSeg
     });
 }
Пример #2
0
 protected override ConfigEntryPoint Reduce_EntryPoint_1(ConfigToken nonTerminalSeg)
 {
     return(new ConfigEntryPoint()
     {
         NonTerminal = nonTerminalSeg,
     });
 }
Пример #3
0
 protected override ConfigCommand Reduce_CommandExpression_1(ConfigToken argumentValueSeg)
 {
     return(new ConfigCommandArg()
     {
         Value = argumentValueSeg
     });
 }
Пример #4
0
 protected override ConfigSegment Reduce_Segment_1(ConfigToken rawSegmentSeg)
 {
     return(new ConfigSegment()
     {
         Token = rawSegmentSeg,
     });
 }
Пример #5
0
 protected override ConfigSegment Reduce_Segment_2(ConfigToken rawSegmentSeg, ConfigToken segmentModifierSeg)
 {
     return(new ConfigSegment()
     {
         Token = rawSegmentSeg,
         Modifier = segmentModifierSeg,
     });
 }
Пример #6
0
 Segment GetSegment(ConfigToken token)
 {
     if (token.Type == ConfigTokenType.NonTerminal)
     {
         return(GetNonTerminal(token.Text));
     }
     else
     {
         return(GetTerminal(token.Text));
     }
 }
Пример #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.");
     }
 }
Пример #8
0
        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();
                }
            }
        }
Пример #9
0
 protected override ConfigProduction Reduce_Production_1(ConfigToken nonTerminalSeg, ConfigToken productionTypeDefSeg, ConfigProduction ruleListSeg)
 {
     ruleListSeg.Target  = nonTerminalSeg;
     ruleListSeg.TypeRef = productionTypeDefSeg;
     return(ruleListSeg);
 }
Пример #10
0
 protected override ConfigProduction Reduce_Production_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(null);
 }
Пример #11
0
 protected override ConfigRule Reduce_SegmentList_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new ConfigRule());
 }
Пример #12
0
 protected override ConfigEntryPoint Reduce_EntryPoint_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new ConfigEntryPoint());
 }
Пример #13
0
 protected override ConfigUsing Reduce_Using_1(ConfigToken labelSeg, ConfigToken stringSeg)
 {
     return(new ConfigUsing(labelSeg, stringSeg));
 }
Пример #14
0
 protected override ConfigUsing Reduce_Using_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new ConfigUsing(null, null));
 }
Пример #15
0
 protected override Config Reduce_ConfigSettings_5(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(new Config());
 }
Пример #16
0
 protected override ConfigSetting Reduce_Setting_1(ConfigToken labelSeg, ConfigToken settingValueSeg)
 {
     return(new ConfigSetting(labelSeg, settingValueSeg));
 }
Пример #17
0
 protected override ConfigSetting Reduce_Setting_2(ConfigToken labelSeg, ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(null);
 }
Пример #18
0
 protected override ConfigCommand Reduce_Command_2(ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(null);
 }
Пример #19
0
 protected override ConfigTokenType GetTokenType(ConfigToken terminal) => terminal.Type;
Пример #20
0
        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);
        }
Пример #21
0
 protected override Config Reduce_ConfigSettings_4(Config configSettingsSeg, ConfigToken errorSeg)
 {
     ReportUnexpectedToken(errorSeg);
     return(configSettingsSeg);
 }