Exemplo n.º 1
0
        private void ScanTokens(NClang.ClangTranslationUnit tu, SyntaxHighlightDataList result)
        {
            var tokens = tu.Tokenize(tu.GetCursor().CursorExtent);

            //var annotatedTokens = tokens.Annotate();           //TODO see if this can provide us with additional data.

            foreach (var token in tokens.Tokens)
            {
                var highlightData = new OffsetSyntaxHighlightingData();
                highlightData.Start  = token.Extent.Start.FileLocation.Offset;
                highlightData.Length = token.Extent.End.FileLocation.Offset - highlightData.Start;


                switch (token.Kind)
                {
                case TokenKind.Comment:
                    highlightData.Type = HighlightType.Comment;
                    result.Add(highlightData);
                    break;

                case TokenKind.Keyword:
                    highlightData.Type = HighlightType.Keyword;
                    result.Add(highlightData);
                    break;
                }
            }
        }
        private void ScanTokens(NClang.ClangTranslationUnit tu, SyntaxHighlightDataList result)
        {
            var tokens = tu.Tokenize(tu.GetCursor().CursorExtent);

            foreach (var token in tokens.Tokens)
            {
                var highlightData = new OffsetSyntaxHighlightingData
                {
                    Start = token.Extent.Start.FileLocation.Offset
                };

                highlightData.Length = token.Extent.End.FileLocation.Offset - highlightData.Start;

                switch (token.Kind)
                {
                case TokenKind.Comment:
                    highlightData.Type = HighlightType.Comment;
                    result.Add(highlightData);
                    break;

                case TokenKind.Keyword:
                    highlightData.Type = HighlightType.Keyword;
                    result.Add(highlightData);
                    break;
                }
            }
        }