public override void WriteToken(Role role, string token, TextTokenType tokenType) { WriteIndentation(); column += token.Length; textWriter.Write(token); isAtStartOfLine = false; }
public override void WriteToken(Role role, string token, TextTokenType tokenType) { // Avoid that two +, - or ? tokens are combined into a ++, -- or ?? token. // Note that we don't need to handle tokens like = because there's no valid // C# program that contains the single token twice in a row. // (for +, - and &, this can happen with unary operators; // for ?, this can happen in "a is int? ? b : c" or "a as int? ?? 0"; // and for /, this can happen with "1/ *ptr" or "1/ //comment".) if (lastWritten == LastWritten.Plus && token[0] == '+' || lastWritten == LastWritten.Minus && token[0] == '-' || lastWritten == LastWritten.Ampersand && token[0] == '&' || lastWritten == LastWritten.QuestionMark && token[0] == '?' || lastWritten == LastWritten.Division && token[0] == '*') { base.Space(); } base.WriteToken(role, token, tokenType); if (token == "+") { lastWritten = LastWritten.Plus; } else if (token == "-") { lastWritten = LastWritten.Minus; } else if (token == "&") { lastWritten = LastWritten.Ampersand; } else if (token == "?") { lastWritten = LastWritten.QuestionMark; } else if (token == "/") { lastWritten = LastWritten.Division; } else { lastWritten = LastWritten.Other; } }
public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType) { WriteIndentation(); if (tokenType != TextTokenType.Keyword && (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier))) { textWriter.Write('@'); column++; } textWriter.Write(identifier.Name); column += identifier.Name.Length; isAtStartOfLine = false; }
public override void WriteToken(Role role, string token, TextTokenType tokenType) { CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role); t.Role = role; EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement; if (node == null) currentList.Add(t); else { node.Location = locationProvider.Location; } base.WriteToken(role, token, tokenType); }
public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType) { if (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier)) { if (lastWritten == LastWritten.KeywordOrIdentifier) { // this space is not strictly required, so we call Space() Space(); } } else if (lastWritten == LastWritten.KeywordOrIdentifier) { // this space is strictly required, so we directly call the formatter base.Space(); } base.WriteIdentifier(identifier, tokenType); lastWritten = LastWritten.KeywordOrIdentifier; }
static void UpdateTextEditorResource(TextTokenType colorType, string name) { var theme = Themes.Theme; var color = theme.GetColor(colorType).TextInheritedColor; App.Current.Resources[Theme.GetTextInheritedForegroundResourceKey(name)] = GetBrush(color.Foreground); App.Current.Resources[Theme.GetTextInheritedBackgroundResourceKey(name)] = GetBrush(color.Background); App.Current.Resources[Theme.GetTextInheritedFontStyleResourceKey(name)] = color.FontStyle ?? FontStyles.Normal; App.Current.Resources[Theme.GetTextInheritedFontWeightResourceKey(name)] = color.FontWeight ?? FontWeights.Normal; color = theme.GetColor(colorType).InheritedColor; App.Current.Resources[Theme.GetInheritedForegroundResourceKey(name)] = GetBrush(color.Foreground); App.Current.Resources[Theme.GetInheritedBackgroundResourceKey(name)] = GetBrush(color.Background); App.Current.Resources[Theme.GetInheritedFontStyleResourceKey(name)] = color.FontStyle ?? FontStyles.Normal; App.Current.Resources[Theme.GetInheritedFontWeightResourceKey(name)] = color.FontWeight ?? FontWeights.Normal; }
public bool Find(int offset, out int defaultTextLength, out TextTokenType tokenType, 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; tokenType = TextTokenType.Last; tokenLength = 0; return false; } ushort val = tokenInfos[index]; defaultTextLength = (val >> TEXT_TOKEN_LENGTH_BIT) & TEXT_TOKEN_LENGTH_MAX; tokenType = (TextTokenType)((val >> TOKEN_TYPE_BIT) & TOKEN_TYPE_MAX); tokenLength = (val >> TOKEN_LENGTH_BIT) & TOKEN_LENGTH_MAX; return true; }
public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType) { if (tokenType == TextTokenType.Text) tokenType = TextTokenHelper.GetTextTokenType(identifier.AnnotationVT<TextTokenType>() ?? identifier.Annotation<object>()); if (tokenType != TextTokenType.Keyword && (identifier.IsVerbatim || CSharpOutputVisitor.IsKeyword(identifier.Name, identifier))) { output.Write('@', TextTokenType.Operator); } var definition = GetCurrentDefinition(identifier); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType, false); return; } object memberRef = GetCurrentMemberReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType); return; } definition = GetCurrentLocalDefinition(); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType); return; } memberRef = GetCurrentLocalReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType, true); return; } if (firstUsingDeclaration) { output.MarkFoldStart(defaultCollapsed: true); firstUsingDeclaration = false; } var s = identifier.Name; if (identifier.Annotation<IdentifierFormatted>() == null) s = IdentifierEscaper.Escape(s); output.Write(s, tokenType); }
public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType) { if (tokenType == TextTokenType.Text) tokenType = TextTokenHelper.GetTextTokenType(identifier.AnnotationVT<TextTokenType>() ?? identifier.Annotation<object>()); var definition = GetCurrentDefinition(identifier); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType, false); return; } object memberRef = GetCurrentMemberReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType); return; } definition = GetCurrentLocalDefinition(); if (definition != null) { output.WriteDefinition(IdentifierEscaper.Escape(identifier.Name), definition, tokenType); return; } memberRef = GetCurrentLocalReference(); if (memberRef != null) { output.WriteReference(IdentifierEscaper.Escape(identifier.Name), memberRef, tokenType, true); return; } if (firstUsingDeclaration) { output.MarkFoldStart(defaultCollapsed: true); firstUsingDeclaration = false; } output.Write(IdentifierEscaper.Escape(identifier.Name), tokenType); }
public void Write(string text, TextTokenType tokenType) { WriteIndent(); Append(tokenType, text); }
public void Write(char ch, TextTokenType tokenType) { WriteIndent(); Append(tokenType, ch); }
void Append(TextTokenType tokenType, char c) { tokens.Append(tokenType, c); b.Append(c); Debug.Assert(b.Length == tokens.Length); }
public IEnumerator <string> GetEnumerator() { bool insideQuote = false; TextTokenType quoteType = TextTokenType.Separator; StringBuilder result = new StringBuilder(); foreach (TextToken token in tokenizer) { switch (token.Type) { case TextTokenType.Separator: if (insideQuote) { result.Append(token.Value); } else { if (!string.IsNullOrWhiteSpace(token.Value) || result.Length > 0) { yield return(result.ToString()); } result.Length = 0; } break; case TextTokenType.SingleQuote: case TextTokenType.DoubleQoute: if (!insideQuote) { quoteType = token.Type; insideQuote = true; if (result.Length > 0) { yield return(result.ToString()); } result.Length = 0; } else if (token.Type == quoteType) { insideQuote = false; quoteType = TextTokenType.Separator; } else { result.Append(token.Value); } break; case TextTokenType.Value: result.Append(token.Value); break; default: throw new InvalidOperationException("Unknown token type: " + token.Type); } } if (result.Length > 0) { yield return(result.ToString()); } }
// Gets called to add one token. No newlines are allowed void AppendInternal(TextTokenType tokenType, int length) { Debug.Assert(length >= 0); if (length == 0) return; redo: if (isAppendingDefaultText) { if (tokenType == TextTokenType.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 = tokenType; } if (currentTokenType != tokenType) { 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 = tokenType; } currentTokenLength = newLength; if (currentTokenLength == 0) isAppendingDefaultText = true; currentOffset += length; } }
public Color GetColor(TextTokenType tokenType) { return GetColor((ColorType)tokenType); }
void IXmlDocOutput.Write(string s, TextTokenType tokenType) { ret.Append(s); }
public TextToken(TextTokenType type, string text) { Type = type; Text = text; }
public void Append(TextTokenType tokenType, char c) { Append(tokenType, c.ToString()); }
public static void WriteOffsetReference(ITextOutput writer, Instruction instruction, MethodDef method, TextTokenType tokenType = TextTokenType.Label) { var r = instruction == null ? null : method == null ? (object)instruction : new InstructionReference(method, instruction); writer.WriteReference(DnlibExtensions.OffsetToString(instruction.GetOffset()), r, tokenType); }
public SimpleType(TextTokenType tokenType, string identifier, TextLocation location) { SetChildByRole(Roles.Identifier, new Identifier (tokenType, identifier, location)); }
public TextToken(TextTokenType type, string value) { Value = value; Type = type; }
public void WriteDefinition(string text, object definition, TextTokenType tokenType, bool isLocal) { WriteIndent(); int start = this.TextLength; Append(tokenType, 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 WriteIdentifier(string ident, TextTokenType tokenType) { WriteIndentation(); textWriter.Write(ident); }
public void WriteReference(string text, object reference, TextTokenType tokenType, bool isLocal) { WriteIndent(); int start = this.TextLength; Append(tokenType, text); int end = this.TextLength; references.Add(new ReferenceSegment { StartOffset = start, EndOffset = end, Reference = reference, IsLocal = isLocal }); }
void Append(TextTokenType tokenType, string s) { tokens.Append(tokenType, s); b.Append(s); Debug.Assert(b.Length == tokens.Length); }
public override void WritePrimitiveValue(object value, TextTokenType? tokenType = null, string literalValue = null) { Expression node = nodes.Peek().LastOrDefault() as Expression; if (node is PrimitiveExpression) { ((PrimitiveExpression)node).SetStartLocation(locationProvider.Location); } if (node is NullReferenceExpression) { ((NullReferenceExpression)node).SetStartLocation(locationProvider.Location); } base.WritePrimitiveValue(value, tokenType, literalValue); }
public void Append(TextTokenType tokenType, string s) { 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(tokenType, 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(tokenType, s.Length - so); break; } } Debug.Assert(oldCurrentOffset + s.Length == currentOffset); }
public SimpleType(TextTokenType tokenType, string identifier) { this.IdentifierToken = Ast.Identifier.Create(tokenType, identifier); }
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 = TextTokenType.Last; isAppendingDefaultText = true; }
HighlightingColor GetColor(TextTokenType tokenType) { return(Themes.Theme.GetColor(tokenType).TextInheritedColor); }
public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType) { if (!identifier.IsNull) identifier.SetStartLocation(locationProvider.Location); currentList.Add(identifier); base.WriteIdentifier(identifier, tokenType); }
public override void WriteIdentifier(Identifier identifier, TextTokenType tokenType) { int startOffset = stringWriter.GetStringBuilder ().Length; int endOffset = startOffset + (identifier.Name ?? "").Length + (identifier.IsVerbatim ? 1 : 0); NewSegments.Add(new KeyValuePair<AstNode, Segment>(identifier, new Segment(startOffset, endOffset - startOffset))); base.WriteIdentifier (identifier, tokenType); }
HighlightingColor GetColor(TextTokenType tokenType) { var color = Themes.Theme.GetColor(tokenType).TextInheritedColor; Debug.Assert(color != null); return color; }
public override void WritePrimitiveValue(object value, TextTokenType? tokenType = null, string literalValue = null) { int column = 0; TextWriterTokenWriter.WritePrimitiveValue(value, tokenType, literalValue, ref column, (a, b) => output.Write(a, b), (a, b, c) => WriteToken(a, b, c)); }
public void Write(string s, TextTokenType tokenType) { if (needsNewLine) WriteNewLine(); output.Write(s, tokenType); }
public void WriteToken(string token, TextTokenType tokenType) { // 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, tokenType); else output.Write(token, tokenType); }
public override void WriteToken(Role role, string token, TextTokenType tokenType) { 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, tokenType); else output.Write(token, tokenType); }