code cleaning done on 80 percent of the parser functions, whats left is to re structure the syntax struct and do furthure tests to eliminate level 0 errors
This commit is contained in:
148
srcs/lm_parser.c
148
srcs/lm_parser.c
@@ -6,97 +6,97 @@
|
||||
/* By: mndhlovu <mndhlovu@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/20 15:24:51 by mndhlovu #+# #+# */
|
||||
/* Updated: 2019/04/26 13:05:45 by mndhlovu ### ########.fr */
|
||||
/* Updated: 2019/04/29 12:45:25 by mndhlovu ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "lem_in.h"
|
||||
|
||||
void lm_locate_cd(int index, t_syntax *synt, char *line)
|
||||
static void lm_locate_cd(int index, t_syntax *synt, char *line)
|
||||
{
|
||||
char *tmp;
|
||||
char *tmp;
|
||||
|
||||
tmp = ft_strchr(line, '#');
|
||||
if ((!synt->s_cmd || !synt->e_cmd)
|
||||
tmp = ft_strchr(line, '#');
|
||||
if ((!synt->s_cmd || !synt->e_cmd)
|
||||
&& (tmp != NULL && line[1] == '#'
|
||||
&& lm_check_forbiden_chars(line, 1)))
|
||||
{
|
||||
if (!synt->s_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##start") == 0)
|
||||
{
|
||||
synt->s_cmd = 1;
|
||||
synt->s_pos = index;
|
||||
}
|
||||
}
|
||||
if (!synt->e_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##end") == 0)
|
||||
{
|
||||
synt->e_cmd = 1;
|
||||
synt->e_pos = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int lm_get_ant_(int counter, t_lmdata *ldata, t_syntax *synt, char *line)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
value = lm_get_value(line);
|
||||
if (value > 0)
|
||||
{
|
||||
ldata->nbants = value;
|
||||
synt->nb_state = 1;
|
||||
return (1);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int lm_get_vertices(int count, t_syntax *synt,
|
||||
t_lmdata *data, t_holder *holder, char *line)
|
||||
{
|
||||
lm_get_cmd_vert(count, synt, data, line);
|
||||
if (!synt->s_error && !synt->e_error)
|
||||
{
|
||||
lm_get_vert_link(count, synt, data, holder, line);
|
||||
if (!synt->v_error && !synt->l_error)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_parser(t_syntax *synt, t_lmdata *ldata,
|
||||
t_holder *holder)
|
||||
{
|
||||
char *raw;
|
||||
int index;
|
||||
|
||||
index = 0;
|
||||
while (ft_getline(&raw) > 0 && raw[0] != '\0')
|
||||
{
|
||||
ft_printf("%s\n", raw);
|
||||
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
||||
if (!synt->s_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##start") == 0)
|
||||
{
|
||||
synt->s_cmd = 1;
|
||||
synt->s_pos = index;
|
||||
}
|
||||
}
|
||||
if (!synt->e_cmd)
|
||||
{
|
||||
if (ft_strcmp(line, "##end") == 0)
|
||||
{
|
||||
synt->e_cmd = 1;
|
||||
synt->e_pos = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int lm_get_ant_(int counter, t_lmdata *ldata
|
||||
, t_syntax *synt, char *line)
|
||||
{
|
||||
int value;
|
||||
|
||||
if (counter == 0 && lm_check_forbiden_chars(line, 0))
|
||||
{
|
||||
value = lm_get_value(line);
|
||||
if (value > 0)
|
||||
{
|
||||
ldata->nbants = value;
|
||||
synt->nb_state = 1;
|
||||
return (1);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int lm_get_vertices(int count, t_syntax *synt
|
||||
, t_lmdata *data, t_holder *holder, char *line)
|
||||
{
|
||||
lm_get_cmd_vert(count, synt, data, line);
|
||||
if (!synt->s_error && !synt->e_error)
|
||||
{
|
||||
lm_get_vert_link(count, synt, data, holder, line);
|
||||
if (!synt->v_error && !synt->l_error)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int lm_parser(t_syntax *synt
|
||||
, t_lmdata *ldata, t_holder *holder)
|
||||
{
|
||||
char *raw;
|
||||
int index;
|
||||
|
||||
index = 0;
|
||||
while (ft_getline(&raw) > 0 && raw[0] != '\0')
|
||||
{
|
||||
if ((add_line_map(ldata, raw)))
|
||||
return (0);
|
||||
if (!(lm_get_ant_(index, ldata, synt, raw)) && index == 0)
|
||||
{
|
||||
//ft_strdel(&raw);
|
||||
return (0);
|
||||
return (0);
|
||||
}
|
||||
lm_locate_cd(index, synt, raw);
|
||||
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
||||
lm_locate_cd(index, synt, raw);
|
||||
if (!(lm_get_vertices(index, synt, ldata, holder, raw)))
|
||||
{
|
||||
ft_strdel(&raw);
|
||||
return (0);
|
||||
}
|
||||
ft_strdel(&raw);
|
||||
index++;
|
||||
}
|
||||
ft_printf("final raw: %s\n", raw);
|
||||
index++;
|
||||
}
|
||||
ft_strdel(&raw);
|
||||
ft_putchar('\n');
|
||||
return (1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user