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