Extend parse_token to accept an optional validator function
This commit is contained in:
parent
fcbf96af48
commit
f4638d43b6
@ -16,8 +16,10 @@ parse_result_t parse_success(ast_node_t *ast, tokenlist_entry_t *next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parse_result_t parse_token(tokenlist_entry_t *current,
|
parse_result_t parse_token(tokenlist_entry_t *current,
|
||||||
lexer_token_id_t token_id, node_id_t ast_id) {
|
lexer_token_id_t token_id, node_id_t ast_id,
|
||||||
if (current->token.id != token_id)
|
token_validator_t is_valid) {
|
||||||
|
if (current->token.id != token_id ||
|
||||||
|
(is_valid && !is_valid(¤t->token)))
|
||||||
return parse_no_match();
|
return parse_no_match();
|
||||||
|
|
||||||
ast_node_t *node;
|
ast_node_t *node;
|
||||||
|
@ -11,11 +11,14 @@ typedef struct parse_result {
|
|||||||
ast_node_t *node;
|
ast_node_t *node;
|
||||||
} parse_result_t;
|
} parse_result_t;
|
||||||
|
|
||||||
|
typedef bool (*token_validator_t)(lexer_token_t *);
|
||||||
|
|
||||||
parse_result_t parse_error(error_t *err);
|
parse_result_t parse_error(error_t *err);
|
||||||
parse_result_t parse_no_match();
|
parse_result_t parse_no_match();
|
||||||
parse_result_t parse_success(ast_node_t *ast, tokenlist_entry_t *next);
|
parse_result_t parse_success(ast_node_t *ast, tokenlist_entry_t *next);
|
||||||
parse_result_t parse_token(tokenlist_entry_t *current,
|
parse_result_t parse_token(tokenlist_entry_t *current,
|
||||||
lexer_token_id_t token_id, node_id_t ast_id);
|
lexer_token_id_t token_id, node_id_t ast_id,
|
||||||
|
token_validator_t is_valid);
|
||||||
|
|
||||||
tokenlist_entry_t *skip_insignificant(tokenlist_entry_t *);
|
tokenlist_entry_t *skip_insignificant(tokenlist_entry_t *);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user