public override bool CheckIntegrity(TablatureContext context, ILogger logger) { var lastIndex = 0; var missingIndices = new List <int>(); foreach (var index in context.DocumentState.DefinedAlternationIndices.OrderBy(i => i)) { if (index != lastIndex + 1) { missingIndices.Add(index); } lastIndex = index; } if (missingIndices.Count == 0) { return(true); } var alternationTextType = context.DocumentState.AlternationTextType ?? AlternationTextType.Arabic; logger.Report(LogLevel.Error, null, Messages.Error_MissingAlternationTexts, string.Join(", ", missingIndices.Select(i => AlternationText.GetAlternationText(alternationTextType, i)))); return(false); }
public override bool TryParse(Scanner scanner, out AlternateCommandletNode commandlet) { commandlet = new AlternateCommandletNode(); var hasColon = scanner.SkipOptional(':', true); while (!scanner.EndOfLine) { var text = scanner.ReadPattern(@"\w+"); if (!AlternationText.IsValid(text)) { this.Report(LogLevel.Error, scanner.LastReadRange, Messages.Error_InvalidAlternationText); commandlet = null; return(false); } commandlet.AlternationTexts.Add(new LiteralNode <string>(text, scanner.LastReadRange)); scanner.SkipOptional(',', true); } if (hasColon && commandlet.AlternationTexts.Count == 0) { this.Report(LogLevel.Warning, scanner.LastReadRange, Messages.Warning_AlternationTextExpectedAfterColon); } return(true); }
public bool ToDocumentElement(TablatureContext context, ILogger logger, out Alternation element) { if (this.AlternationTexts.Count == 0) // implicit { var implicitIndex = context.DocumentState.DefinedAlternationIndices.Max() + 1; element = new Alternation { Range = this.Range, TextType = context.DocumentState.AlternationTextType ?? AlternationTextType.Arabic, Explicity = Explicity.Implicit, Indices = new[] { implicitIndex } }; return(true); } element = new Alternation { Range = this.Range, Explicity = Explicity.Explicit }; var referenceTextType = context.DocumentState.AlternationTextType; var indices = new List <int>(); foreach (var alternationText in this.AlternationTexts) { int index; AlternationTextType textType; Debug.Assert(AlternationText.TryParse(alternationText.Value, out index, out textType)); if (referenceTextType != null && referenceTextType.Value != textType) { logger.Report(LogLevel.Warning, alternationText.Range, Messages.Warning_InconsistentAlternationTextType); } else { referenceTextType = textType; } if (context.DocumentState.DefinedAlternationIndices.Contains(index)) { logger.Report(LogLevel.Error, alternationText.Range, Messages.Error_DuplicatedAlternationText, alternationText.Value); element = null; return(false); } indices.Add(index); } Debug.Assert(referenceTextType != null, "referenceTextType != null"); element.TextType = referenceTextType.Value; element.Indices = indices.ToArray(); return(true); }