diff options
Diffstat (limited to 'src/parser/parsed_error.c')
| -rw-r--r-- | src/parser/parsed_error.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/parser/parsed_error.c b/src/parser/parsed_error.c new file mode 100644 index 0000000..a38a85c --- /dev/null +++ b/src/parser/parsed_error.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parsed_error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/10/10 09:20:17 by cacharle #+# #+# */ +/* Updated: 2020/10/10 09:20:30 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +t_parsed *parsed_error(const char *format, ...) +{ + t_parsed *err; + va_list ap; + + if ((err = parsed_new(NULL, NULL)) == NULL) + return (NULL); + err->syntax_error = true; + va_start(ap, format); + verrorf(format, ap); + va_end(ap); + ft_putchar_fd('\n', STDERR_FILENO); + return (err); +} + +t_parsed *parsed_expected(void) +{ + return (parsed_error("syntax error expected token")); +} + +t_parsed *parsed_unexpected(char *content) +{ + return (parsed_error("syntax error near unexpected token `%s'", content)); +} + +bool parsed_err(t_parsed *parsed) +{ + return (parsed == NULL || parsed->syntax_error); +} |
