![]() |
![]() |
![]() |
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 (MB *mb
,GError **error
); CtplToken * ctpl_lexer_lex_string (const gchar *template
,GError **error
); CtplToken * ctpl_lexer_lex_file (const gchar *filename
,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_file()
.
To dump a tree, use ctpl_lexer_dump_tree()
.
Example 9. Usage of 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) { fprintf (stderr, "Failed to analyse input data: %s\n", error->message); g_clear_error (&error); } else { // do anything you want with the tree here ctpl_lexer_free_tree (tree); } |
#define CTPL_START_CHAR '{'
Character delimiting start 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.
CtplToken * ctpl_lexer_lex (MB *mb
,GError **error
);
Analyses some given data and try to create a tree of tokens representing it.
|
A MB 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() whan no
longer needed.
|
CtplToken * ctpl_lexer_lex_string (const gchar *template
,GError **error
);
Lexes a template from a string.
See ctpl_lexer_lex()
.
CtplToken * ctpl_lexer_lex_file (const gchar *filename
,GError **error
);
Lexes a template from a file.
See ctpl_lexer_lex()
.
Errors can come from the G_FILE_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 |