The deterministic recursive descent parser.
More...
#include "detail.h"
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
Go to the source code of this file.
|
|
#define | RDESC_VERSION_MAJOR 0 |
| | Major version.
|
| |
|
#define | RDESC_VERSION_MINOR 2 |
| | Minor version.
|
| |
|
#define | RDESC_VERSION_PATCH 0 |
| | Patch version.
|
| |
|
#define | RDESC_VERSION_PRE_RELEASE "rc.2" |
| | Prerelease identifier.
|
| |
|
|
const char * | rdesc_version (void) |
| | rdesc version
|
| |
| int | rdesc_init (struct rdesc *parser, const struct rdesc_grammar *grammar, size_t seminfo_size, void(*token_destroyer)(uint16_t id, void *seminfo)) _rdesc_wur |
| | Initializes a new parser.
|
| |
|
void | rdesc_destroy (struct rdesc *parser) |
| | Frees memory allocated by the parser and destroys the parser instance.
|
| |
| int | rdesc_start (struct rdesc *parser, uint16_t start_symbol) _rdesc_wur |
| | Sets start symbol for the next match.
|
| |
|
void | rdesc_reset (struct rdesc *parser) |
| | Resets the parser to its initial state.
|
| |
| enum rdesc_result | rdesc_pump (struct rdesc *parser, uint16_t id, void *seminfo) _rdesc_wur |
| | Drives the parsing process, the pump.
|
| |
| enum rdesc_result | rdesc_resume (struct rdesc *parser) _rdesc_wur |
| | Resume parsing without providing a new token.
|
| |
| struct rdesc_node * | rdesc_root (struct rdesc *parser) |
| | Returns the root of the CST.
|
| |
The deterministic recursive descent parser.
◆ rdesc_result
Parse operation result codes.
| Enumerator |
|---|
| RDESC_ENOMEM | Memory allocation failed.
|
| RDESC_READY | A CST is ready for consumption.
|
| RDESC_CONTINUE | New tokens should be provided.
|
| RDESC_NOMATCH | No grammar rule matches the provided tokens.
|
◆ rdesc_init()
| int rdesc_init |
( |
struct rdesc * |
parser, |
|
|
const struct rdesc_grammar * |
grammar, |
|
|
size_t |
seminfo_size, |
|
|
void(*)(uint16_t id, void *seminfo) |
token_destroyer |
|
) |
| |
Initializes a new parser.
- Parameters
-
| parser | Parser instance to initialize. |
| grammar | Grammar defining production rules (must outlive parser). |
| seminfo_size | Size in bytes of token semantic information. |
| token_destroyer | Optional callback to free token seminfo (can be NULL). |
- Returns
- Non-zero value if memory allocation fails.
◆ rdesc_pump()
Drives the parsing process, the pump.
As the central engine of the parser, it consumes tokens from either the internal backtracking stack or the provided id.
- Parameters
-
| parser | Pointer to the parser instance. |
| id | Identifier of the next token to consume. |
| seminfo | Extra semantic information for the token.
- Semantic information pointer. The parser copies this data internally, so passing a pointer to stack-allocated data is valid. NULL is acceptable.
|
- Returns
- The current status of the parse operation.
- Warning
- Raises an error if the parser is not started.
◆ rdesc_resume()
Resume parsing without providing a new token.
Resumes using either:
- The saved token from a previous ENOMEM error, or
- A token from the backtrack stack
◆ rdesc_root()
| struct rdesc_node * rdesc_root |
( |
struct rdesc * |
parser | ) |
|
Returns the root of the CST.
- Note
- Returns NULL if no CST has been created yet.
◆ rdesc_start()
| int rdesc_start |
( |
struct rdesc * |
parser, |
|
|
uint16_t |
start_symbol |
|
) |
| |
Sets start symbol for the next match.
- Returns
- Non-zero value if memory allocation fails.