Run ToRun(string text, SyntaxTokenClassification classification, IClassificationFormatMap formatMap) {
            var run = new Run(text);

            IClassificationType ct;
            _classificationMap.TryGetValue(classification, out ct);
            if (ct != null) {
                var props = formatMap.GetTextProperties(ct);
                run.SetTextProperties(props);
            }

            return run;
        }
        public TextBlock ToTextBlock(string text, SyntaxTokenClassification classification) {

            var textBlock = new TextBlock { TextWrapping = TextWrapping.Wrap };

            var formatMap = _classificationFormatMapService.GetClassificationFormatMap("tooltip");
            textBlock.SetDefaultTextProperties(formatMap);

            var run = ToRun(text, classification, formatMap);

            textBlock.Inlines.Add(run);

            return textBlock;
        }
        public static SyntaxToken CreateToken(IToken t, SyntaxTokenClassification classification, SyntaxNode parent) {

            SyntaxTokenType type = (SyntaxTokenType)t.Type;
            
            var extend=TextExtentFactory.CreateExtent(t);
            if (extend.IsMissing) {
                return SyntaxToken.Missing;
            }
            
            var token = new SyntaxToken(parent, type, classification, extend);

            return token;
        }       
 public SyntaxToken PreviousToken(SyntaxTokenClassification tokenClassification) {
     return SyntaxTree?.Tokens.NextOrPrevious(Parent, this, tokenClassification, nextToken: false) ?? Missing;
 }
        internal SyntaxToken(SyntaxNode parent, SyntaxTokenType type, SyntaxTokenClassification classification, TextExtent extent) {
            _extent  = extent;
            _parent  = parent;

            _classificationAndType = ((int)type << TypeBitShift) | ((int)classification << ClassificationBitShift);
        }
 public static IEnumerable<SyntaxToken> OfClassification(this IEnumerable<SyntaxToken> source, SyntaxTokenClassification classification) {
     return source.Where(t => t.Classification == classification);
 }
 public static SyntaxToken LastOrDefault(this IEnumerable<SyntaxToken> source, SyntaxTokenClassification classification) {
     return source.LastOrDefault(t => t.Classification == classification);
 }
 public static SyntaxToken FirstOrMissing(this IEnumerable<SyntaxToken> source, SyntaxTokenClassification classification) {
     return source.Where(t => t.Classification == classification).DefaultIfEmpty(SyntaxToken.Missing).First();
 }
 public static SyntaxToken CreateToken(ITerminalNode node, SyntaxTokenClassification classification, SyntaxNode parent) {
     return CreateToken(node.Symbol, classification, parent);
 }