Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions for manipulating Token
s.
This module is intended to be imported qualified.
- tokenize :: ClangBase m => TranslationUnit s' -> SourceRange s'' -> ClangT s m (List s)
- type List s = Vector (Token s)
- getKind :: ClangBase m => Token s' -> ClangT s m TokenKind
- getSpelling :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (ClangString s)
- getLocation :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (SourceLocation s)
- getExtent :: ClangBase m => TranslationUnit s' -> Token s'' -> ClangT s m (SourceRange s)
- annotateTokens :: ClangBase m => TranslationUnit s' -> List s'' -> ClangT s m (CursorList s)
Token lists
:: 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.
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.
:: 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.