public void Append(TextTokenKind tokenKind, string s) { if (s == null) { return; } int oldCurrentOffset = currentOffset; // Newlines could be part of the input string int so = 0; while (so < s.Length) { int nlOffs = s.IndexOfAny(newLineChars, so); if (nlOffs >= 0) { AppendInternal(tokenKind, nlOffs - so); so = nlOffs; int nlLen = s[so] == '\r' && so + 1 < s.Length && s[so + 1] == '\n' ? 2 : 1; currentOffset += nlLen; EndCurrentToken(nlLen); so += nlLen; } else { AppendInternal(tokenKind, s.Length - so); break; } } Debug.Assert(oldCurrentOffset + s.Length == currentOffset); }
public void WriteIdentifier(string identifier, TextTokenKind tokenKind) { var definition = GetCurrentDefinition(); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier), definition, tokenKind); return; } object memberRef = GetCurrentMemberReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier), memberRef, tokenKind); return; } definition = GetCurrentLocalDefinition(); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier), definition, tokenKind); return; } memberRef = GetCurrentLocalReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier), memberRef, tokenKind, true); return; } output.Write(IdentifierEscaper.Escape(identifier), tokenKind); }
static IThemeColor GetColor(TextTokenKind tokenKind) { var color = themeManager.Theme.GetTextColor(tokenKind.ToColorType()); Debug.Assert(color != null); return(color); }
public void Write(string text, int index, int count, TextTokenKind tokenKind) { WriteIndent(); if (index == 0 && text.Length == count) { writer.Write(text); } else if (count == 1) { writer.Write(text[index]); } else { int left = count; while (left > 0) { int len = Math.Min(outputBuffer.Length, left); text.CopyTo(index, outputBuffer, 0, len); writer.Write(outputBuffer, 0, len); left -= len; index += len; } } column += count; }
public override void WriteToken(Role role, string token, TextTokenKind tokenKind) { IMemberRef memberRef = GetCurrentMemberReference(); var node = nodeStack.Peek(); bool addRef = memberRef != null && (node is BinaryOperatorExpression || node is UnaryOperatorExpression || node is AssignmentExpression || node is IndexerExpression); // Add a ref to the method if it's a delegate call if (!addRef && node is InvocationExpression && memberRef is IMethod) { var md = (memberRef as IMethod).Resolve(); if (md != null && md.DeclaringType.IsDelegate()) { addRef = true; } } if (addRef) { output.WriteReference(token, memberRef, tokenKind); } else { output.Write(token, tokenKind); } }
void ITextOutput.Write(string text, int index, int count, TextTokenKind tokenKind) { if (index == 0 && text.Length == count) { ((ITextOutput)this).Write(text, tokenKind); } ((ITextOutput)this).Write(text.Substring(index, count), tokenKind); }
void ITextOutput.Write(StringBuilder sb, int index, int count, TextTokenKind tokenKind) { if (index == 0 && sb.Length == count) { ((ITextOutput)this).Write(sb.ToString(), tokenKind); } ((ITextOutput)this).Write(sb.ToString(index, count), tokenKind); }
void IXmlDocOutput.Write(string s, TextTokenKind tokenKind) { if (needsNewLine) { ((IXmlDocOutput)this).WriteNewLine(); } uiSyntaxHighlighter.Output.Write(s, tokenKind); }
static void WriteIdentifier(ITextOutput output, string id, TextTokenKind tokenKind) { if (isKeyword.Contains(id)) { output.Write("@", TextTokenKind.Operator); } output.Write(IdentifierEscaper.Escape(id), tokenKind); }
public void Write(StringBuilder sb, int index, int count, TextTokenKind tokenKind) { if (index == 0 && sb.Length == count) { Write(sb.ToString(), tokenKind); } Write(sb.ToString(index, count), tokenKind); }
public void Write(string text, int index, int count, TextTokenKind tokenKind) { if (index == 0 && text.Length == count) { Write(text, tokenKind); } Write(text.Substring(index, count), tokenKind); }
/// <summary>Initializes an instance of the <see cref="TextTokenInfo"/> structure.</summary> /// <param name="kind">The type of token.</param> /// <param name="text">The token text.</param> /// <param name="position">The position within the text where the token appears.</param> /// <exception cref="ArgumentOutOfRangeException"><paramref name="position"/> is less than zero.</exception> public TextTokenInfo(TextTokenKind kind, string text, int position) : this() { Verify.Argument("position", position).IsGreaterThanOrEqualToZero(); Kind = kind; OriginalText = text ?? ""; Position = position; }
public override void WriteIdentifier(Identifier identifier, TextTokenKind tokenKind) { if (tokenKind == TextTokenKind.Text) { tokenKind = TextTokenKindUtils.GetTextTokenType(identifier.AnnotationVT <TextTokenKind>() ?? identifier.Annotation <object>()); } if (tokenKind != TextTokenKind.Keyword && (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier))) { output.Write("@", TextTokenKind.Operator); } var definition = GetCurrentDefinition(identifier); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenKind, false); return; } object memberRef = GetCurrentMemberReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenKind); return; } definition = GetCurrentLocalDefinition(); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenKind); return; } memberRef = GetCurrentLocalReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenKind, true); return; } if (firstUsingDeclaration) { firstUsingDeclaration = false; } var s = identifier.Name; if (identifier.Annotation <IdentifierFormatted>() == null) { s = IdentifierEscaper.Escape(s); } output.Write(s, tokenKind); }
public void WriteReference(string text, object reference, TextTokenKind tokenKind, bool isLocal) { WriteIndent(); int start = this.TextLength; Append(tokenKind, text); int end = this.TextLength; references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = reference, IsLocal = isLocal }); }
static TextTokenKind GetTextTokenType(MethodDef method, TextTokenKind staticValue, TextTokenKind instanceValue) { if (method == null) { return(instanceValue); } if (method.IsStatic) { return(staticValue); } return(instanceValue); }
// Gets called to add one token. No newlines are allowed void AppendInternal(TextTokenKind tokenKind, int length) { Debug.Assert(length >= 0); if (length == 0) { return; } redo: if (isAppendingDefaultText) { if (tokenKind == TextTokenKind.Text) { int newLength = currentDefaultTextLength + length; while (newLength > TEXT_TOKEN_LENGTH_MAX) { currentDefaultTextLength = Math.Min(newLength, TEXT_TOKEN_LENGTH_MAX); EndCurrentToken(0); newLength -= TEXT_TOKEN_LENGTH_MAX; } currentDefaultTextLength = newLength; currentOffset += length; return; } isAppendingDefaultText = false; currentTokenType = tokenKind; } if (currentTokenType != tokenKind) { EndCurrentToken(0); goto redo; } { int newLength = currentTokenLength + length; while (newLength > TOKEN_LENGTH_MAX) { currentTokenLength = Math.Min(newLength, TOKEN_LENGTH_MAX); EndCurrentToken(0); newLength -= TOKEN_LENGTH_MAX; isAppendingDefaultText = false; currentTokenType = tokenKind; } currentTokenLength = newLength; if (currentTokenLength == 0) { isAppendingDefaultText = true; } currentOffset += length; } }
void ITextOutput.Write(string text, TextTokenKind tokenKind) { if (col == 1 && indent > 0) output.Write(new string('\t', indent), TextTokenKind.Text); output.Write(text, tokenKind); int index = text.LastIndexOfAny(newLineChars); if (index >= 0) { line += text.Split(lineFeedChar).Length - 1; // good enough for our purposes col = text.Length - (index + 1) + 1; indent = 0; } else col += text.Length; }
public void WriteDefinition(string text, object definition, TextTokenKind tokenKind, bool isLocal) { WriteIndent(); int start = this.TextLength; Append(tokenKind, text); int end = this.TextLength; this.DefinitionLookup.AddDefinition(definition, this.TextLength); references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = definition, IsLocal = isLocal, IsLocalTarget = true }); }
public void WriteToken(string token, TextTokenKind tokenKind) { // Attach member reference to token only if there's no identifier in the current node. IMemberRef memberRef = GetCurrentMemberReference(); if (memberRef != null && nodeStack.Peek().GetChildByRole(AstNode.Roles.Identifier).IsNull) { output.WriteReference(token, memberRef, tokenKind); } else { output.Write(token, tokenKind); } }
void UpdateTextEditorResource(TextTokenKind colorType, string name) { var theme = themeManager.Theme; var color = theme.GetTextColor(colorType.ToColorType()); Application.Current.Resources[GetTextInheritedForegroundResourceKey(name)] = GetBrush(color.Foreground); Application.Current.Resources[GetTextInheritedBackgroundResourceKey(name)] = GetBrush(color.Background); Application.Current.Resources[GetTextInheritedFontStyleResourceKey(name)] = color.FontStyle ?? FontStyles.Normal; Application.Current.Resources[GetTextInheritedFontWeightResourceKey(name)] = color.FontWeight ?? FontWeights.Normal; color = theme.GetColor(colorType.ToColorType()); Application.Current.Resources[GetInheritedForegroundResourceKey(name)] = GetBrush(color.Foreground); Application.Current.Resources[GetInheritedBackgroundResourceKey(name)] = GetBrush(color.Background); Application.Current.Resources[GetInheritedFontStyleResourceKey(name)] = color.FontStyle ?? FontStyles.Normal; Application.Current.Resources[GetInheritedFontWeightResourceKey(name)] = color.FontWeight ?? FontWeights.Normal; }
public void Write(string text, int index, int count, TextTokenKind tokenKind) { WriteIndent(); if (index == 0 && text.Length == count) writer.Write(text); else if (count == 1) writer.Write(text[index]); else { int left = count; while (left > 0) { int len = Math.Min(outputBuffer.Length, left); text.CopyTo(index, outputBuffer, 0, len); writer.Write(outputBuffer, 0, len); left -= len; index += len; } } column += count; }
public override void WriteIdentifier(Identifier identifier, TextTokenKind tokenKind) { if (tokenKind == TextTokenKind.Text) tokenKind = TextTokenKindUtils.GetTextTokenType(identifier.AnnotationVT<TextTokenKind>() ?? identifier.Annotation<object>()); if (tokenKind != TextTokenKind.Keyword && (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier))) { output.Write("@", TextTokenKind.Operator); } var definition = GetCurrentDefinition(identifier); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenKind, false); return; } object memberRef = GetCurrentMemberReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenKind); return; } definition = GetCurrentLocalDefinition(); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenKind); return; } memberRef = GetCurrentLocalReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenKind, true); return; } if (firstUsingDeclaration) { firstUsingDeclaration = false; } var s = identifier.Name; if (identifier.Annotation<IdentifierFormatted>() == null) s = IdentifierEscaper.Escape(s); output.Write(s, tokenKind); }
public void Write(StringBuilder sb, int index, int count, TextTokenKind tokenKind) { WriteIndent(); if (count == 1) { writer.Write(sb[index]); } else { int left = count; while (left > 0) { int len = Math.Min(outputBuffer.Length, left); sb.CopyTo(index, outputBuffer, 0, len); writer.Write(outputBuffer, 0, len); left -= len; } } column += count; }
void ITextOutput.Write(string text, TextTokenKind tokenKind) { if (col == 1 && indent > 0) { output.Write(new string('\t', indent), TextTokenKind.Text); } output.Write(text, tokenKind); int index = text.LastIndexOfAny(newLineChars); if (index >= 0) { line += text.Split(lineFeedChar).Length - 1; // good enough for our purposes col = text.Length - (index + 1) + 1; indent = 0; } else { col += text.Length; } }
public bool Find(int offset, out int defaultTextLength, out TextTokenKind tokenKind, out int tokenLength) { Debug.Assert(tokenInfos != null, "You must call Finish() before you call this method"); int index; if (!offsetToTokenInfoIndex.TryGetValue(offset, out index)) { defaultTextLength = 0; tokenKind = TextTokenKind.Last; tokenLength = 0; return(false); } ushort val = tokenInfos[index]; defaultTextLength = (val >> TEXT_TOKEN_LENGTH_BIT) & TEXT_TOKEN_LENGTH_MAX; tokenKind = (TextTokenKind)((val >> TOKEN_TYPE_BIT) & TOKEN_TYPE_MAX); tokenLength = (val >> TOKEN_LENGTH_BIT) & TOKEN_LENGTH_MAX; return(true); }
void EndCurrentToken(int lengthTillNextToken) { Debug.Assert(currentTokenLength == 0 || !isAppendingDefaultText); int totalLength = currentDefaultTextLength + currentTokenLength; if (totalLength != 0) { offsetToTokenInfoIndex.Add(currentTokenOffset, tokenInfosList.Count); Debug.Assert((int)currentTokenType <= TOKEN_TYPE_MAX); Debug.Assert((int)currentTokenLength <= TOKEN_LENGTH_MAX); Debug.Assert((int)currentDefaultTextLength <= TEXT_TOKEN_LENGTH_MAX); ushort compressedValue = (ushort)( ((int)currentTokenType << TOKEN_TYPE_BIT) | (currentTokenLength << TOKEN_LENGTH_BIT) | (currentDefaultTextLength << TEXT_TOKEN_LENGTH_BIT)); tokenInfosList.Add(compressedValue); } currentTokenOffset += totalLength + lengthTillNextToken; currentDefaultTextLength = 0; currentTokenLength = 0; currentTokenType = TextTokenKind.Last; isAppendingDefaultText = true; }
public static AstType FromName(string fullName, TextTokenKind tokenKind) { if (string.IsNullOrEmpty(fullName)) { throw new ArgumentNullException("fullName"); } fullName = fullName.Trim(); if (!fullName.Contains(".")) { return(new SimpleType(tokenKind, fullName)); } string[] parts = fullName.Split('.'); AstType type = new SimpleType(TextTokenKind.NamespacePart, parts.First()); for (int i = 1; i < parts.Length; i++) { var part = parts[i]; var tt = i + 1 == parts.Length ? tokenKind : TextTokenKind.NamespacePart; type = new QualifiedType(type, Identifier.Create(tt, part)); } return(type); }
void ITextOutput.Write(StringBuilder sb, int index, int count, TextTokenKind tokenKind) { if (index == 0 && sb.Length == count) ((ITextOutput)this).Write(sb.ToString(), tokenKind); ((ITextOutput)this).Write(sb.ToString(index, count), tokenKind); }
static IThemeColor GetColor(TextTokenKind tokenKind) { var color = themeManager.Theme.GetTextColor(tokenKind.ToColorType()); Debug.Assert(color != null); return color; }
void ITextOutput.Write(string text, int index, int count, TextTokenKind tokenKind) { if (index == 0 && text.Length == count) ((ITextOutput)this).Write(text, tokenKind); ((ITextOutput)this).Write(text.Substring(index, count), tokenKind); }
public void Write(string text, TextTokenKind tokenKind) { WriteIndent(); writer.Write(text); column += text.Length; }
HighlightingColor GetColor(TextTokenKind tokenKind) { return textEditor.themeManager.Theme.GetTextColor(tokenKind.ToColorType()).ToHighlightingColor(); }
public void WriteIdentifier(string ident, TextTokenKind tokenKind) { WriteIndentation(); textWriter.Write(ident); }
public override void WritePrimitiveValue(object value, TextTokenKind? tokenKind = null, string literalValue = null) { int column = 0; TextWriterTokenWriter.WritePrimitiveValue(value, tokenKind, literalValue, ref column, (a, b) => output.Write(a, b), WriteToken); }
public void Write(string text, int index, int count, TextTokenKind tokenKind) { if (index == 0 && text.Length == count) Write(text, tokenKind); Write(text.Substring(index, count), tokenKind); }
public void Write(StringBuilder sb, int index, int count, TextTokenKind tokenKind) { if (index == 0 && sb.Length == count) Write(sb.ToString(), tokenKind); Write(sb.ToString(index, count), tokenKind); }
public void Write(string s, TextTokenKind tokenKind) { uiSyntaxHighlighter.Output.Write(s, tokenKind); }
static void WriteIdentifier(ITextOutput output, string id, TextTokenKind tokenKind) { if (isKeyword.Contains(id)) output.Write("@", TextTokenKind.Operator); output.Write(IdentifierEscaper.Escape(id), tokenKind); }
void IXmlDocOutput.Write(string s, TextTokenKind tokenKind) { ret.Append(s); }
public static void WriteOffsetReference(ITextOutput writer, Instruction instruction, MethodDef method, TextTokenKind tokenKind = TextTokenKind.Label) { var r = instruction == null ? null : method == null ? (object)instruction : new InstructionReference(method, instruction); writer.WriteReference(DnlibExtensions.OffsetToString(instruction.GetOffset()), r, tokenKind); }
static TextTokenKind GetTextTokenType(MethodDef method, TextTokenKind staticValue, TextTokenKind instanceValue) { if (method == null) return instanceValue; if (method.IsStatic) return staticValue; return instanceValue; }
public void Write(string s, TextTokenKind tokenKind) { sb.Append(s); }
public void Write(string text, TextTokenKind tokenKind) { WriteIndent(); Append(tokenKind, text); }
void ITextOutput.WriteDefinition(string text, object definition, TextTokenKind tokenKind, bool isLocal) { ((ITextOutput)this).Write(text, tokenKind); }
public void WriteToken(string token, TextTokenKind tokenKind) { WriteIndentation(); textWriter.Write(token); }
public void WriteReference(string text, object reference, TextTokenKind tokenKind, bool isLocal) { Write(text, TextTokenKind.Text); }
void Append(TextTokenKind tokenKind, string s) { tokens.Append(tokenKind, s); b.Append(s); Debug.Assert(b.Length == tokens.Length); }
public void WriteDefinition(string text, object definition, TextTokenKind tokenKind, bool isLocal) { Write(text, TextTokenKind.Text); }
void ITextOutput.WriteReference(string text, object reference, TextTokenKind tokenKind, bool isLocal) { ((ITextOutput)this).Write(text, tokenKind); }
public ErrorMessage(string msg, TextTokenKind type) { this.msg = msg; this.type = type; }
public void Write(string s, TextTokenKind tokenKind) { tokens.Append(tokenKind, s); sb.Append(s); Debug.Assert(sb.Length == tokens.Length); }
public MessageSearchResult(string msg, TextTokenKind type, bool first) { this.msg = msg; this.NameObject = new ErrorMessage(msg, type); this.order = first ? int.MinValue : int.MaxValue; }
public static void WriteLine(this ITextOutput output, string text, TextTokenKind tokenKind) { output.Write(text, tokenKind); output.WriteLine(); }
public void Write(StringBuilder sb, int index, int count, TextTokenKind tokenKind) { WriteIndent(); if (count == 1) writer.Write(sb[index]); else { int left = count; while (left > 0) { int len = Math.Min(outputBuffer.Length, left); sb.CopyTo(index, outputBuffer, 0, len); writer.Write(outputBuffer, 0, len); left -= len; } } column += count; }