| CTPL Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <ctpl/lexer.h> #define CTPL_START_CHAR #define CTPL_END_CHAR #define CTPL_LEXER_ERROR enum CtplLexerError; CtplToken * ctpl_lexer_lex (CtplInputStream *stream,GError **error); CtplToken * ctpl_lexer_lex_string (const gchar *template,GError **error); CtplToken * ctpl_lexer_lex_path (const gchar *path,GError **error); void ctpl_lexer_free_tree (CtplToken *root); void ctpl_lexer_dump_tree (const CtplToken *root);
Syntax analyser creating a token tree from an input data in the CTPL language.
To analyse some data, use ctpl_lexer_lex(), ctpl_lexer_lex_string() or
ctpl_lexer_lex_path(); to destroy the created token tree, use
ctpl_lexer_free_tree().
To dump a tree, use ctpl_lexer_dump_tree().
Example 8. Usage of the lexer and error management
1 2 3 4 5 6 7 8 9 10 11 12 |
CtplToken *tree; GError *error = NULL; tree = ctpl_lexer_lex (input, &error); if (tree == NULL) { fprintf (stderr, "Failed to analyse input data: %s\n", error->message); g_clear_error (&error); } else { /* do what you want with the tree here */ ctpl_lexer_free_tree (tree); } |
#define CTPL_START_CHAR '{'
Character delimiting the start of language tokens from raw data.
#define CTPL_END_CHAR '}'
Character delimiting the end of language tokens from raw data.
typedef enum _CtplLexerError
{
CTPL_LEXER_ERROR_SYNTAX_ERROR,
CTPL_LEXER_ERROR_FAILED
} CtplLexerError;
Error codes that lexing functions can throw, from the CTPL_LEXER_ERROR
domain.
CtplToken * ctpl_lexer_lex (CtplInputStream *stream,GError **error);
Analyses some given data and tries to create a tree of tokens representing it.
|
A CtplInputStream holding the data to analyse |
|
A GError return location for error reporting, or NULL to ignore
errors.
|
Returns : |
A new CtplToken tree holding all read tokens or NULL on error.
The new tree should be freed with ctpl_lexer_free_tree() when no
longer needed.
|
CtplToken * ctpl_lexer_lex_string (const gchar *template,GError **error);
Convenient function to lex a template from a string.
See ctpl_lexer_lex().
CtplToken * ctpl_lexer_lex_path (const gchar *path,GError **error);
Convenient function to lex a template from a file.
See ctpl_lexer_lex().
Errors can come from the G_IO_ERROR domain if the file loading fails, or
from the CTPL_LEXER_ERROR domain if the lexing fails.
void ctpl_lexer_free_tree (CtplToken *root);
Frees a whole CtplToken tree.
See ctpl_token_free().
|
A CtplToken from which start freeing |
void ctpl_lexer_dump_tree (const CtplToken *root);
Dumps a CtplToken tree as generated by the ctpl_lexer_lex().
See ctpl_token_dump().
|
A CtplToken from which start dump |