first).
*/
+#include <stdio.h>
+
static void mem_free (void **);
/*
if (status == mr_matched)
{
- if (sp->m_emits != NULL)
- if (emit_push (sp->m_emits, _BP->_F + _P, text[ind - 1], save_ind, &ctx))
+ if (sp->m_emits != NULL) {
+ const byte ch = (ind <= 0) ? 0 : text[ind - 1];
+ if (emit_push (sp->m_emits, _BP->_F + _P, ch, save_ind, &ctx))
{
free_regbyte_ctx_stack (ctx, *rbc);
return mr_internal_error;
}
- _P = _P2;
+ }
+ _P = _P2;
}
/* if the rule operator is a logical or, we pick up the first matching specifier */
}
}
+
+static void error_msg(int line, const char *msg)
+{
+ fprintf(stderr, "Error in grammar_load_from_text() at line %d: %s\n", line, msg);
+}
+
+
/*
the API
*/
-
grammar grammar_load_from_text (const byte *text)
{
grammar_load_state *g = NULL;
clear_last_error ();
grammar_load_state_create (&g);
- if (g == NULL)
+ if (g == NULL) {
+ error_msg(__LINE__, "");
return 0;
+ }
dict_create (&g->di);
if (g->di == NULL)
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (get_identifier (&text, &g->syntax_symbol))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
eat_spaces (&text);
if (get_identifier (&text, &symbol))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
eat_spaces (&text);
if (get_emtcode (&text, &ma))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (get_regbyte (&text, &ma))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (get_errtext (&text, &ma))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (g->di->m_string != NULL)
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (get_identifier (&text, &g->string_symbol))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (get_rule (&text, &ru, g->maps, g->mapb))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
if (ma == NULL)
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "");
return 0;
}
g->di->m_regbytes))
{
grammar_load_state_destroy (&g);
+ error_msg(__LINE__, "update_dependencies() failed");
return 0;
}