protected override void WalkRepetitionExpression(RepetitionExpression repetitionExpression) { base.WalkRepetitionExpression(repetitionExpression); if (this.zeroWidth[repetitionExpression.Expression] && (repetitionExpression.Quantifier.Delimiter == null || this.zeroWidth[repetitionExpression.Quantifier.Delimiter])) { var containsAssertions = this.containsAssertions[repetitionExpression.Expression] || (repetitionExpression.Quantifier.Delimiter != null && this.containsAssertions[repetitionExpression.Quantifier.Delimiter]); var cursor = repetitionExpression.Quantifier.Start; if (repetitionExpression.Quantifier.Max == null) { if (containsAssertions) { this.result.AddCompilerError(cursor, () => Resources.PEG0021_WARNING_ZeroWidthRepetition_Possible); } else { this.result.AddCompilerError(cursor, () => Resources.PEG0021_ERROR_ZeroWidthRepetition_Certain); } } else if (repetitionExpression.Quantifier.Min != repetitionExpression.Quantifier.Max) { if (containsAssertions) { this.result.AddCompilerError(cursor, () => Resources.PEG0022_WARNING_ZeroWidthRepetition_Possible); } else { this.result.AddCompilerError(cursor, () => Resources.PEG0022_WARNING_ZeroWidthRepetition_Certain); } } } }
protected virtual void WalkRepetitionExpression(RepetitionExpression repetitionExpression) { this.WalkExpression(repetitionExpression.Expression); if (repetitionExpression.Quantifier.Delimiter != null) { this.WalkExpression(repetitionExpression.Quantifier.Delimiter); } }
protected override void WalkRepetitionExpression(RepetitionExpression repetitionExpression) { base.WalkRepetitionExpression(repetitionExpression); var result = this.containsAssertions[repetitionExpression.Expression]; if (repetitionExpression.Quantifier.Delimiter != null) { result |= this.containsAssertions[repetitionExpression.Quantifier.Delimiter]; } this.containsAssertions[repetitionExpression] = result; }
private ParseAction ImportRepetitionExpression(Expression exp, Entity entity, ParseAction parent = null, bool optional = false) { RepetitionExpression repetition = ((RepetitionExpression)exp); // recurse down ParseAction action = this.ImportPropertiesAndParseActions( repetition.Expression, entity, parent, optional ); // mark Plural action.IsPlural = true; return(action); }
protected override void WalkRepetitionExpression(RepetitionExpression repetitionExpression) { if (repetitionExpression.Quantifier.Max == 0 || repetitionExpression.Quantifier.Max < repetitionExpression.Quantifier.Min) { this.result.AddCompilerError(repetitionExpression.Quantifier.Start, () => Resources.PEG0015_WARNING_QuantifierInvalid); } if (repetitionExpression.Quantifier.Max == 1 && repetitionExpression.Quantifier.Delimiter != null) { this.result.AddCompilerError(repetitionExpression.Quantifier.Start, () => Resources.PEG0024_WARNING_UnusedDelimiter); } base.WalkRepetitionExpression(repetitionExpression); }
private bool DoAlwaysSucceeds(string ruleName, Expression expr) { bool succeeds = false; do { ChoiceExpression choice = expr as ChoiceExpression; if (choice != null) { // Note that we only need to check the last alternative because we'll // get another error if an interior one always succeeds. succeeds = DoAlwaysSucceeds(ruleName, choice.Expressions[choice.Expressions.Length - 1]); break; } RangeExpression range = expr as RangeExpression; if (range != null) { succeeds = range.ToString() == "."; break; } RepetitionExpression rep = expr as RepetitionExpression; if (rep != null) { succeeds = rep.Min == 0; break; } SequenceExpression seq = expr as SequenceExpression; if (seq != null) { succeeds = seq.Expressions.All(e => DoAlwaysSucceeds(ruleName, e)); break; } RuleExpression rule2 = expr as RuleExpression; if (rule2 != null && rule2.Name != ruleName) { succeeds = DoAlwaysSucceeds(rule2.Name); break; } }while (false); return(succeeds); }
protected override void WalkRepetitionExpression(RepetitionExpression repetitionExpression) { base.WalkRepetitionExpression(repetitionExpression); bool?result; if (repetitionExpression.Quantifier.Min == 0) { result = true; } else if (repetitionExpression.Quantifier.Min <= 1 || repetitionExpression.Quantifier.Delimiter == null) { result = this.zeroWidth[repetitionExpression.Expression]; } else { result = this.zeroWidth[repetitionExpression.Expression] & this.zeroWidth[repetitionExpression.Quantifier.Delimiter]; } this.zeroWidth[repetitionExpression] = result; }
private string GenerateRepetitionExpression(Expression expression) { RepetitionExpression repetition = expression as RepetitionExpression; return("{ " + this.GenerateExpression(repetition.Expression) + " }"); }
protected override void WalkRepetitionExpression(RepetitionExpression repetitionExpression) { base.WalkRepetitionExpression(repetitionExpression); this.Set(repetitionExpression, repetitionExpression.Expression, type => "IList<" + type + ">"); }
protected override void WalkRepetitionExpression(RepetitionExpression repetitionExpression) => this.RenderRepetitionExpression(repetitionExpression, this.writer, this.currentIndentation);