protected override ConfigProduction Reduce_RuleList_2(ConfigRule rule) { var production = new ConfigProduction(); production.Rules.Add(rule); return(production); }
void PopulateCommand(ConfigProduction production, ConfigRule rule, int ruleNum) { var command = rule.Command; if (command == null) { var targetName = production.Target.Text; var methodName = string.Format(CultureInfo.InvariantCulture, "Reduce_{0}_{1}", targetName, ruleNum); rule.Command = command = GetImplicitCommand(methodName, rule); } else { var validator = new CommandValidator(_reporter); validator.Validate(command, rule.Production); } SetCommandSegment(command, production.Segment); }
void DecorateRule(ConfigProduction cProduction, ConfigRule cRule, int ruleNum) { var cSegments = cRule.Segments; ImmutableArray <Segment> segments; if (cSegments.Count == 0) { cRule.FromPos = cProduction.Target.FromPos; cRule.ToPos = cProduction.Target.ToPos; segments = ImmutableArray <Segment> .Empty; } else { var builder = ImmutableArray.CreateBuilder <Segment>(cSegments.Count); cRule.FromPos = cSegments[0].Token.FromPos; cRule.ToPos = cSegments[cSegments.Count - 1].Token.ToPos; for (var i = 0; i < cSegments.Count; i++) { var cSegment = cSegments[i]; var segment = GetSegment(cSegment.Token, cSegment.Modifier); cSegment.Segment = segment; builder.Add(segment); } segments = builder.MoveToImmutable(); } var production = new Production(cProduction.Segment, segments); cRule.Production = production; PopulateCommand(cProduction, cRule, ruleNum); if (!_config.RuleLookup.ContainsKey(production)) { _config.RuleLookup.Add(production, cRule); } else { ReporterHelper.AddWarning(_reporter, cRule, "The production '{0}' has already been defined.", production); } }
void DecorateProduction(ConfigProduction cProduction) { var target = cProduction.Segment; if (_ntTypes.TryGetValue(target, out var cUsing)) { cProduction.Using = cUsing; } if (!_nextRuleNum.TryGetValue(target.Name, out var nextRuleNum)) { nextRuleNum = 1; } foreach (var cRule in cProduction.Rules) { DecorateRule(cProduction, cRule, nextRuleNum++); } _nextRuleNum[target.Name] = nextRuleNum; }
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); }
protected override ConfigProduction Reduce_Production_1(ConfigToken nonTerminalSeg, ConfigToken productionTypeDefSeg, ConfigProduction ruleListSeg) { ruleListSeg.Target = nonTerminalSeg; ruleListSeg.TypeRef = productionTypeDefSeg; return(ruleListSeg); }
protected override Config Reduce_Config_1(Config configSeg, ConfigProduction productionSeg) { configSeg.Productions.Add(productionSeg); return(configSeg); }
protected override ConfigProduction Reduce_RuleList_1(ConfigProduction ruleListSeg, ConfigRule rule) { ruleListSeg.Rules.Add(rule); return(ruleListSeg); }