/// <summary> /// Gets the offset of the start of the specified language. If the stream is not currently /// in that language, the result is meaningless. /// </summary> /// <param name="stream">The stream to search.</param> /// <param name="language">The language we are currently in and should find the start of.</param> /// <param name="startTokenKey">The token which delimits this language block. If used, stops /// the delimiters being counted as part of the language block.</param> /// <returns>The offset at which the language starts.</returns> public static int GetStartOfLanguageBlock(TextStream stream, string language, string startTokenKey) { do { if (stream.Token.Language.Tag.ToString() != language || stream.Token.Key == startTokenKey) { stream.SeekToken(1); break; } stream.SeekToken(-1); }while (stream.Token.StartOffset > 0); return(stream.Token.StartOffset); }
/// <summary> /// Gets the offset of the end of the specified language. If the stream is not currently /// in that language, the result is meaningless. /// </summary> /// <param name="stream">The stream to search.</param> /// <param name="language">The language we are currently in and should find the end of.</param> /// <param name="endTokenKey">The token which delimits this language block. If used, stops /// the delimiters being counted as part of the language block.</param> /// <returns>The offset at which the language ends.</returns> public static int GetEndOfLanguageBlock(TextStream stream, string language, string endTokenKey) { do { if (stream.Token.Language.Tag.ToString() != language || stream.IsAtDocumentEnd || stream.Token.Key == endTokenKey) { stream.SeekToken(-1); break; } stream.SeekToken(1); }while (true); return(stream.Token.EndOffset); }
/// <summary> /// Gets the first index of ASPDirectiveEndToken from the given stream. /// </summary> /// <param name="stream">The stream to search.</param> /// <returns>The index of the first ASP end token, or -1 if there isn't one /// after the stream's current offset.</returns> public static int GetFirstEndScriptTag(TextStream stream) { do { if (stream.Token.Key == "ASPDirectiveEndToken") { return(stream.Token.StartOffset); } stream.SeekToken(1); }while (stream.IsAtDocumentEnd == false); return(-1); }
/// <summary> /// Checks the given line and determines if it is one single language. /// </summary> /// <param name="line">The line to check.</param> /// <param name="stream">The TextStream from the Document the line belongs to. We /// need this because the line does not have a reference to its parent Document.</param> /// <param name="language">The text representation of the language. We compare this against /// stream.Token.Language.Tag.ToString().</param> /// <returns>True if the line contains one language, false if it contains two or more.</returns> public static bool IsEntireLineOneLanguage(DocumentLine line, TextStream stream, string language) { bool isLineTemplateLanguage = true; stream.Offset = line.StartOffset; do { if (stream.Token.Language.Tag.ToString() != language) { isLineTemplateLanguage = false; break; } stream.SeekToken(1); }while (stream.Token.EndOffset <= line.EndOffset && stream.IsAtDocumentEnd == false); return(isLineTemplateLanguage); }
private Function GetFunction(TextStream textStream, Document document) { int nesting = 0; while (nesting != -1) { if (textStream.TokenIndex == 0) { return(null); } textStream.SeekToken(-1); switch (textStream.PeekToken().Key) { case "OpenParenthesisToken": nesting--; break; case "CloseParenthesisToken": nesting++; break; } } if (!textStream.GoToPreviousToken()) { return(null); } string functionName; if (textStream.Token.Key == "IdentifierToken") { functionName = document.GetTokenText(textStream.Token); } else { return(null); } /*if (textStream.TokenIndex == 0) * return null; * * textStream.SeekToken(-1);*/ Namespace ns = GetNamespace(textStream, document); if (ns == null) { return(null); } foreach (Function f in ns.Functions) { if (f.Name == functionName) { return(f); } } return(null); }
/// <summary> /// Checks the given line and determines if it is one single language. /// </summary> /// <param name="line">The line to check.</param> /// <param name="stream">The TextStream from the Document the line belongs to. We /// need this because the line does not have a reference to its parent Document.</param> /// <param name="language">The text representation of the language. We compare this against /// stream.Token.Language.Tag.ToString().</param> /// <returns>True if the line contains one language, false if it contains two or more.</returns> public static bool IsEntireLineOneLanguage(DocumentLine line, TextStream stream, string language) { bool isLineTemplateLanguage = true; stream.Offset = line.StartOffset; do { if (stream.Token.Language.Tag.ToString() != language) { isLineTemplateLanguage = false; break; } stream.SeekToken(1); } while (stream.Token.EndOffset <= line.EndOffset && stream.IsAtDocumentEnd == false); return isLineTemplateLanguage; }
/// <summary> /// Gets the offset of the start of the specified language. If the stream is not currently /// in that language, the result is meaningless. /// </summary> /// <param name="stream">The stream to search.</param> /// <param name="language">The language we are currently in and should find the start of.</param> /// <param name="startTokenKey">The token which delimits this language block. If used, stops /// the delimiters being counted as part of the language block.</param> /// <returns>The offset at which the language starts.</returns> public static int GetStartOfLanguageBlock(TextStream stream, string language, string startTokenKey) { do { if (stream.Token.Language.Tag.ToString() != language || stream.Token.Key == startTokenKey) { stream.SeekToken(1); break; } stream.SeekToken(-1); } while (stream.Token.StartOffset > 0); return stream.Token.StartOffset; }
/// <summary> /// Gets the first index of ASPDirectiveStartToken from the given stream. /// </summary> /// <param name="stream">The stream to search.</param> /// <returns>The index of the first ASP start token, or -1 if there isn't one /// after the stream's current offset.</returns> public static int GetFirstStartScriptTag(TextStream stream) { do { if (stream.Token.Key == "ASPDirectiveStartToken") { return stream.Token.StartOffset; } stream.SeekToken(1); } while (stream.IsAtDocumentEnd == false); return -1; }
/// <summary> /// Gets the offset of the end of the specified language. If the stream is not currently /// in that language, the result is meaningless. /// </summary> /// <param name="stream">The stream to search.</param> /// <param name="language">The language we are currently in and should find the end of.</param> /// <param name="endTokenKey">The token which delimits this language block. If used, stops /// the delimiters being counted as part of the language block.</param> /// <returns>The offset at which the language ends.</returns> public static int GetEndOfLanguageBlock(TextStream stream, string language, string endTokenKey) { do { if (stream.Token.Language.Tag.ToString() != language || stream.IsAtDocumentEnd || stream.Token.Key == endTokenKey) { stream.SeekToken(-1); break; } stream.SeekToken(1); } while (true); return stream.Token.EndOffset; }