private static int ProcessNormal(FormattedText text, Queue <string> lineParts, int documentOffset) { // Format: any line that isn't one of the other types. Can contain a mixture of keywords // and non-keyword text. Probably doesn't contain entities. // // Parse the line for keywords only // Only need to get this if a keyword is actually found. TextStyle keywordStyle = null; while (lineParts.Count > 0) { var item = lineParts.Dequeue(); if (Keywords.IsKeyword(item)) { if (keywordStyle == null) { keywordStyle = TextStyles.GetStyleForTokenType(TokenType.Keyword); } keywordStyle.Apply(text, documentOffset, item.Length); } documentOffset += item.Length + (lineParts.Count == 0 ? LINE_SEPARATOR_LENGTH : 1); } return(documentOffset); }
private static int ApplyStyleToEntireLine(TokenType tokenType, FormattedText text, string line, int documentOffset) { var textStyle = TextStyles.GetStyleForTokenType(tokenType); textStyle.Apply(text, documentOffset, line.Length); return(documentOffset + line.Length + LINE_SEPARATOR_LENGTH); }
private int ProcessDeclaration(FormattedText text, Queue <string> lineParts, int documentOffset) { // TODO: Potential IndexOutOfRange exceptions; needs validation // Format: entity_type entity_name as entity_alias { // Everything after entity_name is optional var entityTypeStyle = TextStyles.GetStyleForTokenType(TokenType.Keyword); var entityNameStyle = TextStyles.GetStyleForTokenType(TokenType.Entity); // Part 0 is always the entity type documentOffset = ApplyStyleToNextItem(entityTypeStyle, lineParts, text, documentOffset); // Part 1 is always the entity name documentOffset = ApplyStyleToNextItem(entityNameStyle, lineParts, text, documentOffset); // We could be done here if (lineParts.Count == 0) { return(documentOffset); } if (lineParts.Peek() == "as") { // If they exist, parts 2 and 3 are always "as" and the alias documentOffset = ApplyStyleToNextItem(entityTypeStyle, lineParts, text, documentOffset); documentOffset = ApplyStyleToNextItem(entityNameStyle, lineParts, text, documentOffset); } // Tack the rest on as normal text if (lineParts.Count > 0) { while (lineParts.Any()) { var item = lineParts.Dequeue(); documentOffset += item.Length + (lineParts.Count == 0 ? LINE_SEPARATOR_LENGTH : 1); } } return(documentOffset); }
private int ProcessLink(FormattedText text, Queue <string> lineParts, int documentOffset) { // Format: entity_name arrow entity_name : message // The message is optional. // TODO: Potential IndexOutOfRange errors var entityStyle = TextStyles.GetStyleForTokenType(TokenType.Entity); // Part 0 is always an entity documentOffset = ApplyStyleToNextItem(entityStyle, lineParts, text, documentOffset); // Part 1 is always an arrow and no format is necessary var currentItem = lineParts.Dequeue(); documentOffset += currentItem.Length + (lineParts.Count == 0 ? LINE_SEPARATOR_LENGTH : 1); // Part 2 is always an entity documentOffset = ApplyStyleToNextItem(entityStyle, lineParts, text, documentOffset); if (lineParts.Count != 0) { // If part 3 is not a colon, just format the rest of the line as normal text TextStyle remainingStyle; if (lineParts.Peek() == ":") { remainingStyle = TextStyles.GetStyleForTokenType(TokenType.Message); } else { remainingStyle = TextStyles.GetStyleForTokenType(TokenType.Normal); } while (lineParts.Count > 0) { documentOffset = ApplyStyleToNextItem(remainingStyle, lineParts, text, documentOffset); } } return(documentOffset); }