LibClang-3.4.0: Haskell bindings for libclang (a C++ parsing library)

Safe HaskellNone
LanguageHaskell2010

Clang.Token

Contents

Description

Functions for manipulating Tokens.

This module is intended to be imported qualified.

Synopsis

Token lists

tokenize Source

Arguments

:: ClangBase m 
=> TranslationUnit s'

The translation list containing the source code.

-> SourceRange s''

The source range in which text should be tokenized.

-> ClangT s m (List s) 

Tokenizes the source code described by the given range into raw lexical tokens.

type List s = Vector (Token s) Source

A list of tokens, stored as a Vector for efficiency.

Token kinds

getKind :: ClangBase m => Token s' -> ClangT s m TokenKind Source

Determines the kind of the given token, expressed as a TokenKind value.

Mapping between tokens and source code

getSpelling :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (ClangString s) Source

Retrieves the 'spelling', or textual representation, of the given token.

getLocation :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (SourceLocation s) Source

Returns the source location of the given token.

getExtent :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (SourceRange s) Source

Retrieves the source range that covers the given token.

annotateTokens Source

Arguments

:: ClangBase m 
=> TranslationUnit s'

The translation unit that owns the tokens.

-> List s''

The tokens to annotate.

-> ClangT s m (CursorList s) 

Annotates the given set of tokens by providing cursors for each token that can be mapped to a specific entity within the abstract syntax tree.

This is equivalent to invoking getCursor on the source locations of each of these tokens. The cursors provided are filtered, so that only those cursors that have a direct correspondence to the token are accepted. For example, given a function call 'f(x)', getCursor would provide the following cursors:

  • When the cursor is over the 'f', a DeclRefExpr cursor referring to 'f'.
  • When the cursor is over the '(' or the ')', a CallExpr referring to 'f'.
  • When the cursor is over the 'x', a DeclRefExpr cursor referring to 'x'.

Only the first and last of these cursors will occur within the annotate, since the tokens 'f' and 'x' directly refer to a function and a variable, respectively, but the parentheses are just a small part of the full syntax of the function call expression, which is not provided as an annotation.