lang: replace stack-based parser with a recursive parser
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include "ctx.h"
|
||||
|
||||
bool parse_string(struct ivy_parser *parser, struct ivy_token **out)
|
||||
{
|
||||
struct ivy_token *tok = peek_token(parser);
|
||||
if (!tok || tok->t_type != IVY_TOK_STRING) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*out = parse_token(parser);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_str_start(struct ivy_parser *parser)
|
||||
{
|
||||
struct ivy_token *tok = peek_token(parser);
|
||||
if (tok->t_type != IVY_TOK_STR_START) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parse_token(parser);
|
||||
ivy_token_destroy(tok);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_str_end(struct ivy_parser *parser)
|
||||
{
|
||||
struct ivy_token *tok = peek_token(parser);
|
||||
if (tok->t_type != IVY_TOK_STR_END) {
|
||||
return false;
|
||||
}
|
||||
|
||||
parse_token(parser);
|
||||
ivy_token_destroy(tok);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user