Rizin
unix-like reverse engineering framework and cli tools
mpc.c File Reference
#include "mpc.h"

Go to the source code of this file.

Classes

struct  mpc_mem_t
 
struct  mpc_input_t
 
struct  mpc_pdata_fail_t
 
struct  mpc_pdata_lift_t
 
struct  mpc_pdata_expect_t
 
struct  mpc_pdata_anchor_t
 
struct  mpc_pdata_single_t
 
struct  mpc_pdata_range_t
 
struct  mpc_pdata_satisfy_t
 
struct  mpc_pdata_string_t
 
struct  mpc_pdata_apply_t
 
struct  mpc_pdata_apply_to_t
 
struct  mpc_pdata_check_t
 
struct  mpc_pdata_check_with_t
 
struct  mpc_pdata_predict_t
 
struct  mpc_pdata_not_t
 
struct  mpc_pdata_repeat_t
 
struct  mpc_pdata_or_t
 
struct  mpc_pdata_and_t
 
union  mpc_pdata_t
 
struct  mpc_parser_t
 
struct  mpca_grammar_st_t
 
struct  mpca_stmt_t
 

Macros

#define MPC_SUCCESS(x)   r->output = x; return 1
 
#define MPC_FAILURE(x)   r->error = x; return 0
 
#define MPC_PRIMITIVE(x)
 
#define MPC_MAX_RECURSION_DEPTH   1000
 

Enumerations

enum  { MPC_INPUT_STRING = 0 , MPC_INPUT_FILE = 1 , MPC_INPUT_PIPE = 2 }
 
enum  { MPC_INPUT_MARKS_MIN = 32 }
 
enum  { MPC_INPUT_MEM_NUM = 512 }
 
enum  {
  MPC_TYPE_UNDEFINED = 0 , MPC_TYPE_PASS = 1 , MPC_TYPE_FAIL = 2 , MPC_TYPE_LIFT = 3 ,
  MPC_TYPE_LIFT_VAL = 4 , MPC_TYPE_EXPECT = 5 , MPC_TYPE_ANCHOR = 6 , MPC_TYPE_STATE = 7 ,
  MPC_TYPE_ANY = 8 , MPC_TYPE_SINGLE = 9 , MPC_TYPE_ONEOF = 10 , MPC_TYPE_NONEOF = 11 ,
  MPC_TYPE_RANGE = 12 , MPC_TYPE_SATISFY = 13 , MPC_TYPE_STRING = 14 , MPC_TYPE_APPLY = 15 ,
  MPC_TYPE_APPLY_TO = 16 , MPC_TYPE_PREDICT = 17 , MPC_TYPE_NOT = 18 , MPC_TYPE_MAYBE = 19 ,
  MPC_TYPE_MANY = 20 , MPC_TYPE_MANY1 = 21 , MPC_TYPE_COUNT = 22 , MPC_TYPE_OR = 23 ,
  MPC_TYPE_AND = 24 , MPC_TYPE_CHECK = 25 , MPC_TYPE_CHECK_WITH = 26 , MPC_TYPE_SOI = 27 ,
  MPC_TYPE_EOI = 28
}
 
enum  { MPC_PARSE_STACK_MIN = 4 }
 

Functions

static mpc_state_t mpc_state_invalid (void)
 
static mpc_state_t mpc_state_new (void)
 
static mpc_input_tmpc_input_new_string (const char *filename, const char *string)
 
static mpc_input_tmpc_input_new_nstring (const char *filename, const char *string, size_t length)
 
static mpc_input_tmpc_input_new_pipe (const char *filename, FILE *pipe)
 
static mpc_input_tmpc_input_new_file (const char *filename, FILE *file)
 
static void mpc_input_delete (mpc_input_t *i)
 
static int mpc_mem_ptr (mpc_input_t *i, void *p)
 
static void * mpc_malloc (mpc_input_t *i, size_t n)
 
static void * mpc_calloc (mpc_input_t *i, size_t n, size_t m)
 
static void mpc_free (mpc_input_t *i, void *p)
 
static void * mpc_realloc (mpc_input_t *i, void *p, size_t n)
 
static void * mpc_export (mpc_input_t *i, void *p)
 
static void mpc_input_backtrack_disable (mpc_input_t *i)
 
static void mpc_input_backtrack_enable (mpc_input_t *i)
 
static void mpc_input_suppress_disable (mpc_input_t *i)
 
static void mpc_input_suppress_enable (mpc_input_t *i)
 
static void mpc_input_mark (mpc_input_t *i)
 
static void mpc_input_unmark (mpc_input_t *i)
 
static void mpc_input_rewind (mpc_input_t *i)
 
static int mpc_input_buffer_in_range (mpc_input_t *i)
 
static char mpc_input_buffer_get (mpc_input_t *i)
 
static char mpc_input_getc (mpc_input_t *i)
 
static char mpc_input_peekc (mpc_input_t *i)
 
static int mpc_input_terminated (mpc_input_t *i)
 
static int mpc_input_failure (mpc_input_t *i, char c)
 
static int mpc_input_success (mpc_input_t *i, char c, char **o)
 
static int mpc_input_any (mpc_input_t *i, char **o)
 
static int mpc_input_char (mpc_input_t *i, char c, char **o)
 
static int mpc_input_range (mpc_input_t *i, char c, char d, char **o)
 
static int mpc_input_oneof (mpc_input_t *i, const char *c, char **o)
 
static int mpc_input_noneof (mpc_input_t *i, const char *c, char **o)
 
static int mpc_input_satisfy (mpc_input_t *i, int(*cond)(char), char **o)
 
static int mpc_input_string (mpc_input_t *i, const char *c, char **o)
 
static int mpc_input_anchor (mpc_input_t *i, int(*f)(char, char), char **o)
 
static int mpc_input_soi (mpc_input_t *i, char **o)
 
static int mpc_input_eoi (mpc_input_t *i, char **o)
 
static mpc_state_tmpc_input_state_copy (mpc_input_t *i)
 
void mpc_err_delete (mpc_err_t *x)
 
void mpc_err_print (mpc_err_t *x)
 
void mpc_err_print_to (mpc_err_t *x, FILE *f)
 
static void mpc_err_string_cat (char *buffer, int *pos, int *max, char const *fmt,...)
 
static const char * mpc_err_char_unescape (char c)
 
char * mpc_err_string (mpc_err_t *x)
 
static mpc_err_tmpc_err_new (mpc_input_t *i, const char *expected)
 
static mpc_err_tmpc_err_fail (mpc_input_t *i, const char *failure)
 
static mpc_err_tmpc_err_file (const char *filename, const char *failure)
 
static void mpc_err_delete_internal (mpc_input_t *i, mpc_err_t *x)
 
static mpc_err_tmpc_err_export (mpc_input_t *i, mpc_err_t *x)
 
static int mpc_err_contains_expected (mpc_input_t *i, mpc_err_t *x, char *expected)
 
static void mpc_err_add_expected (mpc_input_t *i, mpc_err_t *x, char *expected)
 
static mpc_err_tmpc_err_or (mpc_input_t *i, mpc_err_t **x, int n)
 
static mpc_err_tmpc_err_repeat (mpc_input_t *i, mpc_err_t *x, const char *prefix)
 
static mpc_err_tmpc_err_many1 (mpc_input_t *i, mpc_err_t *x)
 
static mpc_err_tmpc_err_count (mpc_input_t *i, mpc_err_t *x, int n)
 
static mpc_err_tmpc_err_merge (mpc_input_t *i, mpc_err_t *x, mpc_err_t *y)
 
static mpc_val_tmpcf_input_nth_free (mpc_input_t *i, int n, mpc_val_t **xs, int x)
 
static mpc_val_tmpcf_input_fst_free (mpc_input_t *i, int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_input_snd_free (mpc_input_t *i, int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_input_trd_free (mpc_input_t *i, int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_input_strfold (mpc_input_t *i, int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_input_state_ast (mpc_input_t *i, int n, mpc_val_t **xs)
 
static mpc_val_tmpc_parse_fold (mpc_input_t *i, mpc_fold_t f, int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_input_free (mpc_input_t *i, mpc_val_t *x)
 
static mpc_val_tmpcf_input_str_ast (mpc_input_t *i, mpc_val_t *c)
 
static mpc_val_tmpc_parse_apply (mpc_input_t *i, mpc_apply_t f, mpc_val_t *x)
 
static mpc_val_tmpc_parse_apply_to (mpc_input_t *i, mpc_apply_to_t f, mpc_val_t *x, mpc_val_t *d)
 
static void mpc_parse_dtor (mpc_input_t *i, mpc_dtor_t d, mpc_val_t *x)
 
static int mpc_parse_run (mpc_input_t *i, mpc_parser_t *p, mpc_result_t *r, mpc_err_t **e, int depth)
 
int mpc_parse_input (mpc_input_t *i, mpc_parser_t *p, mpc_result_t *r)
 
int mpc_parse (const char *filename, const char *string, mpc_parser_t *p, mpc_result_t *r)
 
int mpc_nparse (const char *filename, const char *string, size_t length, mpc_parser_t *p, mpc_result_t *r)
 
int mpc_parse_file (const char *filename, FILE *file, mpc_parser_t *p, mpc_result_t *r)
 
int mpc_parse_pipe (const char *filename, FILE *pipe, mpc_parser_t *p, mpc_result_t *r)
 
int mpc_parse_contents (const char *filename, mpc_parser_t *p, mpc_result_t *r)
 
static void mpc_undefine_unretained (mpc_parser_t *p, int force)
 
static void mpc_undefine_or (mpc_parser_t *p)
 
static void mpc_undefine_and (mpc_parser_t *p)
 
void mpc_delete (mpc_parser_t *p)
 
static void mpc_soft_delete (mpc_val_t *x)
 
static mpc_parser_tmpc_undefined (void)
 
mpc_parser_tmpc_new (const char *name)
 
mpc_parser_tmpc_copy (mpc_parser_t *a)
 
mpc_parser_tmpc_undefine (mpc_parser_t *p)
 
mpc_parser_tmpc_define (mpc_parser_t *p, mpc_parser_t *a)
 
void mpc_cleanup (int n,...)
 
mpc_parser_tmpc_pass (void)
 
mpc_parser_tmpc_fail (const char *m)
 
mpc_parser_tmpc_failf (const char *fmt,...)
 
mpc_parser_tmpc_lift_val (mpc_val_t *x)
 
mpc_parser_tmpc_lift (mpc_ctor_t lf)
 
mpc_parser_tmpc_anchor (int(*f)(char, char))
 
mpc_parser_tmpc_state (void)
 
mpc_parser_tmpc_expect (mpc_parser_t *a, const char *expected)
 
mpc_parser_tmpc_expectf (mpc_parser_t *a, const char *fmt,...)
 
mpc_parser_tmpc_any (void)
 
mpc_parser_tmpc_char (char c)
 
mpc_parser_tmpc_range (char s, char e)
 
mpc_parser_tmpc_oneof (const char *s)
 
mpc_parser_tmpc_noneof (const char *s)
 
mpc_parser_tmpc_satisfy (int(*f)(char))
 
mpc_parser_tmpc_string (const char *s)
 
mpc_parser_tmpc_apply (mpc_parser_t *a, mpc_apply_t f)
 
mpc_parser_tmpc_apply_to (mpc_parser_t *a, mpc_apply_to_t f, void *x)
 
mpc_parser_tmpc_check (mpc_parser_t *a, mpc_dtor_t da, mpc_check_t f, const char *e)
 
mpc_parser_tmpc_check_with (mpc_parser_t *a, mpc_dtor_t da, mpc_check_with_t f, void *x, const char *e)
 
mpc_parser_tmpc_checkf (mpc_parser_t *a, mpc_dtor_t da, mpc_check_t f, const char *fmt,...)
 
mpc_parser_tmpc_check_withf (mpc_parser_t *a, mpc_dtor_t da, mpc_check_with_t f, void *x, const char *fmt,...)
 
mpc_parser_tmpc_predictive (mpc_parser_t *a)
 
mpc_parser_tmpc_not_lift (mpc_parser_t *a, mpc_dtor_t da, mpc_ctor_t lf)
 
mpc_parser_tmpc_not (mpc_parser_t *a, mpc_dtor_t da)
 
mpc_parser_tmpc_maybe_lift (mpc_parser_t *a, mpc_ctor_t lf)
 
mpc_parser_tmpc_maybe (mpc_parser_t *a)
 
mpc_parser_tmpc_many (mpc_fold_t f, mpc_parser_t *a)
 
mpc_parser_tmpc_many1 (mpc_fold_t f, mpc_parser_t *a)
 
mpc_parser_tmpc_count (int n, mpc_fold_t f, mpc_parser_t *a, mpc_dtor_t da)
 
mpc_parser_tmpc_or (int n,...)
 
mpc_parser_tmpc_and (int n, mpc_fold_t f,...)
 
mpc_parser_tmpc_soi (void)
 
mpc_parser_tmpc_eoi (void)
 
static int mpc_boundary_anchor (char prev, char next)
 
static int mpc_boundary_newline_anchor (char prev, char next)
 
mpc_parser_tmpc_boundary (void)
 
mpc_parser_tmpc_boundary_newline (void)
 
mpc_parser_tmpc_whitespace (void)
 
mpc_parser_tmpc_whitespaces (void)
 
mpc_parser_tmpc_blank (void)
 
mpc_parser_tmpc_newline (void)
 
mpc_parser_tmpc_tab (void)
 
mpc_parser_tmpc_escape (void)
 
mpc_parser_tmpc_digit (void)
 
mpc_parser_tmpc_hexdigit (void)
 
mpc_parser_tmpc_octdigit (void)
 
mpc_parser_tmpc_digits (void)
 
mpc_parser_tmpc_hexdigits (void)
 
mpc_parser_tmpc_octdigits (void)
 
mpc_parser_tmpc_lower (void)
 
mpc_parser_tmpc_upper (void)
 
mpc_parser_tmpc_alpha (void)
 
mpc_parser_tmpc_underscore (void)
 
mpc_parser_tmpc_alphanum (void)
 
mpc_parser_tmpc_int (void)
 
mpc_parser_tmpc_hex (void)
 
mpc_parser_tmpc_oct (void)
 
mpc_parser_tmpc_number (void)
 
mpc_parser_tmpc_real (void)
 
mpc_parser_tmpc_float (void)
 
mpc_parser_tmpc_char_lit (void)
 
mpc_parser_tmpc_string_lit (void)
 
mpc_parser_tmpc_regex_lit (void)
 
mpc_parser_tmpc_ident (void)
 
mpc_parser_tmpc_startwith (mpc_parser_t *a)
 
mpc_parser_tmpc_endwith (mpc_parser_t *a, mpc_dtor_t da)
 
mpc_parser_tmpc_whole (mpc_parser_t *a, mpc_dtor_t da)
 
mpc_parser_tmpc_stripl (mpc_parser_t *a)
 
mpc_parser_tmpc_stripr (mpc_parser_t *a)
 
mpc_parser_tmpc_strip (mpc_parser_t *a)
 
mpc_parser_tmpc_tok (mpc_parser_t *a)
 
mpc_parser_tmpc_sym (const char *s)
 
mpc_parser_tmpc_total (mpc_parser_t *a, mpc_dtor_t da)
 
mpc_parser_tmpc_between (mpc_parser_t *a, mpc_dtor_t ad, const char *o, const char *c)
 
mpc_parser_tmpc_parens (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_braces (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_brackets (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_squares (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_tok_between (mpc_parser_t *a, mpc_dtor_t ad, const char *o, const char *c)
 
mpc_parser_tmpc_tok_parens (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_tok_braces (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_tok_brackets (mpc_parser_t *a, mpc_dtor_t ad)
 
mpc_parser_tmpc_tok_squares (mpc_parser_t *a, mpc_dtor_t ad)
 
static mpc_val_tmpcf_re_or (int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_re_and (int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_re_repeat (int n, mpc_val_t **xs)
 
static mpc_parser_tmpc_re_escape_char (char c)
 
static mpc_val_tmpcf_re_escape (mpc_val_t *x, void *data)
 
static const char * mpc_re_range_escape_char (char c)
 
static mpc_val_tmpcf_re_range (mpc_val_t *x)
 
mpc_parser_tmpc_re (const char *re)
 
mpc_parser_tmpc_re_mode (const char *re, int mode)
 
void mpcf_dtor_null (mpc_val_t *x)
 
mpc_val_tmpcf_ctor_null (void)
 
mpc_val_tmpcf_ctor_str (void)
 
mpc_val_tmpcf_free (mpc_val_t *x)
 
mpc_val_tmpcf_int (mpc_val_t *x)
 
mpc_val_tmpcf_hex (mpc_val_t *x)
 
mpc_val_tmpcf_oct (mpc_val_t *x)
 
mpc_val_tmpcf_float (mpc_val_t *x)
 
mpc_val_tmpcf_strtriml (mpc_val_t *x)
 
mpc_val_tmpcf_strtrimr (mpc_val_t *x)
 
mpc_val_tmpcf_strtrim (mpc_val_t *x)
 
static mpc_val_tmpcf_escape_new (mpc_val_t *x, const char *input, const char **output)
 
static mpc_val_tmpcf_unescape_new (mpc_val_t *x, const char *input, const char **output)
 
mpc_val_tmpcf_escape (mpc_val_t *x)
 
mpc_val_tmpcf_unescape (mpc_val_t *x)
 
mpc_val_tmpcf_escape_regex (mpc_val_t *x)
 
mpc_val_tmpcf_unescape_regex (mpc_val_t *x)
 
mpc_val_tmpcf_escape_string_raw (mpc_val_t *x)
 
mpc_val_tmpcf_unescape_string_raw (mpc_val_t *x)
 
mpc_val_tmpcf_escape_char_raw (mpc_val_t *x)
 
mpc_val_tmpcf_unescape_char_raw (mpc_val_t *x)
 
mpc_val_tmpcf_null (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_fst (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_snd (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_trd (int n, mpc_val_t **xs)
 
static mpc_val_tmpcf_nth_free (int n, mpc_val_t **xs, int x)
 
mpc_val_tmpcf_fst_free (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_snd_free (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_trd_free (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_all_free (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_strfold (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_maths (int n, mpc_val_t **xs)
 
static void mpc_print_unretained (mpc_parser_t *p, int force)
 
void mpc_print (mpc_parser_t *p)
 
int mpc_test_fail (mpc_parser_t *p, const char *s, const void *d, int(*tester)(const void *, const void *), mpc_dtor_t destructor, void(*printer)(const void *))
 
int mpc_test_pass (mpc_parser_t *p, const char *s, const void *d, int(*tester)(const void *, const void *), mpc_dtor_t destructor, void(*printer)(const void *))
 
void mpc_ast_delete (mpc_ast_t *a)
 
static void mpc_ast_delete_no_children (mpc_ast_t *a)
 
mpc_ast_tmpc_ast_new (const char *tag, const char *contents)
 
mpc_ast_tmpc_ast_build (int n, const char *tag,...)
 
mpc_ast_tmpc_ast_add_root (mpc_ast_t *a)
 
int mpc_ast_eq (mpc_ast_t *a, mpc_ast_t *b)
 
mpc_ast_tmpc_ast_add_child (mpc_ast_t *r, mpc_ast_t *a)
 
mpc_ast_tmpc_ast_add_tag (mpc_ast_t *a, const char *t)
 
mpc_ast_tmpc_ast_add_root_tag (mpc_ast_t *a, const char *t)
 
mpc_ast_tmpc_ast_tag (mpc_ast_t *a, const char *t)
 
mpc_ast_tmpc_ast_state (mpc_ast_t *a, mpc_state_t s)
 
static void mpc_ast_print_depth (mpc_ast_t *a, int d, FILE *fp)
 
void mpc_ast_print (mpc_ast_t *a)
 
void mpc_ast_print_to (mpc_ast_t *a, FILE *fp)
 
int mpc_ast_get_index (mpc_ast_t *ast, const char *tag)
 
int mpc_ast_get_index_lb (mpc_ast_t *ast, const char *tag, int lb)
 
mpc_ast_tmpc_ast_get_child (mpc_ast_t *ast, const char *tag)
 
mpc_ast_tmpc_ast_get_child_lb (mpc_ast_t *ast, const char *tag, int lb)
 
mpc_ast_trav_tmpc_ast_traverse_start (mpc_ast_t *ast, mpc_ast_trav_order_t order)
 
mpc_ast_tmpc_ast_traverse_next (mpc_ast_trav_t **trav)
 
void mpc_ast_traverse_free (mpc_ast_trav_t **trav)
 
mpc_val_tmpcf_fold_ast (int n, mpc_val_t **xs)
 
mpc_val_tmpcf_str_ast (mpc_val_t *c)
 
mpc_val_tmpcf_state_ast (int n, mpc_val_t **xs)
 
mpc_parser_tmpca_state (mpc_parser_t *a)
 
mpc_parser_tmpca_tag (mpc_parser_t *a, const char *t)
 
mpc_parser_tmpca_add_tag (mpc_parser_t *a, const char *t)
 
mpc_parser_tmpca_root (mpc_parser_t *a)
 
mpc_parser_tmpca_not (mpc_parser_t *a)
 
mpc_parser_tmpca_maybe (mpc_parser_t *a)
 
mpc_parser_tmpca_many (mpc_parser_t *a)
 
mpc_parser_tmpca_many1 (mpc_parser_t *a)
 
mpc_parser_tmpca_count (int n, mpc_parser_t *a)
 
mpc_parser_tmpca_or (int n,...)
 
mpc_parser_tmpca_and (int n,...)
 
mpc_parser_tmpca_total (mpc_parser_t *a)
 
static mpc_val_tmpcaf_grammar_or (int n, mpc_val_t **xs)
 
static mpc_val_tmpcaf_grammar_and (int n, mpc_val_t **xs)
 
static mpc_val_tmpcaf_grammar_repeat (int n, mpc_val_t **xs)
 
static mpc_val_tmpcaf_grammar_string (mpc_val_t *x, void *s)
 
static mpc_val_tmpcaf_grammar_char (mpc_val_t *x, void *s)
 
static mpc_val_tmpcaf_fold_regex (int n, mpc_val_t **xs)
 
static int is_number (const char *s)
 
static mpc_parser_tmpca_grammar_find_parser (char *x, mpca_grammar_st_t *st)
 
static mpc_val_tmpcaf_grammar_id (mpc_val_t *x, void *s)
 
mpc_parser_tmpca_grammar_st (const char *grammar, mpca_grammar_st_t *st)
 
mpc_parser_tmpca_grammar (int flags, const char *grammar,...)
 
static mpc_val_tmpca_stmt_afold (int n, mpc_val_t **xs)
 
static mpc_val_tmpca_stmt_fold (int n, mpc_val_t **xs)
 
static void mpca_stmt_list_delete (mpc_val_t *x)
 
static mpc_val_tmpca_stmt_list_apply_to (mpc_val_t *x, void *s)
 
static mpc_err_tmpca_lang_st (mpc_input_t *i, mpca_grammar_st_t *st)
 
mpc_err_tmpca_lang_file (int flags, FILE *f,...)
 
mpc_err_tmpca_lang_pipe (int flags, FILE *p,...)
 
mpc_err_tmpca_lang (int flags, const char *language,...)
 
mpc_err_tmpca_lang_contents (int flags, const char *filename,...)
 
static int mpc_nodecount_unretained (mpc_parser_t *p, int force)
 
void mpc_stats (mpc_parser_t *p)
 
static void mpc_optimise_unretained (mpc_parser_t *p, int force)
 
void mpc_optimise (mpc_parser_t *p)
 

Variables

static char char_unescape_buffer [4]
 
static const char mpc_escape_input_c []
 
static const char * mpc_escape_output_c []
 
static const char mpc_escape_input_raw_re [] = { '/' }
 
static const char * mpc_escape_output_raw_re [] = { "\\/", NULL }
 
static const char mpc_escape_input_raw_cstr [] = { '"' }
 
static const char * mpc_escape_output_raw_cstr [] = { "\\\"", NULL }
 
static const char mpc_escape_input_raw_cchar [] = { '\'' }
 
static const char * mpc_escape_output_raw_cchar [] = { "\\'", NULL }
 

Macro Definition Documentation

◆ MPC_FAILURE

#define MPC_FAILURE (   x)    r->error = x; return 0

Definition at line 1040 of file mpc.c.

◆ MPC_MAX_RECURSION_DEPTH

#define MPC_MAX_RECURSION_DEPTH   1000

Definition at line 1045 of file mpc.c.

◆ MPC_PRIMITIVE

#define MPC_PRIMITIVE (   x)
Value:
if (x) { MPC_SUCCESS(r->output); } \
else { MPC_FAILURE(NULL); }
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
int x
Definition: mipsasm.c:20
#define MPC_SUCCESS(x)
Definition: mpc.c:1039
#define MPC_FAILURE(x)
Definition: mpc.c:1040

Definition at line 1041 of file mpc.c.

◆ MPC_SUCCESS

#define MPC_SUCCESS (   x)    r->output = x; return 1

Definition at line 1039 of file mpc.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MPC_INPUT_STRING 
MPC_INPUT_FILE 
MPC_INPUT_PIPE 

Definition at line 60 of file mpc.c.

60  {
61  MPC_INPUT_STRING = 0,
62  MPC_INPUT_FILE = 1,
63  MPC_INPUT_PIPE = 2
64 };
@ MPC_INPUT_FILE
Definition: mpc.c:62
@ MPC_INPUT_PIPE
Definition: mpc.c:63
@ MPC_INPUT_STRING
Definition: mpc.c:61

◆ anonymous enum

anonymous enum
Enumerator
MPC_INPUT_MARKS_MIN 

Definition at line 66 of file mpc.c.

66  {
68 };
@ MPC_INPUT_MARKS_MIN
Definition: mpc.c:67

◆ anonymous enum

anonymous enum
Enumerator
MPC_INPUT_MEM_NUM 

Definition at line 70 of file mpc.c.

70  {
71  MPC_INPUT_MEM_NUM = 512
72 };
@ MPC_INPUT_MEM_NUM
Definition: mpc.c:71

◆ anonymous enum

anonymous enum
Enumerator
MPC_TYPE_UNDEFINED 
MPC_TYPE_PASS 
MPC_TYPE_FAIL 
MPC_TYPE_LIFT 
MPC_TYPE_LIFT_VAL 
MPC_TYPE_EXPECT 
MPC_TYPE_ANCHOR 
MPC_TYPE_STATE 
MPC_TYPE_ANY 
MPC_TYPE_SINGLE 
MPC_TYPE_ONEOF 
MPC_TYPE_NONEOF 
MPC_TYPE_RANGE 
MPC_TYPE_SATISFY 
MPC_TYPE_STRING 
MPC_TYPE_APPLY 
MPC_TYPE_APPLY_TO 
MPC_TYPE_PREDICT 
MPC_TYPE_NOT 
MPC_TYPE_MAYBE 
MPC_TYPE_MANY 
MPC_TYPE_MANY1 
MPC_TYPE_COUNT 
MPC_TYPE_OR 
MPC_TYPE_AND 
MPC_TYPE_CHECK 
MPC_TYPE_CHECK_WITH 
MPC_TYPE_SOI 
MPC_TYPE_EOI 

Definition at line 883 of file mpc.c.

883  {
884  MPC_TYPE_UNDEFINED = 0,
885  MPC_TYPE_PASS = 1,
886  MPC_TYPE_FAIL = 2,
887  MPC_TYPE_LIFT = 3,
888  MPC_TYPE_LIFT_VAL = 4,
889  MPC_TYPE_EXPECT = 5,
890  MPC_TYPE_ANCHOR = 6,
891  MPC_TYPE_STATE = 7,
892 
893  MPC_TYPE_ANY = 8,
894  MPC_TYPE_SINGLE = 9,
895  MPC_TYPE_ONEOF = 10,
896  MPC_TYPE_NONEOF = 11,
897  MPC_TYPE_RANGE = 12,
898  MPC_TYPE_SATISFY = 13,
899  MPC_TYPE_STRING = 14,
900 
901  MPC_TYPE_APPLY = 15,
902  MPC_TYPE_APPLY_TO = 16,
903  MPC_TYPE_PREDICT = 17,
904  MPC_TYPE_NOT = 18,
905  MPC_TYPE_MAYBE = 19,
906  MPC_TYPE_MANY = 20,
907  MPC_TYPE_MANY1 = 21,
908  MPC_TYPE_COUNT = 22,
909 
910  MPC_TYPE_OR = 23,
911  MPC_TYPE_AND = 24,
912 
913  MPC_TYPE_CHECK = 25,
914  MPC_TYPE_CHECK_WITH = 26,
915 
916  MPC_TYPE_SOI = 27,
917  MPC_TYPE_EOI = 28
918 };
@ MPC_TYPE_LIFT_VAL
Definition: mpc.c:888
@ MPC_TYPE_PASS
Definition: mpc.c:885
@ MPC_TYPE_SINGLE
Definition: mpc.c:894
@ MPC_TYPE_LIFT
Definition: mpc.c:887
@ MPC_TYPE_FAIL
Definition: mpc.c:886
@ MPC_TYPE_PREDICT
Definition: mpc.c:903
@ MPC_TYPE_NONEOF
Definition: mpc.c:896
@ MPC_TYPE_NOT
Definition: mpc.c:904
@ MPC_TYPE_SATISFY
Definition: mpc.c:898
@ MPC_TYPE_MAYBE
Definition: mpc.c:905
@ MPC_TYPE_STRING
Definition: mpc.c:899
@ MPC_TYPE_CHECK_WITH
Definition: mpc.c:914
@ MPC_TYPE_SOI
Definition: mpc.c:916
@ MPC_TYPE_RANGE
Definition: mpc.c:897
@ MPC_TYPE_UNDEFINED
Definition: mpc.c:884
@ MPC_TYPE_MANY
Definition: mpc.c:906
@ MPC_TYPE_COUNT
Definition: mpc.c:908
@ MPC_TYPE_EOI
Definition: mpc.c:917
@ MPC_TYPE_APPLY
Definition: mpc.c:901
@ MPC_TYPE_CHECK
Definition: mpc.c:913
@ MPC_TYPE_APPLY_TO
Definition: mpc.c:902
@ MPC_TYPE_EXPECT
Definition: mpc.c:889
@ MPC_TYPE_ANCHOR
Definition: mpc.c:890
@ MPC_TYPE_OR
Definition: mpc.c:910
@ MPC_TYPE_ANY
Definition: mpc.c:893
@ MPC_TYPE_STATE
Definition: mpc.c:891
@ MPC_TYPE_ONEOF
Definition: mpc.c:895
@ MPC_TYPE_AND
Definition: mpc.c:911
@ MPC_TYPE_MANY1
Definition: mpc.c:907

◆ anonymous enum

anonymous enum
Enumerator
MPC_PARSE_STACK_MIN 

Definition at line 1035 of file mpc.c.

1035  {
1037 };
@ MPC_PARSE_STACK_MIN
Definition: mpc.c:1036

Function Documentation

◆ is_number()

static int is_number ( const char *  s)
static

Definition at line 3453 of file mpc.c.

3453  {
3454  size_t i;
3455  for (i = 0; i < strlen(s); i++) { if (!strchr("0123456789", s[i])) { return 0; } }
3456  return 1;
3457 }
lzma_index ** i
Definition: index.h:629
static RzSocket * s
Definition: rtr.c:28

References i, and s.

Referenced by mpca_grammar_find_parser().

◆ mpc_alpha()

mpc_parser_t* mpc_alpha ( void  )

Definition at line 2025 of file mpc.c.

2025 { return mpc_expect(mpc_oneof("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), "letter"); }
mpc_parser_t * mpc_oneof(const char *s)
Definition: mpc.c:1762
mpc_parser_t * mpc_expect(mpc_parser_t *a, const char *expected)
Definition: mpc.c:1690

References mpc_expect(), and mpc_oneof().

Referenced by mpc_alphanum(), and mpc_ident().

◆ mpc_alphanum()

mpc_parser_t* mpc_alphanum ( void  )

Definition at line 2027 of file mpc.c.

2027 { return mpc_expect(mpc_or(3, mpc_alpha(), mpc_digit(), mpc_underscore()), "alphanumeric"); }
mpc_parser_t * mpc_digit(void)
Definition: mpc.c:2016
mpc_parser_t * mpc_alpha(void)
Definition: mpc.c:2025
mpc_parser_t * mpc_underscore(void)
Definition: mpc.c:2026
mpc_parser_t * mpc_or(int n,...)
Definition: mpc.c:1928

References mpc_alpha(), mpc_digit(), mpc_expect(), mpc_or(), and mpc_underscore().

Referenced by mpc_ident(), and mpc_re_escape_char().

◆ mpc_anchor()

mpc_parser_t* mpc_anchor ( int(*)(char, char)  f)

Definition at line 1677 of file mpc.c.

1677  {
1679  p->type = MPC_TYPE_ANCHOR;
1680  p->data.anchor.f = f;
1681  return mpc_expect(p, "anchor");
1682 }
void * p
Definition: libc.cpp:67
static mpc_parser_t * mpc_undefined(void)
Definition: mpc.c:1472
#define f(i)
Definition: sha256.c:46

References f, mpc_expect(), MPC_TYPE_ANCHOR, mpc_undefined(), and p.

Referenced by mpc_boundary(), and mpc_boundary_newline().

◆ mpc_and()

mpc_parser_t* mpc_and ( int  n,
mpc_fold_t  f,
  ... 
)

Definition at line 1948 of file mpc.c.

1948  {
1949 
1950  int i;
1951  va_list va;
1952 
1954 
1955  p->type = MPC_TYPE_AND;
1956  p->data.and.n = n;
1957  p->data.and.f = f;
1958  p->data.and.xs = malloc(sizeof(mpc_parser_t*) * n);
1959  p->data.and.dxs = malloc(sizeof(mpc_dtor_t) * (n-1));
1960 
1961  va_start(va, f);
1962  for (i = 0; i < n; i++) {
1963  p->data.and.xs[i] = va_arg(va, mpc_parser_t*);
1964  }
1965  for (i = 0; i < (n-1); i++) {
1966  p->data.and.dxs[i] = va_arg(va, mpc_dtor_t);
1967  }
1968  va_end(va);
1969 
1970  return p;
1971 }
void * malloc(size_t size)
Definition: malloc.c:123
int n
Definition: mipsasm.c:19
void(* mpc_dtor_t)(mpc_val_t *)
Definition: mpc.h:78

References f, i, malloc(), MPC_TYPE_AND, mpc_undefined(), n, and p.

Referenced by mpc_between(), mpc_endwith(), mpc_escape(), mpc_ident(), mpc_re_escape_char(), mpc_re_mode(), mpc_real(), mpc_startwith(), mpc_strip(), mpc_stripl(), mpc_stripr(), mpc_tok(), mpc_tok_between(), mpc_whole(), mpca_grammar_st(), mpca_lang_st(), mpca_state(), mpcf_re_and(), and mpcf_re_escape().

◆ mpc_any()

mpc_parser_t* mpc_any ( void  )

Definition at line 1741 of file mpc.c.

1741  {
1743  p->type = MPC_TYPE_ANY;
1744  return mpc_expect(p, "any character");
1745 }

References mpc_expect(), MPC_TYPE_ANY, mpc_undefined(), and p.

Referenced by mpc_char_lit(), mpc_escape(), and mpcf_re_escape().

◆ mpc_apply()

mpc_parser_t* mpc_apply ( mpc_parser_t a,
mpc_apply_t  f 
)

Definition at line 1798 of file mpc.c.

1798  {
1800  p->type = MPC_TYPE_APPLY;
1801  p->data.apply.x = a;
1802  p->data.apply.f = f;
1803  return p;
1804 }
#define a(i)
Definition: sha256.c:41

References a, f, MPC_TYPE_APPLY, mpc_undefined(), and p.

Referenced by mpc_blank(), mpc_float(), mpc_hex(), mpc_int(), mpc_oct(), mpc_re_mode(), mpca_root(), mpcaf_fold_regex(), mpcaf_grammar_char(), and mpcaf_grammar_string().

◆ mpc_apply_to()

mpc_parser_t* mpc_apply_to ( mpc_parser_t a,
mpc_apply_to_t  f,
void *  x 
)

Definition at line 1806 of file mpc.c.

1806  {
1808  p->type = MPC_TYPE_APPLY_TO;
1809  p->data.apply_to.x = a;
1810  p->data.apply_to.f = f;
1811  p->data.apply_to.d = x;
1812  return p;
1813 }

References a, f, MPC_TYPE_APPLY_TO, mpc_undefined(), p, and x.

Referenced by mpc_re_mode(), mpca_add_tag(), mpca_grammar_st(), mpca_lang_st(), and mpca_tag().

◆ mpc_ast_add_child()

mpc_ast_t* mpc_ast_add_child ( mpc_ast_t r,
mpc_ast_t a 
)

Definition at line 2974 of file mpc.c.

2974  {
2975  r->children_num++;
2976  r->children = realloc(r->children, sizeof(mpc_ast_t*) * r->children_num);
2977  r->children[r->children_num-1] = a;
2978  return r;
2979 }
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
Definition: mpc.h:284

References a, r, and realloc().

Referenced by mpc_ast_add_root(), mpc_ast_build(), and mpcf_fold_ast().

◆ mpc_ast_add_root()

mpc_ast_t* mpc_ast_add_root ( mpc_ast_t a)

Definition at line 2946 of file mpc.c.

2946  {
2947 
2948  mpc_ast_t *r;
2949 
2950  if (a == NULL) { return a; }
2951  if (a->children_num == 0) { return a; }
2952  if (a->children_num == 1) { return a; }
2953 
2954  r = mpc_ast_new(">", "");
2955  mpc_ast_add_child(r, a);
2956  return r;
2957 }
mpc_ast_t * mpc_ast_new(const char *tag, const char *contents)
Definition: mpc.c:2910
mpc_ast_t * mpc_ast_add_child(mpc_ast_t *r, mpc_ast_t *a)
Definition: mpc.c:2974

References a, mpc_ast_add_child(), mpc_ast_new(), NULL, and r.

Referenced by mpca_root().

◆ mpc_ast_add_root_tag()

mpc_ast_t* mpc_ast_add_root_tag ( mpc_ast_t a,
const char *  t 
)

Definition at line 2990 of file mpc.c.

2990  {
2991  if (a == NULL) { return a; }
2992  a->tag = realloc(a->tag, (strlen(t)-1) + strlen(a->tag) + 1);
2993  memmove(a->tag + (strlen(t)-1), a->tag, strlen(a->tag)+1);
2994  memmove(a->tag, t, (strlen(t)-1));
2995  return a;
2996 }

References a, NULL, and realloc().

Referenced by mpcf_fold_ast().

◆ mpc_ast_add_tag()

mpc_ast_t* mpc_ast_add_tag ( mpc_ast_t a,
const char *  t 
)

Definition at line 2981 of file mpc.c.

2981  {
2982  if (a == NULL) { return a; }
2983  a->tag = realloc(a->tag, strlen(t) + 1 + strlen(a->tag) + 1);
2984  memmove(a->tag + strlen(t) + 1, a->tag, strlen(a->tag)+1);
2985  memmove(a->tag, t, strlen(t));
2986  memmove(a->tag + strlen(t), "|", 1);
2987  return a;
2988 }

References a, NULL, and realloc().

Referenced by mpca_add_tag().

◆ mpc_ast_build()

mpc_ast_t* mpc_ast_build ( int  n,
const char *  tag,
  ... 
)

Definition at line 2928 of file mpc.c.

2928  {
2929 
2930  mpc_ast_t *a = mpc_ast_new(tag, "");
2931 
2932  int i;
2933  va_list va;
2934  va_start(va, tag);
2935 
2936  for (i = 0; i < n; i++) {
2937  mpc_ast_add_child(a, va_arg(va, mpc_ast_t*));
2938  }
2939 
2940  va_end(va);
2941 
2942  return a;
2943 
2944 }

References a, i, mpc_ast_add_child(), mpc_ast_new(), n, and test-lz4-versions::tag.

◆ mpc_ast_delete()

void mpc_ast_delete ( mpc_ast_t a)

Definition at line 2886 of file mpc.c.

2886  {
2887 
2888  int i;
2889 
2890  if (a == NULL) { return; }
2891 
2892  for (i = 0; i < a->children_num; i++) {
2893  mpc_ast_delete(a->children[i]);
2894  }
2895 
2896  free(a->children);
2897  free(a->tag);
2898  free(a->contents);
2899  free(a);
2900 
2901 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void mpc_ast_delete(mpc_ast_t *a)
Definition: mpc.c:2886

References a, free(), i, and NULL.

Referenced by main(), mpc_optimise_unretained(), mpca_and(), mpca_count(), mpca_not(), and mpca_total().

◆ mpc_ast_delete_no_children()

static void mpc_ast_delete_no_children ( mpc_ast_t a)
static

Definition at line 2903 of file mpc.c.

2903  {
2904  free(a->children);
2905  free(a->tag);
2906  free(a->contents);
2907  free(a);
2908 }

References a, and free().

Referenced by mpcf_fold_ast().

◆ mpc_ast_eq()

int mpc_ast_eq ( mpc_ast_t a,
mpc_ast_t b 
)

Definition at line 2959 of file mpc.c.

2959  {
2960 
2961  int i;
2962 
2963  if (strcmp(a->tag, b->tag) != 0) { return 0; }
2964  if (strcmp(a->contents, b->contents) != 0) { return 0; }
2965  if (a->children_num != b->children_num) { return 0; }
2966 
2967  for (i = 0; i < a->children_num; i++) {
2968  if (!mpc_ast_eq(a->children[i], b->children[i])) { return 0; }
2969  }
2970 
2971  return 1;
2972 }
int mpc_ast_eq(mpc_ast_t *a, mpc_ast_t *b)
Definition: mpc.c:2959
#define b(i)
Definition: sha256.c:42

References a, b, and i.

◆ mpc_ast_get_child()

mpc_ast_t* mpc_ast_get_child ( mpc_ast_t ast,
const char *  tag 
)

Definition at line 3060 of file mpc.c.

3060  {
3061  return mpc_ast_get_child_lb(ast, tag, 0);
3062 }
mpc_ast_t * mpc_ast_get_child_lb(mpc_ast_t *ast, const char *tag, int lb)
Definition: mpc.c:3064

References mpc_ast_get_child_lb(), and test-lz4-versions::tag.

◆ mpc_ast_get_child_lb()

mpc_ast_t* mpc_ast_get_child_lb ( mpc_ast_t ast,
const char *  tag,
int  lb 
)

Definition at line 3064 of file mpc.c.

3064  {
3065  int i;
3066 
3067  for(i=lb; i<ast->children_num; i++) {
3068  if(strcmp(ast->children[i]->tag, tag) == 0) {
3069  return ast->children[i];
3070  }
3071  }
3072 
3073  return NULL;
3074 }
int children_num
Definition: mpc.h:288
char * tag
Definition: mpc.h:285
struct mpc_ast_t ** children
Definition: mpc.h:289

References mpc_ast_t::children, mpc_ast_t::children_num, i, NULL, test-lz4-versions::tag, and mpc_ast_t::tag.

Referenced by mpc_ast_get_child().

◆ mpc_ast_get_index()

int mpc_ast_get_index ( mpc_ast_t ast,
const char *  tag 
)

Definition at line 3044 of file mpc.c.

3044  {
3045  return mpc_ast_get_index_lb(ast, tag, 0);
3046 }
int mpc_ast_get_index_lb(mpc_ast_t *ast, const char *tag, int lb)
Definition: mpc.c:3048

References mpc_ast_get_index_lb(), and test-lz4-versions::tag.

◆ mpc_ast_get_index_lb()

int mpc_ast_get_index_lb ( mpc_ast_t ast,
const char *  tag,
int  lb 
)

Definition at line 3048 of file mpc.c.

3048  {
3049  int i;
3050 
3051  for(i=lb; i<ast->children_num; i++) {
3052  if(strcmp(ast->children[i]->tag, tag) == 0) {
3053  return i;
3054  }
3055  }
3056 
3057  return -1;
3058 }

References mpc_ast_t::children, mpc_ast_t::children_num, i, test-lz4-versions::tag, and mpc_ast_t::tag.

Referenced by mpc_ast_get_index().

◆ mpc_ast_new()

mpc_ast_t* mpc_ast_new ( const char *  tag,
const char *  contents 
)

Definition at line 2910 of file mpc.c.

2910  {
2911 
2912  mpc_ast_t *a = malloc(sizeof(mpc_ast_t));
2913 
2914  a->tag = malloc(strlen(tag) + 1);
2915  strcpy(a->tag, tag);
2916 
2917  a->contents = malloc(strlen(contents) + 1);
2918  strcpy(a->contents, contents);
2919 
2920  a->state = mpc_state_new();
2921 
2922  a->children_num = 0;
2923  a->children = NULL;
2924  return a;
2925 
2926 }
static mpc_state_t mpc_state_new(void)
Definition: mpc.c:16

References a, malloc(), mpc_state_new(), NULL, and test-lz4-versions::tag.

Referenced by mpc_ast_add_root(), mpc_ast_build(), mpcf_fold_ast(), mpcf_input_str_ast(), and mpcf_str_ast().

◆ mpc_ast_print()

void mpc_ast_print ( mpc_ast_t a)

Definition at line 3036 of file mpc.c.

3036  {
3037  mpc_ast_print_depth(a, 0, stdout);
3038 }
static void mpc_ast_print_depth(mpc_ast_t *a, int d, FILE *fp)
Definition: mpc.c:3010

References a, and mpc_ast_print_depth().

Referenced by main().

◆ mpc_ast_print_depth()

static void mpc_ast_print_depth ( mpc_ast_t a,
int  d,
FILE *  fp 
)
static

Definition at line 3010 of file mpc.c.

3010  {
3011 
3012  int i;
3013 
3014  if (a == NULL) {
3015  fprintf(fp, "NULL\n");
3016  return;
3017  }
3018 
3019  for (i = 0; i < d; i++) { fprintf(fp, " "); }
3020 
3021  if (strlen(a->contents)) {
3022  fprintf(fp, "%s:%lu:%lu '%s'\n", a->tag,
3023  (long unsigned int)(a->state.row+1),
3024  (long unsigned int)(a->state.col+1),
3025  a->contents);
3026  } else {
3027  fprintf(fp, "%s \n", a->tag);
3028  }
3029 
3030  for (i = 0; i < a->children_num; i++) {
3031  mpc_ast_print_depth(a->children[i], d+1, fp);
3032  }
3033 
3034 }
#define d(i)
Definition: sha256.c:44

References a, d, i, and NULL.

Referenced by mpc_ast_print(), and mpc_ast_print_to().

◆ mpc_ast_print_to()

void mpc_ast_print_to ( mpc_ast_t a,
FILE *  fp 
)

Definition at line 3040 of file mpc.c.

3040  {
3041  mpc_ast_print_depth(a, 0, fp);
3042 }

References a, and mpc_ast_print_depth().

Referenced by main().

◆ mpc_ast_state()

mpc_ast_t* mpc_ast_state ( mpc_ast_t a,
mpc_state_t  s 
)

Definition at line 3004 of file mpc.c.

3004  {
3005  if (a == NULL) { return a; }
3006  a->state = s;
3007  return a;
3008 }

References a, NULL, and s.

Referenced by mpcf_input_state_ast(), and mpcf_state_ast().

◆ mpc_ast_tag()

mpc_ast_t* mpc_ast_tag ( mpc_ast_t a,
const char *  t 
)

Definition at line 2998 of file mpc.c.

2998  {
2999  a->tag = realloc(a->tag, strlen(t) + 1);
3000  strcpy(a->tag, t);
3001  return a;
3002 }

References a, and realloc().

Referenced by mpca_tag().

◆ mpc_ast_traverse_free()

void mpc_ast_traverse_free ( mpc_ast_trav_t **  trav)

Definition at line 3201 of file mpc.c.

3201  {
3202  mpc_ast_trav_t *n_trav;
3203 
3204  /* Go through parents until all are free */
3205  while(*trav != NULL) {
3206  n_trav = (*trav)->parent;
3207  free(*trav);
3208  *trav = n_trav;
3209  }
3210 }
struct mpc_ast_trav_t * parent
Definition: mpc.h:317

References free(), NULL, and mpc_ast_trav_t::parent.

◆ mpc_ast_traverse_next()

mpc_ast_t* mpc_ast_traverse_next ( mpc_ast_trav_t **  trav)

Definition at line 3118 of file mpc.c.

3118  {
3119  mpc_ast_trav_t *n_trav, *to_free;
3120  mpc_ast_t *ret = NULL;
3121  int cchild;
3122 
3123  /* The end of traversal was reached */
3124  if(*trav == NULL) return NULL;
3125 
3126  switch((*trav)->order) {
3128  ret = (*trav)->curr_node;
3129 
3130  /* If there aren't any more children, go up */
3131  while(*trav != NULL &&
3132  (*trav)->curr_child >= (*trav)->curr_node->children_num)
3133  {
3134  to_free = *trav;
3135  *trav = (*trav)->parent;
3136  free(to_free);
3137  }
3138 
3139  /* If trav is NULL, the end was reached */
3140  if(*trav == NULL) {
3141  break;
3142  }
3143 
3144  /* Go to next child */
3145  n_trav = malloc(sizeof(mpc_ast_trav_t));
3146 
3147  cchild = (*trav)->curr_child;
3148  n_trav->curr_node = (*trav)->curr_node->children[cchild];
3149  n_trav->parent = *trav;
3150  n_trav->curr_child = 0;
3151  n_trav->order = (*trav)->order;
3152 
3153  (*trav)->curr_child++;
3154  *trav = n_trav;
3155 
3156  break;
3157 
3159  ret = (*trav)->curr_node;
3160 
3161  /* Move up tree to the parent If the parent doesn't have any more nodes,
3162  * then this is the current node. If it does, move down to its left most
3163  * child. Also, free the previous traversal node */
3164  to_free = *trav;
3165  *trav = (*trav)->parent;
3166  free(to_free);
3167 
3168  if(*trav == NULL)
3169  break;
3170 
3171  /* Next child */
3172  (*trav)->curr_child++;
3173 
3174  /* If there aren't any more children, this is the next node */
3175  if((*trav)->curr_child >= (*trav)->curr_node->children_num) {
3176  break;
3177  }
3178 
3179  /* If there are still more children, find the leftmost child from this
3180  * node */
3181  while((*trav)->curr_node->children_num > 0) {
3182  n_trav = malloc(sizeof(mpc_ast_trav_t));
3183 
3184  cchild = (*trav)->curr_child;
3185  n_trav->curr_node = (*trav)->curr_node->children[cchild];
3186  n_trav->parent = *trav;
3187  n_trav->curr_child = 0;
3188  n_trav->order = (*trav)->order;
3189 
3190  *trav = n_trav;
3191  }
3192 
3193  default:
3194  /* Unreachable, but compiler complaints */
3195  break;
3196  }
3197 
3198  return ret;
3199 }
@ mpc_ast_trav_order_pre
Definition: mpc.h:311
@ mpc_ast_trav_order_post
Definition: mpc.h:312
mpc_ast_trav_order_t order
Definition: mpc.h:319
mpc_ast_t * curr_node
Definition: mpc.h:316
int curr_child
Definition: mpc.h:318

References mpc_ast_t::children, mpc_ast_trav_t::curr_child, mpc_ast_trav_t::curr_node, free(), malloc(), mpc_ast_trav_order_post, mpc_ast_trav_order_pre, NULL, mpc_ast_trav_t::order, and mpc_ast_trav_t::parent.

◆ mpc_ast_traverse_start()

mpc_ast_trav_t* mpc_ast_traverse_start ( mpc_ast_t ast,
mpc_ast_trav_order_t  order 
)

Definition at line 3076 of file mpc.c.

3078 {
3079  mpc_ast_trav_t *trav, *n_trav;
3080  mpc_ast_t *cnode = ast;
3081 
3082  /* Create the traversal structure */
3083  trav = malloc(sizeof(mpc_ast_trav_t));
3084  trav->curr_node = cnode;
3085  trav->parent = NULL;
3086  trav->curr_child = 0;
3087  trav->order = order;
3088 
3089  /* Get start node */
3090  switch(order) {
3092  /* Nothing else is needed for pre order start */
3093  break;
3094 
3096  while(cnode->children_num > 0) {
3097  cnode = cnode->children[0];
3098 
3099  n_trav = malloc(sizeof(mpc_ast_trav_t));
3100  n_trav->curr_node = cnode;
3101  n_trav->parent = trav;
3102  n_trav->curr_child = 0;
3103  n_trav->order = order;
3104 
3105  trav = n_trav;
3106  }
3107 
3108  break;
3109 
3110  default:
3111  /* Unreachable, but compiler complaints */
3112  break;
3113  }
3114 
3115  return trav;
3116 }

References mpc_ast_t::children, mpc_ast_t::children_num, mpc_ast_trav_t::curr_child, mpc_ast_trav_t::curr_node, malloc(), mpc_ast_trav_order_post, mpc_ast_trav_order_pre, NULL, mpc_ast_trav_t::order, and mpc_ast_trav_t::parent.

◆ mpc_between()

mpc_parser_t* mpc_between ( mpc_parser_t a,
mpc_dtor_t  ad,
const char *  o,
const char *  c 
)

Definition at line 2093 of file mpc.c.

2093  {
2094  return mpc_and(3, mpcf_snd_free,
2095  mpc_string(o), a, mpc_string(c),
2096  free, ad);
2097 }
mpc_parser_t * mpc_string(const char *s)
Definition: mpc.c:1786
mpc_parser_t * mpc_and(int n, mpc_fold_t f,...)
Definition: mpc.c:1948
mpc_val_t * mpcf_snd_free(int n, mpc_val_t **xs)
Definition: mpc.c:2638
#define c(i)
Definition: sha256.c:43

References a, c, free(), mpc_and(), mpc_string(), and mpcf_snd_free().

Referenced by mpc_braces(), mpc_brackets(), mpc_char_lit(), mpc_parens(), mpc_regex_lit(), mpc_squares(), and mpc_string_lit().

◆ mpc_blank()

mpc_parser_t* mpc_blank ( void  )

Definition at line 2010 of file mpc.c.

2010 { return mpc_expect(mpc_apply(mpc_whitespaces(), mpcf_free), "whitespace"); }
mpc_parser_t * mpc_apply(mpc_parser_t *a, mpc_apply_t f)
Definition: mpc.c:1798
mpc_val_t * mpcf_free(mpc_val_t *x)
Definition: mpc.c:2432
mpc_parser_t * mpc_whitespaces(void)
Definition: mpc.c:2009

References mpc_apply(), mpc_expect(), mpc_whitespaces(), and mpcf_free().

Referenced by mpc_strip(), mpc_stripl(), mpc_stripr(), and mpc_tok().

◆ mpc_boundary()

mpc_parser_t* mpc_boundary ( void  )

Definition at line 2005 of file mpc.c.

2005 { return mpc_expect(mpc_anchor(mpc_boundary_anchor), "word boundary"); }
static int mpc_boundary_anchor(char prev, char next)
Definition: mpc.c:1989
mpc_parser_t * mpc_anchor(int(*f)(char, char))
Definition: mpc.c:1677

References mpc_anchor(), mpc_boundary_anchor(), and mpc_expect().

Referenced by mpc_re_escape_char().

◆ mpc_boundary_anchor()

static int mpc_boundary_anchor ( char  prev,
char  next 
)
static

Definition at line 1989 of file mpc.c.

1989  {
1990  const char* word = "abcdefghijklmnopqrstuvwxyz"
1991  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
1992  "0123456789_";
1993  if ( strchr(word, next) && prev == '\0') { return 1; }
1994  if ( strchr(word, prev) && next == '\0') { return 1; }
1995  if ( strchr(word, next) && !strchr(word, prev)) { return 1; }
1996  if (!strchr(word, next) && strchr(word, prev)) { return 1; }
1997  return 0;
1998 }

Referenced by mpc_boundary().

◆ mpc_boundary_newline()

mpc_parser_t* mpc_boundary_newline ( void  )

Definition at line 2006 of file mpc.c.

2006 { return mpc_expect(mpc_anchor(mpc_boundary_newline_anchor), "start of newline"); }
static int mpc_boundary_newline_anchor(char prev, char next)
Definition: mpc.c:2000

References mpc_anchor(), mpc_boundary_newline_anchor(), and mpc_expect().

Referenced by mpcf_re_escape().

◆ mpc_boundary_newline_anchor()

static int mpc_boundary_newline_anchor ( char  prev,
char  next 
)
static

Definition at line 2000 of file mpc.c.

2000  {
2001  (void)next;
2002  return prev == '\n';
2003 }

Referenced by mpc_boundary_newline().

◆ mpc_braces()

mpc_parser_t* mpc_braces ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2100 of file mpc.c.

2100 { return mpc_between(a, ad, "<", ">"); }
mpc_parser_t * mpc_between(mpc_parser_t *a, mpc_dtor_t ad, const char *o, const char *c)
Definition: mpc.c:2093

References a, and mpc_between().

◆ mpc_brackets()

mpc_parser_t* mpc_brackets ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2101 of file mpc.c.

2101 { return mpc_between(a, ad, "{", "}"); }

References a, and mpc_between().

Referenced by mpc_re_mode().

◆ mpc_calloc()

static void* mpc_calloc ( mpc_input_t i,
size_t  n,
size_t  m 
)
static

Definition at line 257 of file mpc.c.

257  {
258  char *x = mpc_malloc(i, n * m);
259  memset(x, 0, n * m);
260  return x;
261 }
return memset(p, 0, total)
static void * mpc_malloc(mpc_input_t *i, size_t n)
Definition: mpc.c:237

References i, regress::m, memset(), mpc_malloc(), n, and x.

Referenced by mpc_err_repeat(), and mpcf_input_strfold().

◆ mpc_char()

mpc_parser_t* mpc_char ( char  c)

Definition at line 1747 of file mpc.c.

1747  {
1749  p->type = MPC_TYPE_SINGLE;
1750  p->data.single.x = c;
1751  return mpc_expectf(p, "'%c'", c);
1752 }
mpc_parser_t * mpc_expectf(mpc_parser_t *a, const char *fmt,...)
Definition: mpc.c:1719

References c, mpc_expectf(), MPC_TYPE_SINGLE, mpc_undefined(), and p.

Referenced by mpc_escape(), mpc_newline(), mpc_re_escape_char(), mpc_re_mode(), mpc_real(), mpc_tab(), mpc_underscore(), mpcaf_grammar_char(), and mpcf_re_escape().

◆ mpc_char_lit()

mpc_parser_t* mpc_char_lit ( void  )

Definition at line 2056 of file mpc.c.

2056  {
2057  return mpc_expect(mpc_between(mpc_or(2, mpc_escape(), mpc_any()), free, "'", "'"), "char");
2058 }
mpc_parser_t * mpc_escape(void)
Definition: mpc.c:2014
mpc_parser_t * mpc_any(void)
Definition: mpc.c:1741

References free(), mpc_any(), mpc_between(), mpc_escape(), mpc_expect(), and mpc_or().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_check()

mpc_parser_t* mpc_check ( mpc_parser_t a,
mpc_dtor_t  da,
mpc_check_t  f,
const char *  e 
)

Definition at line 1815 of file mpc.c.

1815  {
1817  p->type = MPC_TYPE_CHECK;
1818  p->data.check.x = a;
1819  p->data.check.dx = da;
1820  p->data.check.f = f;
1821  p->data.check.e = malloc(strlen(e) + 1);
1822  strcpy(p->data.check.e, e);
1823  return p;
1824 }
#define e(frag)

References a, e, f, malloc(), MPC_TYPE_CHECK, mpc_undefined(), and p.

Referenced by mpc_checkf().

◆ mpc_check_with()

mpc_parser_t* mpc_check_with ( mpc_parser_t a,
mpc_dtor_t  da,
mpc_check_with_t  f,
void *  x,
const char *  e 
)

Definition at line 1826 of file mpc.c.

1826  {
1828  p->type = MPC_TYPE_CHECK_WITH;
1829  p->data.check_with.x = a;
1830  p->data.check_with.dx = da;
1831  p->data.check_with.f = f;
1832  p->data.check_with.d = x;
1833  p->data.check_with.e = malloc(strlen(e) + 1);
1834  strcpy(p->data.check_with.e, e);
1835  return p;
1836 }

References a, e, f, malloc(), MPC_TYPE_CHECK_WITH, mpc_undefined(), p, and x.

Referenced by mpc_check_withf().

◆ mpc_check_withf()

mpc_parser_t* mpc_check_withf ( mpc_parser_t a,
mpc_dtor_t  da,
mpc_check_with_t  f,
void *  x,
const char *  fmt,
  ... 
)

Definition at line 1854 of file mpc.c.

1854  {
1855  va_list va;
1856  char *buffer;
1857  mpc_parser_t *p;
1858 
1859  va_start(va, fmt);
1860  buffer = malloc(2048);
1861  vsprintf(buffer, fmt, va);
1862  va_end(va);
1863 
1864  p = mpc_check_with(a, da, f, x, buffer);
1865  free(buffer);
1866 
1867  return p;
1868 }
struct buffer buffer
vsprintf
Definition: kernel.h:367
mpc_parser_t * mpc_check_with(mpc_parser_t *a, mpc_dtor_t da, mpc_check_with_t f, void *x, const char *e)
Definition: mpc.c:1826
Definition: buffer.h:15

References a, f, free(), malloc(), mpc_check_with(), p, vsprintf, and x.

◆ mpc_checkf()

mpc_parser_t* mpc_checkf ( mpc_parser_t a,
mpc_dtor_t  da,
mpc_check_t  f,
const char *  fmt,
  ... 
)

Definition at line 1838 of file mpc.c.

1838  {
1839  va_list va;
1840  char *buffer;
1841  mpc_parser_t *p;
1842 
1843  va_start(va, fmt);
1844  buffer = malloc(2048);
1845  vsprintf(buffer, fmt, va);
1846  va_end(va);
1847 
1848  p = mpc_check(a, da, f, buffer);
1849  free(buffer);
1850 
1851  return p;
1852 }
mpc_parser_t * mpc_check(mpc_parser_t *a, mpc_dtor_t da, mpc_check_t f, const char *e)
Definition: mpc.c:1815

References a, f, free(), malloc(), mpc_check(), p, and vsprintf.

◆ mpc_cleanup()

void mpc_cleanup ( int  n,
  ... 
)

Definition at line 1596 of file mpc.c.

1596  {
1597  int i;
1598  mpc_parser_t **list = malloc(sizeof(mpc_parser_t*) * n);
1599 
1600  va_list va;
1601  va_start(va, n);
1602  for (i = 0; i < n; i++) { list[i] = va_arg(va, mpc_parser_t*); }
1603  for (i = 0; i < n; i++) { mpc_undefine(list[i]); }
1604  for (i = 0; i < n; i++) { mpc_delete(list[i]); }
1605  va_end(va);
1606 
1607  free(list);
1608 }
static void list(RzEgg *egg)
Definition: rz-gg.c:52
mpc_parser_t * mpc_undefine(mpc_parser_t *p)
Definition: mpc.c:1574
void mpc_delete(mpc_parser_t *p)
Definition: mpc.c:1453

References free(), i, list(), malloc(), mpc_delete(), mpc_undefine(), and n.

Referenced by main(), mpc_re_mode(), mpca_grammar_st(), and mpca_lang_st().

◆ mpc_copy()

mpc_parser_t* mpc_copy ( mpc_parser_t a)

Definition at line 1488 of file mpc.c.

1488  {
1489  int i = 0;
1490  mpc_parser_t *p;
1491 
1492  if (a->retained) { return a; }
1493 
1494  p = mpc_undefined();
1495  p->retained = a->retained;
1496  p->type = a->type;
1497  p->data = a->data;
1498 
1499  if (a->name) {
1500  p->name = malloc(strlen(a->name)+1);
1501  strcpy(p->name, a->name);
1502  }
1503 
1504  switch (a->type) {
1505 
1506  case MPC_TYPE_FAIL:
1507  p->data.fail.m = malloc(strlen(a->data.fail.m)+1);
1508  strcpy(p->data.fail.m, a->data.fail.m);
1509  break;
1510 
1511  case MPC_TYPE_ONEOF:
1512  case MPC_TYPE_NONEOF:
1513  case MPC_TYPE_STRING:
1514  p->data.string.x = malloc(strlen(a->data.string.x)+1);
1515  strcpy(p->data.string.x, a->data.string.x);
1516  break;
1517 
1518  case MPC_TYPE_APPLY: p->data.apply.x = mpc_copy(a->data.apply.x); break;
1519  case MPC_TYPE_APPLY_TO: p->data.apply_to.x = mpc_copy(a->data.apply_to.x); break;
1520  case MPC_TYPE_PREDICT: p->data.predict.x = mpc_copy(a->data.predict.x); break;
1521 
1522  case MPC_TYPE_MAYBE:
1523  case MPC_TYPE_NOT:
1524  p->data.not.x = mpc_copy(a->data.not.x);
1525  break;
1526 
1527  case MPC_TYPE_EXPECT:
1528  p->data.expect.x = mpc_copy(a->data.expect.x);
1529  p->data.expect.m = malloc(strlen(a->data.expect.m)+1);
1530  strcpy(p->data.expect.m, a->data.expect.m);
1531  break;
1532 
1533  case MPC_TYPE_MANY:
1534  case MPC_TYPE_MANY1:
1535  case MPC_TYPE_COUNT:
1536  p->data.repeat.x = mpc_copy(a->data.repeat.x);
1537  break;
1538 
1539  case MPC_TYPE_OR:
1540  p->data.or.xs = malloc(a->data.or.n * sizeof(mpc_parser_t*));
1541  for (i = 0; i < a->data.or.n; i++) {
1542  p->data.or.xs[i] = mpc_copy(a->data.or.xs[i]);
1543  }
1544  break;
1545  case MPC_TYPE_AND:
1546  p->data.and.xs = malloc(a->data.and.n * sizeof(mpc_parser_t*));
1547  for (i = 0; i < a->data.and.n; i++) {
1548  p->data.and.xs[i] = mpc_copy(a->data.and.xs[i]);
1549  }
1550  p->data.and.dxs = malloc((a->data.and.n-1) * sizeof(mpc_dtor_t));
1551  for (i = 0; i < a->data.and.n-1; i++) {
1552  p->data.and.dxs[i] = a->data.and.dxs[i];
1553  }
1554  break;
1555 
1556  case MPC_TYPE_CHECK:
1557  p->data.check.x = mpc_copy(a->data.check.x);
1558  p->data.check.e = malloc(strlen(a->data.check.e)+1);
1559  strcpy(p->data.check.e, a->data.check.e);
1560  break;
1561  case MPC_TYPE_CHECK_WITH:
1562  p->data.check_with.x = mpc_copy(a->data.check_with.x);
1563  p->data.check_with.e = malloc(strlen(a->data.check_with.e)+1);
1564  strcpy(p->data.check_with.e, a->data.check_with.e);
1565  break;
1566 
1567  default: break;
1568  }
1569 
1570 
1571  return p;
1572 }
mpc_parser_t * mpc_copy(mpc_parser_t *a)
Definition: mpc.c:1488

References a, i, malloc(), MPC_TYPE_AND, MPC_TYPE_APPLY, MPC_TYPE_APPLY_TO, MPC_TYPE_CHECK, MPC_TYPE_CHECK_WITH, MPC_TYPE_COUNT, MPC_TYPE_EXPECT, MPC_TYPE_FAIL, MPC_TYPE_MANY, MPC_TYPE_MANY1, MPC_TYPE_MAYBE, MPC_TYPE_NONEOF, MPC_TYPE_NOT, MPC_TYPE_ONEOF, MPC_TYPE_OR, MPC_TYPE_PREDICT, MPC_TYPE_STRING, mpc_undefined(), and p.

◆ mpc_count()

mpc_parser_t* mpc_count ( int  n,
mpc_fold_t  f,
mpc_parser_t a,
mpc_dtor_t  da 
)

Definition at line 1918 of file mpc.c.

1918  {
1920  p->type = MPC_TYPE_COUNT;
1921  p->data.repeat.n = n;
1922  p->data.repeat.f = f;
1923  p->data.repeat.x = a;
1924  p->data.repeat.dx = da;
1925  return p;
1926 }

References a, f, MPC_TYPE_COUNT, mpc_undefined(), n, and p.

Referenced by mpca_count(), and mpcf_re_repeat().

◆ mpc_define()

mpc_parser_t* mpc_define ( mpc_parser_t p,
mpc_parser_t a 
)

Definition at line 1580 of file mpc.c.

1580  {
1581 
1582  if (p->retained) {
1583  p->type = a->type;
1584  p->data = a->data;
1585  } else {
1586  mpc_parser_t *a2 = mpc_failf("Attempt to assign to Unretained Parser!");
1587  p->type = a2->type;
1588  p->data = a2->data;
1589  free(a2);
1590  }
1591 
1592  free(a);
1593  return p;
1594 }
mpc_parser_t * mpc_failf(const char *fmt,...)
Definition: mpc.c:1644
mpc_pdata_t data
Definition: mpc.c:960
char type
Definition: mpc.c:961

References a, mpc_parser_t::data, free(), mpc_failf(), p, and mpc_parser_t::type.

Referenced by mpc_re_mode(), mpca_grammar_st(), mpca_lang_st(), and mpca_stmt_list_apply_to().

◆ mpc_delete()

void mpc_delete ( mpc_parser_t p)

Definition at line 1453 of file mpc.c.

1453  {
1454  if (p->retained) {
1455 
1456  if (p->type != MPC_TYPE_UNDEFINED) {
1458  }
1459 
1460  free(p->name);
1461  free(p);
1462 
1463  } else {
1465  }
1466 }
static void mpc_undefine_unretained(mpc_parser_t *p, int force)
Definition: mpc.c:1396

References free(), MPC_TYPE_UNDEFINED, mpc_undefine_unretained(), and p.

Referenced by mpc_cleanup(), mpc_optimise_unretained(), and mpc_re_mode().

◆ mpc_digit()

mpc_parser_t* mpc_digit ( void  )

Definition at line 2016 of file mpc.c.

2016 { return mpc_expect(mpc_oneof("0123456789"), "digit"); }

References mpc_expect(), and mpc_oneof().

Referenced by mpc_alphanum(), mpc_digits(), and mpc_re_escape_char().

◆ mpc_digits()

mpc_parser_t* mpc_digits ( void  )

Definition at line 2019 of file mpc.c.

2019 { return mpc_expect(mpc_many1(mpcf_strfold, mpc_digit()), "digits"); }
mpc_val_t * mpcf_strfold(int n, mpc_val_t **xs)
Definition: mpc.c:2648
mpc_parser_t * mpc_many1(mpc_fold_t f, mpc_parser_t *a)
Definition: mpc.c:1910

References mpc_digit(), mpc_expect(), mpc_many1(), and mpcf_strfold().

Referenced by mpc_int(), mpc_real(), mpca_grammar_st(), and mpca_lang_st().

◆ mpc_endwith()

mpc_parser_t* mpc_endwith ( mpc_parser_t a,
mpc_dtor_t  da 
)

Definition at line 2082 of file mpc.c.

2082 { return mpc_and(2, mpcf_fst, a, mpc_eoi(), da); }
mpc_parser_t * mpc_eoi(void)
Definition: mpc.c:1983
mpc_val_t * mpcf_fst(int n, mpc_val_t **xs)
Definition: mpc.c:2625

References a, mpc_and(), mpc_eoi(), and mpcf_fst().

◆ mpc_eoi()

mpc_parser_t* mpc_eoi ( void  )

Definition at line 1983 of file mpc.c.

1983  {
1985  p->type = MPC_TYPE_EOI;
1986  return mpc_expect(p, "end of input");
1987 }

References mpc_expect(), MPC_TYPE_EOI, mpc_undefined(), and p.

Referenced by mpc_endwith(), mpc_re_escape_char(), mpc_whole(), and mpcf_re_escape().

◆ mpc_err_add_expected()

static void mpc_err_add_expected ( mpc_input_t i,
mpc_err_t x,
char *  expected 
)
static

Definition at line 741 of file mpc.c.

741  {
742  (void)i;
743  x->expected_num++;
744  x->expected = mpc_realloc(i, x->expected, sizeof(char*) * x->expected_num);
745  x->expected[x->expected_num-1] = mpc_malloc(i, strlen(expected) + 1);
746  strcpy(x->expected[x->expected_num-1], expected);
747 }
static void * mpc_realloc(mpc_input_t *i, void *p, size_t n)
Definition: mpc.c:270

References i, mpc_malloc(), mpc_realloc(), and x.

Referenced by mpc_err_or().

◆ mpc_err_char_unescape()

static const char* mpc_err_char_unescape ( char  c)
static

Definition at line 606 of file mpc.c.

606  {
607 
608  char_unescape_buffer[0] = '\'';
609  char_unescape_buffer[1] = ' ';
610  char_unescape_buffer[2] = '\'';
611  char_unescape_buffer[3] = '\0';
612 
613  switch (c) {
614  case '\a': return "bell";
615  case '\b': return "backspace";
616  case '\f': return "formfeed";
617  case '\r': return "carriage return";
618  case '\v': return "vertical tab";
619  case '\0': return "end of input";
620  case '\n': return "newline";
621  case '\t': return "tab";
622  case ' ' : return "space";
623  default:
624  char_unescape_buffer[1] = c;
625  return char_unescape_buffer;
626  }
627 
628 }
static char char_unescape_buffer[4]
Definition: mpc.c:604

References c, and char_unescape_buffer.

Referenced by mpc_err_string().

◆ mpc_err_contains_expected()

static int mpc_err_contains_expected ( mpc_input_t i,
mpc_err_t x,
char *  expected 
)
static

Definition at line 732 of file mpc.c.

732  {
733  int j;
734  (void)i;
735  for (j = 0; j < x->expected_num; j++) {
736  if (strcmp(x->expected[j], expected) == 0) { return 1; }
737  }
738  return 0;
739 }

References i, and x.

Referenced by mpc_err_or().

◆ mpc_err_count()

static mpc_err_t* mpc_err_count ( mpc_input_t i,
mpc_err_t x,
int  n 
)
static

Definition at line 861 of file mpc.c.

861  {
862  mpc_err_t *y;
863  int digits = n/10 + 1;
864  char *prefix;
865  prefix = mpc_malloc(i, digits + strlen(" of ") + 1);
866  sprintf(prefix, "%i of ", n);
867  y = mpc_err_repeat(i, x, prefix);
868  mpc_free(i, prefix);
869  return y;
870 }
unsigned short prefix[65536]
Definition: gun.c:163
sprintf
Definition: kernel.h:365
static void mpc_free(mpc_input_t *i, void *p)
Definition: mpc.c:263
static mpc_err_t * mpc_err_repeat(mpc_input_t *i, mpc_err_t *x, const char *prefix)
Definition: mpc.c:801
Definition: mpc.h:40

References i, mpc_err_repeat(), mpc_free(), mpc_malloc(), n, prefix, sprintf, and x.

Referenced by mpc_parse_run().

◆ mpc_err_delete()

void mpc_err_delete ( mpc_err_t x)

Definition at line 575 of file mpc.c.

575  {
576  int i;
577  for (i = 0; i < x->expected_num; i++) { free(x->expected[i]); }
578  free(x->expected);
579  free(x->filename);
580  free(x->failure);
581  free(x);
582 }

References free(), i, and x.

Referenced by main(), mpc_re_mode(), mpc_test_fail(), mpc_test_pass(), and mpca_grammar_st().

◆ mpc_err_delete_internal()

static void mpc_err_delete_internal ( mpc_input_t i,
mpc_err_t x 
)
static

Definition at line 711 of file mpc.c.

711  {
712  int j;
713  if (x == NULL) { return; }
714  for (j = 0; j < x->expected_num; j++) { mpc_free(i, x->expected[j]); }
715  mpc_free(i, x->expected);
716  mpc_free(i, x->filename);
717  mpc_free(i, x->failure);
718  mpc_free(i, x);
719 }

References i, mpc_free(), NULL, and x.

Referenced by mpc_err_or(), and mpc_parse_input().

◆ mpc_err_export()

static mpc_err_t* mpc_err_export ( mpc_input_t i,
mpc_err_t x 
)
static

Definition at line 721 of file mpc.c.

721  {
722  int j;
723  for (j = 0; j < x->expected_num; j++) {
724  x->expected[j] = mpc_export(i, x->expected[j]);
725  }
726  x->expected = mpc_export(i, x->expected);
727  x->filename = mpc_export(i, x->filename);
728  x->failure = mpc_export(i, x->failure);
729  return mpc_export(i, x);
730 }
static void * mpc_export(mpc_input_t *i, void *p)
Definition: mpc.c:286

References i, mpc_export(), and x.

Referenced by mpc_parse_input().

◆ mpc_err_fail()

static mpc_err_t* mpc_err_fail ( mpc_input_t i,
const char *  failure 
)
static

Definition at line 682 of file mpc.c.

682  {
683  mpc_err_t *x;
684  if (i->suppress) { return NULL; }
685  x = mpc_malloc(i, sizeof(mpc_err_t));
686  x->filename = mpc_malloc(i, strlen(i->filename) + 1);
687  strcpy(x->filename, i->filename);
688  x->state = i->state;
689  x->expected_num = 0;
690  x->expected = NULL;
691  x->failure = mpc_malloc(i, strlen(failure) + 1);
692  strcpy(x->failure, failure);
693  x->received = ' ';
694  return x;
695 }

References i, mpc_malloc(), NULL, and x.

Referenced by mpc_parse_input(), and mpc_parse_run().

◆ mpc_err_file()

static mpc_err_t* mpc_err_file ( const char *  filename,
const char *  failure 
)
static

Definition at line 697 of file mpc.c.

697  {
698  mpc_err_t *x;
699  x = malloc(sizeof(mpc_err_t));
700  x->filename = malloc(strlen(filename) + 1);
701  strcpy(x->filename, filename);
702  x->state = mpc_state_new();
703  x->expected_num = 0;
704  x->expected = NULL;
705  x->failure = malloc(strlen(failure) + 1);
706  strcpy(x->failure, failure);
707  x->received = ' ';
708  return x;
709 }
const char * filename
Definition: ioapi.h:137

References malloc(), mpc_state_new(), NULL, and x.

Referenced by mpc_parse_contents(), and mpca_lang_contents().

◆ mpc_err_many1()

static mpc_err_t* mpc_err_many1 ( mpc_input_t i,
mpc_err_t x 
)
static

Definition at line 857 of file mpc.c.

857  {
858  return mpc_err_repeat(i, x, "one or more of ");
859 }

References i, mpc_err_repeat(), and x.

Referenced by mpc_parse_run().

◆ mpc_err_merge()

static mpc_err_t* mpc_err_merge ( mpc_input_t i,
mpc_err_t x,
mpc_err_t y 
)
static

Definition at line 872 of file mpc.c.

872  {
873  mpc_err_t *errs[2];
874  errs[0] = x;
875  errs[1] = y;
876  return mpc_err_or(i, errs, 2);
877 }
static mpc_err_t * mpc_err_or(mpc_input_t *i, mpc_err_t **x, int n)
Definition: mpc.c:749

References i, mpc_err_or(), and x.

Referenced by mpc_parse_input(), and mpc_parse_run().

◆ mpc_err_new()

static mpc_err_t* mpc_err_new ( mpc_input_t i,
const char *  expected 
)
static

Definition at line 666 of file mpc.c.

666  {
667  mpc_err_t *x;
668  if (i->suppress) { return NULL; }
669  x = mpc_malloc(i, sizeof(mpc_err_t));
670  x->filename = mpc_malloc(i, strlen(i->filename) + 1);
671  strcpy(x->filename, i->filename);
672  x->state = i->state;
673  x->expected_num = 1;
674  x->expected = mpc_malloc(i, sizeof(char*));
675  x->expected[0] = mpc_malloc(i, strlen(expected) + 1);
676  strcpy(x->expected[0], expected);
677  x->failure = NULL;
678  x->received = mpc_input_peekc(i);
679  return x;
680 }
static char mpc_input_peekc(mpc_input_t *i)
Definition: mpc.c:394

References i, mpc_input_peekc(), mpc_malloc(), NULL, and x.

Referenced by mpc_parse_run().

◆ mpc_err_or()

static mpc_err_t* mpc_err_or ( mpc_input_t i,
mpc_err_t **  x,
int  n 
)
static

Definition at line 749 of file mpc.c.

749  {
750 
751  int j, k, fst;
752  mpc_err_t *e;
753 
754  fst = -1;
755  for (j = 0; j < n; j++) {
756  if (x[j] != NULL) { fst = j; }
757  }
758 
759  if (fst == -1) { return NULL; }
760 
761  e = mpc_malloc(i, sizeof(mpc_err_t));
762  e->state = mpc_state_invalid();
763  e->expected_num = 0;
764  e->expected = NULL;
765  e->failure = NULL;
766  e->filename = mpc_malloc(i, strlen(x[fst]->filename)+1);
767  strcpy(e->filename, x[fst]->filename);
768 
769  for (j = 0; j < n; j++) {
770  if (x[j] == NULL) { continue; }
771  if (x[j]->state.pos > e->state.pos) { e->state = x[j]->state; }
772  }
773 
774  for (j = 0; j < n; j++) {
775  if (x[j] == NULL) { continue; }
776  if (x[j]->state.pos < e->state.pos) { continue; }
777 
778  if (x[j]->failure) {
779  e->failure = mpc_malloc(i, strlen(x[j]->failure)+1);
780  strcpy(e->failure, x[j]->failure);
781  break;
782  }
783 
784  e->received = x[j]->received;
785 
786  for (k = 0; k < x[j]->expected_num; k++) {
787  if (!mpc_err_contains_expected(i, e, x[j]->expected[k])) {
788  mpc_err_add_expected(i, e, x[j]->expected[k]);
789  }
790  }
791  }
792 
793  for (j = 0; j < n; j++) {
794  if (x[j] == NULL) { continue; }
796  }
797 
798  return e;
799 }
const char * k
Definition: dsignal.c:11
static void mpc_err_delete_internal(mpc_input_t *i, mpc_err_t *x)
Definition: mpc.c:711
static int mpc_err_contains_expected(mpc_input_t *i, mpc_err_t *x, char *expected)
Definition: mpc.c:732
static mpc_state_t mpc_state_invalid(void)
Definition: mpc.c:7
static void mpc_err_add_expected(mpc_input_t *i, mpc_err_t *x, char *expected)
Definition: mpc.c:741
Definition: dis.h:43

References e, i, k, mpc_err_add_expected(), mpc_err_contains_expected(), mpc_err_delete_internal(), mpc_malloc(), mpc_state_invalid(), n, NULL, and x.

Referenced by mpc_err_merge().

◆ mpc_err_print()

void mpc_err_print ( mpc_err_t x)

Definition at line 584 of file mpc.c.

584  {
585  mpc_err_print_to(x, stdout);
586 }
void mpc_err_print_to(mpc_err_t *x, FILE *f)
Definition: mpc.c:588

References mpc_err_print_to(), and x.

Referenced by main(), and mpc_test_pass().

◆ mpc_err_print_to()

void mpc_err_print_to ( mpc_err_t x,
FILE *  f 
)

Definition at line 588 of file mpc.c.

588  {
589  char *str = mpc_err_string(x);
590  fprintf(f, "%s", str);
591  free(str);
592 }
char * mpc_err_string(mpc_err_t *x)
Definition: mpc.c:630

References f, free(), mpc_err_string(), cmd_descs_generate::str, and x.

Referenced by mpc_err_print().

◆ mpc_err_repeat()

static mpc_err_t* mpc_err_repeat ( mpc_input_t i,
mpc_err_t x,
const char *  prefix 
)
static

Definition at line 801 of file mpc.c.

801  {
802 
803  int j = 0;
804  size_t l = 0;
805  char *expect = NULL;
806 
807  if (x == NULL) { return NULL; }
808 
809  if (x->expected_num == 0) {
810  expect = mpc_calloc(i, 1, 1);
811  x->expected_num = 1;
812  x->expected = mpc_realloc(i, x->expected, sizeof(char*) * x->expected_num);
813  x->expected[0] = expect;
814  return x;
815  }
816 
817  else if (x->expected_num == 1) {
818  expect = mpc_malloc(i, strlen(prefix) + strlen(x->expected[0]) + 1);
819  strcpy(expect, prefix);
820  strcat(expect, x->expected[0]);
821  mpc_free(i, x->expected[0]);
822  x->expected[0] = expect;
823  return x;
824  }
825 
826  else if (x->expected_num > 1) {
827 
828  l += strlen(prefix);
829  for (j = 0; j < x->expected_num-2; j++) {
830  l += strlen(x->expected[j]) + strlen(", ");
831  }
832  l += strlen(x->expected[x->expected_num-2]);
833  l += strlen(" or ");
834  l += strlen(x->expected[x->expected_num-1]);
835 
836  expect = mpc_malloc(i, l + 1);
837 
838  strcpy(expect, prefix);
839  for (j = 0; j < x->expected_num-2; j++) {
840  strcat(expect, x->expected[j]); strcat(expect, ", ");
841  }
842  strcat(expect, x->expected[x->expected_num-2]);
843  strcat(expect, " or ");
844  strcat(expect, x->expected[x->expected_num-1]);
845 
846  for (j = 0; j < x->expected_num; j++) { mpc_free(i, x->expected[j]); }
847 
848  x->expected_num = 1;
849  x->expected = mpc_realloc(i, x->expected, sizeof(char*) * x->expected_num);
850  x->expected[0] = expect;
851  return x;
852  }
853 
854  return NULL;
855 }
#define expect(expr, value)
Definition: lz4.c:170
static void * mpc_calloc(mpc_input_t *i, size_t n, size_t m)
Definition: mpc.c:257

References expect, i, mpc_calloc(), mpc_free(), mpc_malloc(), mpc_realloc(), NULL, prefix, and x.

Referenced by mpc_err_count(), and mpc_err_many1().

◆ mpc_err_string()

char* mpc_err_string ( mpc_err_t x)

Definition at line 630 of file mpc.c.

630  {
631 
632  int i;
633  int pos = 0;
634  int max = 1023;
635  char *buffer = calloc(1, 1024);
636 
637  if (x->failure) {
639  "%s: error: %s\n", x->filename, x->failure);
640  return buffer;
641  }
642 
644  "%s:%li:%li: error: expected ", x->filename, x->state.row+1, x->state.col+1);
645 
646  if (x->expected_num == 0) { mpc_err_string_cat(buffer, &pos, &max, "ERROR: NOTHING EXPECTED"); }
647  if (x->expected_num == 1) { mpc_err_string_cat(buffer, &pos, &max, "%s", x->expected[0]); }
648  if (x->expected_num >= 2) {
649 
650  for (i = 0; i < x->expected_num-2; i++) {
651  mpc_err_string_cat(buffer, &pos, &max, "%s, ", x->expected[i]);
652  }
653 
654  mpc_err_string_cat(buffer, &pos, &max, "%s or %s",
655  x->expected[x->expected_num-2],
656  x->expected[x->expected_num-1]);
657  }
658 
659  mpc_err_string_cat(buffer, &pos, &max, " at ");
661  mpc_err_string_cat(buffer, &pos, &max, "\n");
662 
663  return realloc(buffer, strlen(buffer) + 1);
664 }
int max
Definition: enough.c:225
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static const char * mpc_err_char_unescape(char c)
Definition: mpc.c:606
static void mpc_err_string_cat(char *buffer, int *pos, int *max, char const *fmt,...)
Definition: mpc.c:594
int pos
Definition: main.c:11

References calloc(), i, max, mpc_err_char_unescape(), mpc_err_string_cat(), pos, realloc(), and x.

Referenced by mpc_err_print_to(), mpc_re_mode(), and mpca_grammar_st().

◆ mpc_err_string_cat()

static void mpc_err_string_cat ( char *  buffer,
int pos,
int max,
char const fmt,
  ... 
)
static

Definition at line 594 of file mpc.c.

594  {
595  /* TODO: Error Checking on Length */
596  int left = ((*max) - (*pos));
597  va_list va;
598  va_start(va, fmt);
599  if (left < 0) { left = 0;}
600  (*pos) += vsprintf(buffer + (*pos), fmt, va);
601  va_end(va);
602 }

References pos, and vsprintf.

Referenced by mpc_err_string().

◆ mpc_escape()

mpc_parser_t* mpc_escape ( void  )

Definition at line 2014 of file mpc.c.

2014 { return mpc_and(2, mpcf_strfold, mpc_char('\\'), mpc_any(), free); }
mpc_parser_t * mpc_char(char c)
Definition: mpc.c:1747

References free(), mpc_and(), mpc_any(), mpc_char(), and mpcf_strfold().

Referenced by mpc_char_lit(), mpc_re_mode(), mpc_regex_lit(), and mpc_string_lit().

◆ mpc_expect()

◆ mpc_expectf()

mpc_parser_t* mpc_expectf ( mpc_parser_t a,
const char *  fmt,
  ... 
)

Definition at line 1719 of file mpc.c.

1719  {
1720  va_list va;
1721  char *buffer;
1722 
1724  p->type = MPC_TYPE_EXPECT;
1725 
1726  va_start(va, fmt);
1727  buffer = malloc(2048);
1728  vsprintf(buffer, fmt, va);
1729  va_end(va);
1730 
1731  buffer = realloc(buffer, strlen(buffer) + 1);
1732  p->data.expect.x = a;
1733  p->data.expect.m = buffer;
1734  return p;
1735 }

References a, malloc(), MPC_TYPE_EXPECT, mpc_undefined(), p, realloc(), and vsprintf.

Referenced by mpc_char(), mpc_noneof(), mpc_oneof(), mpc_range(), mpc_satisfy(), and mpc_string().

◆ mpc_export()

static void* mpc_export ( mpc_input_t i,
void *  p 
)
static

Definition at line 286 of file mpc.c.

286  {
287  char *q = NULL;
288  if (!mpc_mem_ptr(i, p)) { return p; }
289  q = malloc(sizeof(mpc_mem_t));
290  memcpy(q, p, sizeof(mpc_mem_t));
291  mpc_free(i, p);
292  return q;
293 }
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static int mpc_mem_ptr(mpc_input_t *i, void *p)
Definition: mpc.c:231
Definition: mpc.c:74

References i, malloc(), memcpy(), mpc_free(), mpc_mem_ptr(), NULL, and p.

Referenced by mpc_err_export(), mpc_parse_apply(), mpc_parse_apply_to(), mpc_parse_dtor(), mpc_parse_fold(), and mpc_parse_input().

◆ mpc_fail()

mpc_parser_t* mpc_fail ( const char *  m)

Definition at line 1616 of file mpc.c.

1616  {
1618  p->type = MPC_TYPE_FAIL;
1619  p->data.fail.m = malloc(strlen(m) + 1);
1620  strcpy(p->data.fail.m, m);
1621  return p;
1622 }

References regress::m, malloc(), MPC_TYPE_FAIL, mpc_undefined(), and p.

Referenced by mpcf_re_range().

◆ mpc_failf()

mpc_parser_t* mpc_failf ( const char *  fmt,
  ... 
)

Definition at line 1644 of file mpc.c.

1644  {
1645 
1646  va_list va;
1647  char *buffer;
1648 
1650  p->type = MPC_TYPE_FAIL;
1651 
1652  va_start(va, fmt);
1653  buffer = malloc(2048);
1654  vsprintf(buffer, fmt, va);
1655  va_end(va);
1656 
1657  buffer = realloc(buffer, strlen(buffer) + 1);
1658  p->data.fail.m = buffer;
1659  return p;
1660 
1661 }

References malloc(), MPC_TYPE_FAIL, mpc_undefined(), p, realloc(), and vsprintf.

Referenced by mpc_define(), mpc_re_mode(), mpca_grammar_find_parser(), and mpca_grammar_st().

◆ mpc_float()

mpc_parser_t* mpc_float ( void  )

Definition at line 2052 of file mpc.c.

2052  {
2053  return mpc_expect(mpc_apply(mpc_real(), mpcf_float), "float");
2054 }
mpc_parser_t * mpc_real(void)
Definition: mpc.c:2034
mpc_val_t * mpcf_float(mpc_val_t *x)
Definition: mpc.c:2455

References mpc_apply(), mpc_expect(), mpc_real(), and mpcf_float().

◆ mpc_free()

static void mpc_free ( mpc_input_t i,
void *  p 
)
static

Definition at line 263 of file mpc.c.

263  {
264  size_t j;
265  if (!mpc_mem_ptr(i, p)) { free(p); return; }
266  j = ((size_t)(((char*)p) - ((char*)i->mem))) / sizeof(mpc_mem_t);
267  i->mem_full[j] = 0;
268 }
int size_t
Definition: sftypes.h:40

References free(), i, mpc_mem_ptr(), and p.

Referenced by mpc_err_count(), mpc_err_delete_internal(), mpc_err_repeat(), mpc_export(), mpc_parse_dtor(), mpc_parse_run(), mpc_realloc(), mpcf_input_free(), mpcf_input_nth_free(), mpcf_input_state_ast(), mpcf_input_str_ast(), and mpcf_input_strfold().

◆ mpc_hex()

mpc_parser_t* mpc_hex ( void  )

Definition at line 2030 of file mpc.c.

2030 { return mpc_expect(mpc_apply(mpc_hexdigits(), mpcf_hex), "hexadecimal"); }
mpc_val_t * mpcf_hex(mpc_val_t *x)
Definition: mpc.c:2441
mpc_parser_t * mpc_hexdigits(void)
Definition: mpc.c:2020

References mpc_apply(), mpc_expect(), mpc_hexdigits(), and mpcf_hex().

Referenced by mpc_number().

◆ mpc_hexdigit()

mpc_parser_t* mpc_hexdigit ( void  )

Definition at line 2017 of file mpc.c.

2017 { return mpc_expect(mpc_oneof("0123456789ABCDEFabcdef"), "hex digit"); }

References mpc_expect(), and mpc_oneof().

Referenced by mpc_hexdigits().

◆ mpc_hexdigits()

mpc_parser_t* mpc_hexdigits ( void  )

Definition at line 2020 of file mpc.c.

2020 { return mpc_expect(mpc_many1(mpcf_strfold, mpc_hexdigit()), "hex digits"); }
mpc_parser_t * mpc_hexdigit(void)
Definition: mpc.c:2017

References mpc_expect(), mpc_hexdigit(), mpc_many1(), and mpcf_strfold().

Referenced by mpc_hex().

◆ mpc_ident()

mpc_parser_t* mpc_ident ( void  )

Definition at line 2070 of file mpc.c.

2070  {
2071  mpc_parser_t *p0, *p1;
2072  p0 = mpc_or(2, mpc_alpha(), mpc_underscore());
2074  return mpc_and(2, mpcf_strfold, p0, p1, free);
2075 }
mpc_parser_t * mpc_many(mpc_fold_t f, mpc_parser_t *a)
Definition: mpc.c:1902
mpc_parser_t * mpc_alphanum(void)
Definition: mpc.c:2027

References free(), mpc_alpha(), mpc_alphanum(), mpc_and(), mpc_many(), mpc_or(), mpc_underscore(), and mpcf_strfold().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_input_anchor()

static int mpc_input_anchor ( mpc_input_t i,
int(*)(char, char)  f,
char **  o 
)
static

Definition at line 543 of file mpc.c.

543  {
544  *o = NULL;
545  return f(i->last, mpc_input_peekc(i));
546 }

References f, i, mpc_input_peekc(), and NULL.

Referenced by mpc_parse_run().

◆ mpc_input_any()

static int mpc_input_any ( mpc_input_t i,
char **  o 
)
static

Definition at line 482 of file mpc.c.

482  {
483  char x;
484  if (mpc_input_terminated(i)) { return 0; }
485  x = mpc_input_getc(i);
486  return mpc_input_success(i, x, o);
487 }
static int mpc_input_terminated(mpc_input_t *i)
Definition: mpc.c:431
static char mpc_input_getc(mpc_input_t *i)
Definition: mpc.c:370
static int mpc_input_success(mpc_input_t *i, char c, char **o)
Definition: mpc.c:455

References i, mpc_input_getc(), mpc_input_success(), mpc_input_terminated(), and x.

Referenced by mpc_parse_run().

◆ mpc_input_backtrack_disable()

static void mpc_input_backtrack_disable ( mpc_input_t i)
static

Definition at line 295 of file mpc.c.

295 { i->backtrack--; }

References i.

Referenced by mpc_parse_run().

◆ mpc_input_backtrack_enable()

static void mpc_input_backtrack_enable ( mpc_input_t i)
static

Definition at line 296 of file mpc.c.

296 { i->backtrack++; }

References i.

Referenced by mpc_parse_run().

◆ mpc_input_buffer_get()

static char mpc_input_buffer_get ( mpc_input_t i)
static

Definition at line 366 of file mpc.c.

366  {
367  return i->buffer[i->state.pos - i->marks[0].pos];
368 }

References i.

Referenced by mpc_input_getc(), and mpc_input_peekc().

◆ mpc_input_buffer_in_range()

static int mpc_input_buffer_in_range ( mpc_input_t i)
static

Definition at line 362 of file mpc.c.

362  {
363  return i->state.pos < (long)(strlen(i->buffer) + i->marks[0].pos);
364 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags long
Definition: sflib.h:79

References i, and long.

Referenced by mpc_input_failure(), mpc_input_getc(), mpc_input_peekc(), and mpc_input_success().

◆ mpc_input_char()

static int mpc_input_char ( mpc_input_t i,
char  c,
char **  o 
)
static

Definition at line 489 of file mpc.c.

489  {
490  char x;
491  if (mpc_input_terminated(i)) { return 0; }
492  x = mpc_input_getc(i);
493  return x == c ? mpc_input_success(i, x, o) : mpc_input_failure(i, x);
494 }
static int mpc_input_failure(mpc_input_t *i, char c)
Definition: mpc.c:435

References c, i, mpc_input_failure(), mpc_input_getc(), mpc_input_success(), mpc_input_terminated(), and x.

Referenced by mpc_input_string(), and mpc_parse_run().

◆ mpc_input_delete()

static void mpc_input_delete ( mpc_input_t i)
static

Definition at line 219 of file mpc.c.

219  {
220 
221  free(i->filename);
222 
223  if (i->type == MPC_INPUT_STRING) { free(i->string); }
224  if (i->type == MPC_INPUT_PIPE) { free(i->buffer); }
225 
226  free(i->marks);
227  free(i->lasts);
228  free(i);
229 }

References free(), i, MPC_INPUT_PIPE, and MPC_INPUT_STRING.

Referenced by mpc_nparse(), mpc_parse(), mpc_parse_file(), mpc_parse_pipe(), mpca_lang(), mpca_lang_contents(), mpca_lang_file(), and mpca_lang_pipe().

◆ mpc_input_eoi()

static int mpc_input_eoi ( mpc_input_t i,
char **  o 
)
static

Definition at line 553 of file mpc.c.

553  {
554  *o = NULL;
555  if (i->state.term) {
556  return 0;
557  } else if (mpc_input_terminated(i)) {
558  i->state.term = 1;
559  return 1;
560  } else {
561  return 0;
562  }
563 }

References i, mpc_input_terminated(), and NULL.

Referenced by mpc_parse_run().

◆ mpc_input_failure()

static int mpc_input_failure ( mpc_input_t i,
char  c 
)
static

Definition at line 435 of file mpc.c.

435  {
436 
437  switch (i->type) {
438  case MPC_INPUT_STRING: { break; }
439  case MPC_INPUT_FILE: fseek(i->file, -1, SEEK_CUR); { break; }
440  case MPC_INPUT_PIPE: {
441 
442  if (!i->buffer) { ungetc(c, i->file); break; }
443 
444  if (i->buffer && mpc_input_buffer_in_range(i)) {
445  break;
446  } else {
447  ungetc(c, i->file);
448  }
449  }
450  default: { break; }
451  }
452  return 0;
453 }
static int mpc_input_buffer_in_range(mpc_input_t *i)
Definition: mpc.c:362
#define SEEK_CUR
Definition: zip.c:80

References c, i, mpc_input_buffer_in_range(), MPC_INPUT_FILE, MPC_INPUT_PIPE, MPC_INPUT_STRING, and SEEK_CUR.

Referenced by mpc_input_char(), mpc_input_noneof(), mpc_input_oneof(), mpc_input_range(), and mpc_input_satisfy().

◆ mpc_input_getc()

static char mpc_input_getc ( mpc_input_t i)
static

Definition at line 370 of file mpc.c.

370  {
371 
372  char c = '\0';
373 
374  switch (i->type) {
375 
376  case MPC_INPUT_STRING: return i->string[i->state.pos];
377  case MPC_INPUT_FILE: c = fgetc(i->file); return c;
378  case MPC_INPUT_PIPE:
379 
380  if (!i->buffer) { c = getc(i->file); return c; }
381 
382  if (i->buffer && mpc_input_buffer_in_range(i)) {
384  return c;
385  } else {
386  c = getc(i->file);
387  return c;
388  }
389 
390  default: return c;
391  }
392 }
static char mpc_input_buffer_get(mpc_input_t *i)
Definition: mpc.c:366

References c, i, mpc_input_buffer_get(), mpc_input_buffer_in_range(), MPC_INPUT_FILE, MPC_INPUT_PIPE, and MPC_INPUT_STRING.

Referenced by mpc_input_any(), mpc_input_char(), mpc_input_noneof(), mpc_input_oneof(), mpc_input_range(), and mpc_input_satisfy().

◆ mpc_input_mark()

static void mpc_input_mark ( mpc_input_t i)
static

Definition at line 301 of file mpc.c.

301  {
302 
303  if (i->backtrack < 1) { return; }
304 
305  i->marks_num++;
306 
307  if (i->marks_num > i->marks_slots) {
308  i->marks_slots = i->marks_num + i->marks_num / 2;
309  i->marks = realloc(i->marks, sizeof(mpc_state_t) * i->marks_slots);
310  i->lasts = realloc(i->lasts, sizeof(char) * i->marks_slots);
311  }
312 
313  i->marks[i->marks_num-1] = i->state;
314  i->lasts[i->marks_num-1] = i->last;
315 
316  if (i->type == MPC_INPUT_PIPE && i->marks_num == 1) {
317  i->buffer = calloc(1, 1);
318  }
319 
320 }

References calloc(), i, MPC_INPUT_PIPE, and realloc().

Referenced by mpc_input_string(), and mpc_parse_run().

◆ mpc_input_new_file()

static mpc_input_t* mpc_input_new_file ( const char *  filename,
FILE *  file 
)
static

Definition at line 192 of file mpc.c.

192  {
193 
194  mpc_input_t *i = malloc(sizeof(mpc_input_t));
195 
196  i->filename = malloc(strlen(filename) + 1);
197  strcpy(i->filename, filename);
198  i->type = MPC_INPUT_FILE;
199  i->state = mpc_state_new();
200 
201  i->string = NULL;
202  i->buffer = NULL;
203  i->file = file;
204 
205  i->suppress = 0;
206  i->backtrack = 1;
207  i->marks_num = 0;
208  i->marks_slots = MPC_INPUT_MARKS_MIN;
209  i->marks = malloc(sizeof(mpc_state_t) * i->marks_slots);
210  i->lasts = malloc(sizeof(char) * i->marks_slots);
211  i->last = '\0';
212 
213  i->mem_index = 0;
214  memset(i->mem_full, 0, sizeof(char) * MPC_INPUT_MEM_NUM);
215 
216  return i;
217 }
static int file
Definition: z80asm.c:58

References file, i, malloc(), memset(), MPC_INPUT_FILE, MPC_INPUT_MARKS_MIN, MPC_INPUT_MEM_NUM, mpc_state_new(), and NULL.

Referenced by mpc_parse_file(), mpca_lang_contents(), and mpca_lang_file().

◆ mpc_input_new_nstring()

static mpc_input_t* mpc_input_new_nstring ( const char *  filename,
const char *  string,
size_t  length 
)
static

Definition at line 132 of file mpc.c.

132  {
133 
134  mpc_input_t *i = malloc(sizeof(mpc_input_t));
135 
136  i->filename = malloc(strlen(filename) + 1);
137  strcpy(i->filename, filename);
138  i->type = MPC_INPUT_STRING;
139 
140  i->state = mpc_state_new();
141 
142  i->string = malloc(length + 1);
143  strncpy(i->string, string, length);
144  i->string[length] = '\0';
145  i->buffer = NULL;
146  i->file = NULL;
147 
148  i->suppress = 0;
149  i->backtrack = 1;
150  i->marks_num = 0;
151  i->marks_slots = MPC_INPUT_MARKS_MIN;
152  i->marks = malloc(sizeof(mpc_state_t) * i->marks_slots);
153  i->lasts = malloc(sizeof(char) * i->marks_slots);
154  i->last = '\0';
155 
156  i->mem_index = 0;
157  memset(i->mem_full, 0, sizeof(char) * MPC_INPUT_MEM_NUM);
158 
159  return i;
160 
161 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133

References i, length, malloc(), memset(), MPC_INPUT_MARKS_MIN, MPC_INPUT_MEM_NUM, MPC_INPUT_STRING, mpc_state_new(), and NULL.

Referenced by mpc_nparse().

◆ mpc_input_new_pipe()

static mpc_input_t* mpc_input_new_pipe ( const char *  filename,
FILE *  pipe 
)
static

Definition at line 163 of file mpc.c.

163  {
164 
165  mpc_input_t *i = malloc(sizeof(mpc_input_t));
166 
167  i->filename = malloc(strlen(filename) + 1);
168  strcpy(i->filename, filename);
169 
170  i->type = MPC_INPUT_PIPE;
171  i->state = mpc_state_new();
172 
173  i->string = NULL;
174  i->buffer = NULL;
175  i->file = pipe;
176 
177  i->suppress = 0;
178  i->backtrack = 1;
179  i->marks_num = 0;
180  i->marks_slots = MPC_INPUT_MARKS_MIN;
181  i->marks = malloc(sizeof(mpc_state_t) * i->marks_slots);
182  i->lasts = malloc(sizeof(char) * i->marks_slots);
183  i->last = '\0';
184 
185  i->mem_index = 0;
186  memset(i->mem_full, 0, sizeof(char) * MPC_INPUT_MEM_NUM);
187 
188  return i;
189 
190 }
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname pipe
Definition: sflib.h:73

References i, malloc(), memset(), MPC_INPUT_MARKS_MIN, MPC_INPUT_MEM_NUM, MPC_INPUT_PIPE, mpc_state_new(), NULL, and pipe.

Referenced by mpc_parse_pipe(), and mpca_lang_pipe().

◆ mpc_input_new_string()

static mpc_input_t* mpc_input_new_string ( const char *  filename,
const char *  string 
)
static

Definition at line 103 of file mpc.c.

103  {
104 
105  mpc_input_t *i = malloc(sizeof(mpc_input_t));
106 
107  i->filename = malloc(strlen(filename) + 1);
108  strcpy(i->filename, filename);
109  i->type = MPC_INPUT_STRING;
110 
111  i->state = mpc_state_new();
112 
113  i->string = malloc(strlen(string) + 1);
114  strcpy(i->string, string);
115  i->buffer = NULL;
116  i->file = NULL;
117 
118  i->suppress = 0;
119  i->backtrack = 1;
120  i->marks_num = 0;
121  i->marks_slots = MPC_INPUT_MARKS_MIN;
122  i->marks = malloc(sizeof(mpc_state_t) * i->marks_slots);
123  i->lasts = malloc(sizeof(char) * i->marks_slots);
124  i->last = '\0';
125 
126  i->mem_index = 0;
127  memset(i->mem_full, 0, sizeof(char) * MPC_INPUT_MEM_NUM);
128 
129  return i;
130 }

References i, malloc(), memset(), MPC_INPUT_MARKS_MIN, MPC_INPUT_MEM_NUM, MPC_INPUT_STRING, mpc_state_new(), and NULL.

Referenced by mpc_parse(), and mpca_lang().

◆ mpc_input_noneof()

static int mpc_input_noneof ( mpc_input_t i,
const char *  c,
char **  o 
)
static

Definition at line 510 of file mpc.c.

510  {
511  char x;
512  if (mpc_input_terminated(i)) { return 0; }
513  x = mpc_input_getc(i);
514  return strchr(c, x) == 0 ? mpc_input_success(i, x, o) : mpc_input_failure(i, x);
515 }

References c, i, mpc_input_failure(), mpc_input_getc(), mpc_input_success(), mpc_input_terminated(), and x.

Referenced by mpc_parse_run().

◆ mpc_input_oneof()

static int mpc_input_oneof ( mpc_input_t i,
const char *  c,
char **  o 
)
static

Definition at line 503 of file mpc.c.

503  {
504  char x;
505  if (mpc_input_terminated(i)) { return 0; }
506  x = mpc_input_getc(i);
507  return strchr(c, x) != 0 ? mpc_input_success(i, x, o) : mpc_input_failure(i, x);
508 }

References c, i, mpc_input_failure(), mpc_input_getc(), mpc_input_success(), mpc_input_terminated(), and x.

Referenced by mpc_parse_run().

◆ mpc_input_peekc()

static char mpc_input_peekc ( mpc_input_t i)
static

Definition at line 394 of file mpc.c.

394  {
395 
396  char c = '\0';
397 
398  switch (i->type) {
399  case MPC_INPUT_STRING: return i->string[i->state.pos];
400  case MPC_INPUT_FILE:
401 
402  c = fgetc(i->file);
403  if (feof(i->file)) { return '\0'; }
404 
405  fseek(i->file, -1, SEEK_CUR);
406  return c;
407 
408  case MPC_INPUT_PIPE:
409 
410  if (!i->buffer) {
411  c = getc(i->file);
412  if (feof(i->file)) { return '\0'; }
413  ungetc(c, i->file);
414  return c;
415  }
416 
417  if (i->buffer && mpc_input_buffer_in_range(i)) {
418  return mpc_input_buffer_get(i);
419  } else {
420  c = getc(i->file);
421  if (feof(i->file)) { return '\0'; }
422  ungetc(c, i->file);
423  return c;
424  }
425 
426  default: return c;
427  }
428 
429 }

References c, i, mpc_input_buffer_get(), mpc_input_buffer_in_range(), MPC_INPUT_FILE, MPC_INPUT_PIPE, MPC_INPUT_STRING, and SEEK_CUR.

Referenced by mpc_err_new(), mpc_input_anchor(), and mpc_input_terminated().

◆ mpc_input_range()

static int mpc_input_range ( mpc_input_t i,
char  c,
char  d,
char **  o 
)
static

Definition at line 496 of file mpc.c.

496  {
497  char x;
498  if (mpc_input_terminated(i)) { return 0; }
499  x = mpc_input_getc(i);
500  return x >= c && x <= d ? mpc_input_success(i, x, o) : mpc_input_failure(i, x);
501 }

References c, d, i, mpc_input_failure(), mpc_input_getc(), mpc_input_success(), mpc_input_terminated(), and x.

Referenced by mpc_parse_run().

◆ mpc_input_rewind()

static void mpc_input_rewind ( mpc_input_t i)
static

Definition at line 348 of file mpc.c.

348  {
349 
350  if (i->backtrack < 1) { return; }
351 
352  i->state = i->marks[i->marks_num-1];
353  i->last = i->lasts[i->marks_num-1];
354 
355  if (i->type == MPC_INPUT_FILE) {
356  fseek(i->file, i->state.pos, SEEK_SET);
357  }
358 
360 }
static void mpc_input_unmark(mpc_input_t *i)
Definition: mpc.c:322
#define SEEK_SET
Definition: zip.c:88

References i, MPC_INPUT_FILE, mpc_input_unmark(), and SEEK_SET.

Referenced by mpc_input_string(), and mpc_parse_run().

◆ mpc_input_satisfy()

static int mpc_input_satisfy ( mpc_input_t i,
int(*)(char)  cond,
char **  o 
)
static

Definition at line 517 of file mpc.c.

517  {
518  char x;
519  if (mpc_input_terminated(i)) { return 0; }
520  x = mpc_input_getc(i);
521  return cond(x) ? mpc_input_success(i, x, o) : mpc_input_failure(i, x);
522 }
#define cond(bop, top, mask, flags)

References cond, i, mpc_input_failure(), mpc_input_getc(), mpc_input_success(), mpc_input_terminated(), and x.

Referenced by mpc_parse_run().

◆ mpc_input_soi()

static int mpc_input_soi ( mpc_input_t i,
char **  o 
)
static

Definition at line 548 of file mpc.c.

548  {
549  *o = NULL;
550  return i->last == '\0';
551 }

References i, and NULL.

Referenced by mpc_parse_run().

◆ mpc_input_state_copy()

static mpc_state_t* mpc_input_state_copy ( mpc_input_t i)
static

Definition at line 565 of file mpc.c.

565  {
566  mpc_state_t *r = mpc_malloc(i, sizeof(mpc_state_t));
567  memcpy(r, &i->state, sizeof(mpc_state_t));
568  return r;
569 }

References i, memcpy(), mpc_malloc(), and r.

Referenced by mpc_parse_run().

◆ mpc_input_string()

static int mpc_input_string ( mpc_input_t i,
const char *  c,
char **  o 
)
static

Definition at line 524 of file mpc.c.

524  {
525 
526  const char *x = c;
527 
528  mpc_input_mark(i);
529  while (*x) {
530  if (!mpc_input_char(i, *x, NULL)) {
532  return 0;
533  }
534  x++;
535  }
537 
538  *o = mpc_malloc(i, strlen(c) + 1);
539  strcpy(*o, c);
540  return 1;
541 }
static void mpc_input_mark(mpc_input_t *i)
Definition: mpc.c:301
static int mpc_input_char(mpc_input_t *i, char c, char **o)
Definition: mpc.c:489
static void mpc_input_rewind(mpc_input_t *i)
Definition: mpc.c:348

References c, i, mpc_input_char(), mpc_input_mark(), mpc_input_rewind(), mpc_input_unmark(), mpc_malloc(), NULL, and x.

Referenced by mpc_parse_run().

◆ mpc_input_success()

static int mpc_input_success ( mpc_input_t i,
char  c,
char **  o 
)
static

Definition at line 455 of file mpc.c.

455  {
456 
457  if (i->type == MPC_INPUT_PIPE
458  && i->buffer && !mpc_input_buffer_in_range(i)) {
459  i->buffer = realloc(i->buffer, strlen(i->buffer) + 2);
460  i->buffer[strlen(i->buffer) + 1] = '\0';
461  i->buffer[strlen(i->buffer) + 0] = c;
462  }
463 
464  i->last = c;
465  i->state.pos++;
466  i->state.col++;
467 
468  if (c == '\n') {
469  i->state.col = 0;
470  i->state.row++;
471  }
472 
473  if (o) {
474  (*o) = mpc_malloc(i, 2);
475  (*o)[0] = c;
476  (*o)[1] = '\0';
477  }
478 
479  return 1;
480 }

References c, i, mpc_input_buffer_in_range(), MPC_INPUT_PIPE, mpc_malloc(), and realloc().

Referenced by mpc_input_any(), mpc_input_char(), mpc_input_noneof(), mpc_input_oneof(), mpc_input_range(), and mpc_input_satisfy().

◆ mpc_input_suppress_disable()

static void mpc_input_suppress_disable ( mpc_input_t i)
static

Definition at line 298 of file mpc.c.

298 { i->suppress--; }

References i.

Referenced by mpc_parse_run().

◆ mpc_input_suppress_enable()

static void mpc_input_suppress_enable ( mpc_input_t i)
static

Definition at line 299 of file mpc.c.

299 { i->suppress++; }

References i.

Referenced by mpc_parse_run().

◆ mpc_input_terminated()

static int mpc_input_terminated ( mpc_input_t i)
static

Definition at line 431 of file mpc.c.

431  {
432  return mpc_input_peekc(i) == '\0';
433 }

References i, and mpc_input_peekc().

Referenced by mpc_input_any(), mpc_input_char(), mpc_input_eoi(), mpc_input_noneof(), mpc_input_oneof(), mpc_input_range(), and mpc_input_satisfy().

◆ mpc_input_unmark()

static void mpc_input_unmark ( mpc_input_t i)
static

Definition at line 322 of file mpc.c.

322  {
323  int j;
324 
325  if (i->backtrack < 1) { return; }
326 
327  i->marks_num--;
328 
329  if (i->marks_slots > i->marks_num + i->marks_num / 2
330  && i->marks_slots > MPC_INPUT_MARKS_MIN) {
331  i->marks_slots =
332  i->marks_num > MPC_INPUT_MARKS_MIN ?
333  i->marks_num : MPC_INPUT_MARKS_MIN;
334  i->marks = realloc(i->marks, sizeof(mpc_state_t) * i->marks_slots);
335  i->lasts = realloc(i->lasts, sizeof(char) * i->marks_slots);
336  }
337 
338  if (i->type == MPC_INPUT_PIPE && i->marks_num == 0) {
339  for (j = strlen(i->buffer) - 1; j >= 0; j--)
340  ungetc(i->buffer[j], i->file);
341 
342  free(i->buffer);
343  i->buffer = NULL;
344  }
345 
346 }

References free(), i, MPC_INPUT_MARKS_MIN, MPC_INPUT_PIPE, NULL, and realloc().

Referenced by mpc_input_rewind(), mpc_input_string(), and mpc_parse_run().

◆ mpc_int()

mpc_parser_t* mpc_int ( void  )

Definition at line 2029 of file mpc.c.

2029 { return mpc_expect(mpc_apply(mpc_digits(), mpcf_int), "integer"); }
mpc_parser_t * mpc_digits(void)
Definition: mpc.c:2019
mpc_val_t * mpcf_int(mpc_val_t *x)
Definition: mpc.c:2434

References mpc_apply(), mpc_digits(), mpc_expect(), and mpcf_int().

Referenced by mpc_number(), mpc_re_mode(), mpca_grammar_st(), and mpca_lang_st().

◆ mpc_lift()

mpc_parser_t* mpc_lift ( mpc_ctor_t  lf)

Definition at line 1670 of file mpc.c.

1670  {
1672  p->type = MPC_TYPE_LIFT;
1673  p->data.lift.lf = lf;
1674  return p;
1675 }

References MPC_TYPE_LIFT, mpc_undefined(), and p.

Referenced by mpc_re_escape_char(), mpcf_re_and(), and mpcf_re_escape().

◆ mpc_lift_val()

mpc_parser_t* mpc_lift_val ( mpc_val_t x)

Definition at line 1663 of file mpc.c.

1663  {
1665  p->type = MPC_TYPE_LIFT_VAL;
1666  p->data.lift.x = x;
1667  return p;
1668 }

References MPC_TYPE_LIFT_VAL, mpc_undefined(), p, and x.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_lower()

mpc_parser_t* mpc_lower ( void  )

Definition at line 2023 of file mpc.c.

2023 { return mpc_expect(mpc_oneof("abcdefghijklmnopqrstuvwxyz"), "lowercase letter"); }

References mpc_expect(), and mpc_oneof().

◆ mpc_malloc()

static void* mpc_malloc ( mpc_input_t i,
size_t  n 
)
static

Definition at line 237 of file mpc.c.

237  {
238  size_t j;
239  char *p;
240 
241  if (n > sizeof(mpc_mem_t)) { return malloc(n); }
242 
243  j = i->mem_index;
244  do {
245  if (!i->mem_full[i->mem_index]) {
246  p = (void*)(i->mem + i->mem_index);
247  i->mem_full[i->mem_index] = 1;
248  i->mem_index = (i->mem_index+1) % MPC_INPUT_MEM_NUM;
249  return p;
250  }
251  i->mem_index = (i->mem_index+1) % MPC_INPUT_MEM_NUM;
252  } while (j != i->mem_index);
253 
254  return malloc(n);
255 }

References i, malloc(), MPC_INPUT_MEM_NUM, n, and p.

Referenced by mpc_calloc(), mpc_err_add_expected(), mpc_err_count(), mpc_err_fail(), mpc_err_new(), mpc_err_or(), mpc_err_repeat(), mpc_input_state_copy(), mpc_input_string(), mpc_input_success(), and mpc_parse_run().

◆ mpc_many()

mpc_parser_t* mpc_many ( mpc_fold_t  f,
mpc_parser_t a 
)

Definition at line 1902 of file mpc.c.

1902  {
1904  p->type = MPC_TYPE_MANY;
1905  p->data.repeat.x = a;
1906  p->data.repeat.f = f;
1907  return p;
1908 }

References a, f, MPC_TYPE_MANY, mpc_undefined(), and p.

Referenced by mpc_ident(), mpc_re_mode(), mpc_regex_lit(), mpc_string_lit(), mpc_whitespaces(), mpca_grammar_st(), mpca_lang_st(), mpca_many(), and mpcf_re_repeat().

◆ mpc_many1()

mpc_parser_t* mpc_many1 ( mpc_fold_t  f,
mpc_parser_t a 
)

Definition at line 1910 of file mpc.c.

1910  {
1912  p->type = MPC_TYPE_MANY1;
1913  p->data.repeat.x = a;
1914  p->data.repeat.f = f;
1915  return p;
1916 }

References a, f, MPC_TYPE_MANY1, mpc_undefined(), and p.

Referenced by mpc_digits(), mpc_hexdigits(), mpc_octdigits(), mpca_grammar_st(), mpca_lang_st(), mpca_many1(), and mpcf_re_repeat().

◆ mpc_maybe()

mpc_parser_t* mpc_maybe ( mpc_parser_t a)

Definition at line 1898 of file mpc.c.

1898  {
1899  return mpc_maybe_lift(a, mpcf_ctor_null);
1900 }
mpc_val_t * mpcf_ctor_null(void)
Definition: mpc.c:2430
mpc_parser_t * mpc_maybe_lift(mpc_parser_t *a, mpc_ctor_t lf)
Definition: mpc.c:1890

References a, mpc_maybe_lift(), and mpcf_ctor_null().

Referenced by mpc_re_mode(), mpca_grammar_st(), mpca_lang_st(), and mpca_maybe().

◆ mpc_maybe_lift()

mpc_parser_t* mpc_maybe_lift ( mpc_parser_t a,
mpc_ctor_t  lf 
)

Definition at line 1890 of file mpc.c.

1890  {
1892  p->type = MPC_TYPE_MAYBE;
1893  p->data.not.x = a;
1894  p->data.not.lf = lf;
1895  return p;
1896 }

References a, MPC_TYPE_MAYBE, mpc_undefined(), and p.

Referenced by mpc_maybe(), mpc_real(), and mpcf_re_repeat().

◆ mpc_mem_ptr()

static int mpc_mem_ptr ( mpc_input_t i,
void *  p 
)
static

Definition at line 231 of file mpc.c.

231  {
232  return
233  (char*)p >= (char*)(i->mem) &&
234  (char*)p < (char*)(i->mem) + (MPC_INPUT_MEM_NUM * sizeof(mpc_mem_t));
235 }

References i, MPC_INPUT_MEM_NUM, and p.

Referenced by mpc_export(), mpc_free(), and mpc_realloc().

◆ mpc_new()

mpc_parser_t* mpc_new ( const char *  name)

Definition at line 1480 of file mpc.c.

1480  {
1482  p->retained = 1;
1483  p->name = realloc(p->name, strlen(name) + 1);
1484  strcpy(p->name, name);
1485  return p;
1486 }
Definition: z80asm.h:102

References mpc_undefined(), p, and realloc().

Referenced by main(), mpc_re_mode(), mpca_grammar_st(), and mpca_lang_st().

◆ mpc_newline()

mpc_parser_t* mpc_newline ( void  )

Definition at line 2012 of file mpc.c.

2012 { return mpc_expect(mpc_char('\n'), "newline"); }

References mpc_char(), and mpc_expect().

Referenced by mpcf_re_escape().

◆ mpc_nodecount_unretained()

static int mpc_nodecount_unretained ( mpc_parser_t p,
int  force 
)
static

Definition at line 3847 of file mpc.c.

3847  {
3848 
3849  int i, total;
3850 
3851  if (p->retained && !force) { return 0; }
3852 
3853  if (p->type == MPC_TYPE_EXPECT) { return 1 + mpc_nodecount_unretained(p->data.expect.x, 0); }
3854 
3855  if (p->type == MPC_TYPE_APPLY) { return 1 + mpc_nodecount_unretained(p->data.apply.x, 0); }
3856  if (p->type == MPC_TYPE_APPLY_TO) { return 1 + mpc_nodecount_unretained(p->data.apply_to.x, 0); }
3857  if (p->type == MPC_TYPE_PREDICT) { return 1 + mpc_nodecount_unretained(p->data.predict.x, 0); }
3858 
3859  if (p->type == MPC_TYPE_CHECK) { return 1 + mpc_nodecount_unretained(p->data.check.x, 0); }
3860  if (p->type == MPC_TYPE_CHECK_WITH) { return 1 + mpc_nodecount_unretained(p->data.check_with.x, 0); }
3861 
3862  if (p->type == MPC_TYPE_NOT) { return 1 + mpc_nodecount_unretained(p->data.not.x, 0); }
3863  if (p->type == MPC_TYPE_MAYBE) { return 1 + mpc_nodecount_unretained(p->data.not.x, 0); }
3864 
3865  if (p->type == MPC_TYPE_MANY) { return 1 + mpc_nodecount_unretained(p->data.repeat.x, 0); }
3866  if (p->type == MPC_TYPE_MANY1) { return 1 + mpc_nodecount_unretained(p->data.repeat.x, 0); }
3867  if (p->type == MPC_TYPE_COUNT) { return 1 + mpc_nodecount_unretained(p->data.repeat.x, 0); }
3868 
3869  if (p->type == MPC_TYPE_OR) {
3870  total = 1;
3871  for(i = 0; i < p->data.or.n; i++) {
3872  total += mpc_nodecount_unretained(p->data.or.xs[i], 0);
3873  }
3874  return total;
3875  }
3876 
3877  if (p->type == MPC_TYPE_AND) {
3878  total = 1;
3879  for(i = 0; i < p->data.and.n; i++) {
3880  total += mpc_nodecount_unretained(p->data.and.xs[i], 0);
3881  }
3882  return total;
3883  }
3884 
3885  return 1;
3886 
3887 }
static int mpc_nodecount_unretained(mpc_parser_t *p, int force)
Definition: mpc.c:3847

References i, MPC_TYPE_AND, MPC_TYPE_APPLY, MPC_TYPE_APPLY_TO, MPC_TYPE_CHECK, MPC_TYPE_CHECK_WITH, MPC_TYPE_COUNT, MPC_TYPE_EXPECT, MPC_TYPE_MANY, MPC_TYPE_MANY1, MPC_TYPE_MAYBE, MPC_TYPE_NOT, MPC_TYPE_OR, MPC_TYPE_PREDICT, and p.

Referenced by mpc_stats().

◆ mpc_noneof()

mpc_parser_t* mpc_noneof ( const char *  s)

Definition at line 1770 of file mpc.c.

1770  {
1772  p->type = MPC_TYPE_NONEOF;
1773  p->data.string.x = malloc(strlen(s) + 1);
1774  strcpy(p->data.string.x, s);
1775  return mpc_expectf(p, "none of '%s'", s);
1776 
1777 }

References malloc(), mpc_expectf(), MPC_TYPE_NONEOF, mpc_undefined(), p, and s.

Referenced by mpc_re_mode(), mpc_regex_lit(), mpc_string_lit(), mpcf_re_escape(), and mpcf_re_range().

◆ mpc_not()

mpc_parser_t* mpc_not ( mpc_parser_t a,
mpc_dtor_t  da 
)

Definition at line 1886 of file mpc.c.

1886  {
1887  return mpc_not_lift(a, da, mpcf_ctor_null);
1888 }
mpc_parser_t * mpc_not_lift(mpc_parser_t *a, mpc_dtor_t da, mpc_ctor_t lf)
Definition: mpc.c:1877

References a, mpc_not_lift(), and mpcf_ctor_null().

Referenced by mpca_not().

◆ mpc_not_lift()

mpc_parser_t* mpc_not_lift ( mpc_parser_t a,
mpc_dtor_t  da,
mpc_ctor_t  lf 
)

Definition at line 1877 of file mpc.c.

1877  {
1879  p->type = MPC_TYPE_NOT;
1880  p->data.not.x = a;
1881  p->data.not.dx = da;
1882  p->data.not.lf = lf;
1883  return p;
1884 }

References a, MPC_TYPE_NOT, mpc_undefined(), and p.

Referenced by mpc_not(), and mpc_re_escape_char().

◆ mpc_nparse()

int mpc_nparse ( const char *  filename,
const char *  string,
size_t  length,
mpc_parser_t p,
mpc_result_t r 
)

Definition at line 1329 of file mpc.c.

1329  {
1330  int x;
1332  x = mpc_parse_input(i, p, r);
1334  return x;
1335 }
static void mpc_input_delete(mpc_input_t *i)
Definition: mpc.c:219
static mpc_input_t * mpc_input_new_nstring(const char *filename, const char *string, size_t length)
Definition: mpc.c:132
int mpc_parse_input(mpc_input_t *i, mpc_parser_t *p, mpc_result_t *r)
Definition: mpc.c:1307

References i, length, mpc_input_delete(), mpc_input_new_nstring(), mpc_parse_input(), p, r, and x.

◆ mpc_number()

mpc_parser_t* mpc_number ( void  )

Definition at line 2032 of file mpc.c.

2032 { return mpc_expect(mpc_or(3, mpc_int(), mpc_hex(), mpc_oct()), "number"); }
mpc_parser_t * mpc_hex(void)
Definition: mpc.c:2030
mpc_parser_t * mpc_int(void)
Definition: mpc.c:2029
mpc_parser_t * mpc_oct(void)
Definition: mpc.c:2031

References mpc_expect(), mpc_hex(), mpc_int(), mpc_oct(), and mpc_or().

◆ mpc_oct()

mpc_parser_t* mpc_oct ( void  )

Definition at line 2031 of file mpc.c.

2031 { return mpc_expect(mpc_apply(mpc_octdigits(), mpcf_oct), "octadecimal"); }
mpc_val_t * mpcf_oct(mpc_val_t *x)
Definition: mpc.c:2448
mpc_parser_t * mpc_octdigits(void)
Definition: mpc.c:2021

References mpc_apply(), mpc_expect(), mpc_octdigits(), and mpcf_oct().

Referenced by mpc_number().

◆ mpc_octdigit()

mpc_parser_t* mpc_octdigit ( void  )

Definition at line 2018 of file mpc.c.

2018 { return mpc_expect(mpc_oneof("01234567"), "oct digit"); }

References mpc_expect(), and mpc_oneof().

Referenced by mpc_octdigits().

◆ mpc_octdigits()

mpc_parser_t* mpc_octdigits ( void  )

Definition at line 2021 of file mpc.c.

2021 { return mpc_expect(mpc_many1(mpcf_strfold, mpc_octdigit()), "oct digits"); }
mpc_parser_t * mpc_octdigit(void)
Definition: mpc.c:2018

References mpc_expect(), mpc_many1(), mpc_octdigit(), and mpcf_strfold().

Referenced by mpc_oct().

◆ mpc_oneof()

mpc_parser_t* mpc_oneof ( const char *  s)

Definition at line 1762 of file mpc.c.

1762  {
1764  p->type = MPC_TYPE_ONEOF;
1765  p->data.string.x = malloc(strlen(s) + 1);
1766  strcpy(p->data.string.x, s);
1767  return mpc_expectf(p, "one of '%s'", s);
1768 }

References malloc(), mpc_expectf(), MPC_TYPE_ONEOF, mpc_undefined(), p, and s.

Referenced by mpc_alpha(), mpc_digit(), mpc_hexdigit(), mpc_lower(), mpc_octdigit(), mpc_real(), mpc_upper(), mpc_whitespace(), mpca_grammar_st(), mpca_lang_st(), and mpcf_re_range().

◆ mpc_optimise()

void mpc_optimise ( mpc_parser_t p)

Definition at line 4064 of file mpc.c.

4064  {
4066 }
static void mpc_optimise_unretained(mpc_parser_t *p, int force)
Definition: mpc.c:3895

References mpc_optimise_unretained(), and p.

Referenced by mpc_re_mode(), mpca_grammar_st(), mpca_lang_st(), and mpca_stmt_list_apply_to().

◆ mpc_optimise_unretained()

static void mpc_optimise_unretained ( mpc_parser_t p,
int  force 
)
static

Definition at line 3895 of file mpc.c.

3895  {
3896 
3897  int i, n, m;
3898  mpc_parser_t *t;
3899 
3900  if (p->retained && !force) { return; }
3901 
3902  /* Optimise Subexpressions */
3903 
3904  if (p->type == MPC_TYPE_EXPECT) { mpc_optimise_unretained(p->data.expect.x, 0); }
3905  if (p->type == MPC_TYPE_APPLY) { mpc_optimise_unretained(p->data.apply.x, 0); }
3906  if (p->type == MPC_TYPE_APPLY_TO) { mpc_optimise_unretained(p->data.apply_to.x, 0); }
3907  if (p->type == MPC_TYPE_CHECK) { mpc_optimise_unretained(p->data.check.x, 0); }
3908  if (p->type == MPC_TYPE_CHECK_WITH) { mpc_optimise_unretained(p->data.check_with.x, 0); }
3909  if (p->type == MPC_TYPE_PREDICT) { mpc_optimise_unretained(p->data.predict.x, 0); }
3910  if (p->type == MPC_TYPE_NOT) { mpc_optimise_unretained(p->data.not.x, 0); }
3911  if (p->type == MPC_TYPE_MAYBE) { mpc_optimise_unretained(p->data.not.x, 0); }
3912  if (p->type == MPC_TYPE_MANY) { mpc_optimise_unretained(p->data.repeat.x, 0); }
3913  if (p->type == MPC_TYPE_MANY1) { mpc_optimise_unretained(p->data.repeat.x, 0); }
3914  if (p->type == MPC_TYPE_COUNT) { mpc_optimise_unretained(p->data.repeat.x, 0); }
3915 
3916  if (p->type == MPC_TYPE_OR) {
3917  for(i = 0; i < p->data.or.n; i++) {
3918  mpc_optimise_unretained(p->data.or.xs[i], 0);
3919  }
3920  }
3921 
3922  if (p->type == MPC_TYPE_AND) {
3923  for(i = 0; i < p->data.and.n; i++) {
3924  mpc_optimise_unretained(p->data.and.xs[i], 0);
3925  }
3926  }
3927 
3928  /* Perform optimisations */
3929 
3930  while (1) {
3931 
3932  /* Merge rhs `or` */
3933  if (p->type == MPC_TYPE_OR
3934  && p->data.or.xs[p->data.or.n-1]->type == MPC_TYPE_OR
3935  && !p->data.or.xs[p->data.or.n-1]->retained) {
3936  t = p->data.or.xs[p->data.or.n-1];
3937  n = p->data.or.n; m = t->data.or.n;
3938  p->data.or.n = n + m - 1;
3939  p->data.or.xs = realloc(p->data.or.xs, sizeof(mpc_parser_t*) * (n + m -1));
3940  memmove(p->data.or.xs + n - 1, t->data.or.xs, m * sizeof(mpc_parser_t*));
3941  free(t->data.or.xs); free(t->name); free(t);
3942  continue;
3943  }
3944 
3945  /* Merge lhs `or` */
3946  if (p->type == MPC_TYPE_OR
3947  && p->data.or.xs[0]->type == MPC_TYPE_OR
3948  && !p->data.or.xs[0]->retained) {
3949  t = p->data.or.xs[0];
3950  n = p->data.or.n; m = t->data.or.n;
3951  p->data.or.n = n + m - 1;
3952  p->data.or.xs = realloc(p->data.or.xs, sizeof(mpc_parser_t*) * (n + m -1));
3953  memmove(p->data.or.xs + m, p->data.or.xs + 1, (n - 1) * sizeof(mpc_parser_t*));
3954  memmove(p->data.or.xs, t->data.or.xs, m * sizeof(mpc_parser_t*));
3955  free(t->data.or.xs); free(t->name); free(t);
3956  continue;
3957  }
3958 
3959  /* Remove ast `pass` */
3960  if (p->type == MPC_TYPE_AND
3961  && p->data.and.n == 2
3962  && p->data.and.xs[0]->type == MPC_TYPE_PASS
3963  && !p->data.and.xs[0]->retained
3964  && p->data.and.f == mpcf_fold_ast) {
3965  t = p->data.and.xs[1];
3966  mpc_delete(p->data.and.xs[0]);
3967  free(p->data.and.xs); free(p->data.and.dxs); free(p->name);
3968  memcpy(p, t, sizeof(mpc_parser_t));
3969  free(t);
3970  continue;
3971  }
3972 
3973  /* Merge ast lhs `and` */
3974  if (p->type == MPC_TYPE_AND
3975  && p->data.and.f == mpcf_fold_ast
3976  && p->data.and.xs[0]->type == MPC_TYPE_AND
3977  && !p->data.and.xs[0]->retained
3978  && p->data.and.xs[0]->data.and.f == mpcf_fold_ast) {
3979  t = p->data.and.xs[0];
3980  n = p->data.and.n; m = t->data.and.n;
3981  p->data.and.n = n + m - 1;
3982  p->data.and.xs = realloc(p->data.and.xs, sizeof(mpc_parser_t*) * (n + m - 1));
3983  p->data.and.dxs = realloc(p->data.and.dxs, sizeof(mpc_dtor_t) * (n + m - 1 - 1));
3984  memmove(p->data.and.xs + m, p->data.and.xs + 1, (n - 1) * sizeof(mpc_parser_t*));
3985  memmove(p->data.and.xs, t->data.and.xs, m * sizeof(mpc_parser_t*));
3986  for (i = 0; i < p->data.and.n-1; i++) { p->data.and.dxs[i] = (mpc_dtor_t)mpc_ast_delete; }
3987  free(t->data.and.xs); free(t->data.and.dxs); free(t->name); free(t);
3988  continue;
3989  }
3990 
3991  /* Merge ast rhs `and` */
3992  if (p->type == MPC_TYPE_AND
3993  && p->data.and.f == mpcf_fold_ast
3994  && p->data.and.xs[p->data.and.n-1]->type == MPC_TYPE_AND
3995  && !p->data.and.xs[p->data.and.n-1]->retained
3996  && p->data.and.xs[p->data.and.n-1]->data.and.f == mpcf_fold_ast) {
3997  t = p->data.and.xs[p->data.and.n-1];
3998  n = p->data.and.n; m = t->data.and.n;
3999  p->data.and.n = n + m - 1;
4000  p->data.and.xs = realloc(p->data.and.xs, sizeof(mpc_parser_t*) * (n + m -1));
4001  p->data.and.dxs = realloc(p->data.and.dxs, sizeof(mpc_dtor_t) * (n + m - 1 - 1));
4002  memmove(p->data.and.xs + n - 1, t->data.and.xs, m * sizeof(mpc_parser_t*));
4003  for (i = 0; i < p->data.and.n-1; i++) { p->data.and.dxs[i] = (mpc_dtor_t)mpc_ast_delete; }
4004  free(t->data.and.xs); free(t->data.and.dxs); free(t->name); free(t);
4005  continue;
4006  }
4007 
4008  /* Remove re `lift` */
4009  if (p->type == MPC_TYPE_AND
4010  && p->data.and.n == 2
4011  && p->data.and.xs[0]->type == MPC_TYPE_LIFT
4012  && p->data.and.xs[0]->data.lift.lf == mpcf_ctor_str
4013  && !p->data.and.xs[0]->retained
4014  && p->data.and.f == mpcf_strfold) {
4015  t = p->data.and.xs[1];
4016  mpc_delete(p->data.and.xs[0]);
4017  free(p->data.and.xs); free(p->data.and.dxs); free(p->name);
4018  memcpy(p, t, sizeof(mpc_parser_t));
4019  free(t);
4020  continue;
4021  }
4022 
4023  /* Merge re lhs `and` */
4024  if (p->type == MPC_TYPE_AND
4025  && p->data.and.f == mpcf_strfold
4026  && p->data.and.xs[0]->type == MPC_TYPE_AND
4027  && !p->data.and.xs[0]->retained
4028  && p->data.and.xs[0]->data.and.f == mpcf_strfold) {
4029  t = p->data.and.xs[0];
4030  n = p->data.and.n; m = t->data.and.n;
4031  p->data.and.n = n + m - 1;
4032  p->data.and.xs = realloc(p->data.and.xs, sizeof(mpc_parser_t*) * (n + m - 1));
4033  p->data.and.dxs = realloc(p->data.and.dxs, sizeof(mpc_dtor_t) * (n + m - 1 - 1));
4034  memmove(p->data.and.xs + m, p->data.and.xs + 1, (n - 1) * sizeof(mpc_parser_t*));
4035  memmove(p->data.and.xs, t->data.and.xs, m * sizeof(mpc_parser_t*));
4036  for (i = 0; i < p->data.and.n-1; i++) { p->data.and.dxs[i] = free; }
4037  free(t->data.and.xs); free(t->data.and.dxs); free(t->name); free(t);
4038  continue;
4039  }
4040 
4041  /* Merge re rhs `and` */
4042  if (p->type == MPC_TYPE_AND
4043  && p->data.and.f == mpcf_strfold
4044  && p->data.and.xs[p->data.and.n-1]->type == MPC_TYPE_AND
4045  && !p->data.and.xs[p->data.and.n-1]->retained
4046  && p->data.and.xs[p->data.and.n-1]->data.and.f == mpcf_strfold) {
4047  t = p->data.and.xs[p->data.and.n-1];
4048  n = p->data.and.n; m = t->data.and.n;
4049  p->data.and.n = n + m - 1;
4050  p->data.and.xs = realloc(p->data.and.xs, sizeof(mpc_parser_t*) * (n + m -1));
4051  p->data.and.dxs = realloc(p->data.and.dxs, sizeof(mpc_dtor_t) * (n + m - 1 - 1));
4052  memmove(p->data.and.xs + n - 1, t->data.and.xs, m * sizeof(mpc_parser_t*));
4053  for (i = 0; i < p->data.and.n-1; i++) { p->data.and.dxs[i] = free; }
4054  free(t->data.and.xs); free(t->data.and.dxs); free(t->name); free(t);
4055  continue;
4056  }
4057 
4058  return;
4059 
4060  }
4061 
4062 }
mpc_val_t * mpcf_ctor_str(void)
Definition: mpc.c:2431
mpc_val_t * mpcf_fold_ast(int n, mpc_val_t **xs)
Definition: mpc.c:3212
char * name
Definition: mpc.c:959
mpc_parser_t ** xs
Definition: mpc.c:936
mpc_dtor_t * dxs
Definition: mpc.c:936
mpc_parser_t ** xs
Definition: mpc.c:935
mpc_pdata_and_t and
Definition: mpc.c:954
mpc_pdata_or_t or
Definition: mpc.c:955

References mpc_pdata_t::and, mpc_parser_t::data, mpc_pdata_and_t::dxs, free(), i, regress::m, memcpy(), mpc_ast_delete(), mpc_delete(), MPC_TYPE_AND, MPC_TYPE_APPLY, MPC_TYPE_APPLY_TO, MPC_TYPE_CHECK, MPC_TYPE_CHECK_WITH, MPC_TYPE_COUNT, MPC_TYPE_EXPECT, MPC_TYPE_LIFT, MPC_TYPE_MANY, MPC_TYPE_MANY1, MPC_TYPE_MAYBE, MPC_TYPE_NOT, MPC_TYPE_OR, MPC_TYPE_PASS, MPC_TYPE_PREDICT, mpcf_ctor_str(), mpcf_fold_ast(), mpcf_strfold(), n, mpc_pdata_or_t::n, mpc_pdata_and_t::n, mpc_parser_t::name, mpc_pdata_t::or, p, realloc(), mpc_pdata_or_t::xs, and mpc_pdata_and_t::xs.

Referenced by mpc_optimise().

◆ mpc_or()

mpc_parser_t* mpc_or ( int  n,
  ... 
)

Definition at line 1928 of file mpc.c.

1928  {
1929 
1930  int i;
1931  va_list va;
1932 
1934 
1935  p->type = MPC_TYPE_OR;
1936  p->data.or.n = n;
1937  p->data.or.xs = malloc(sizeof(mpc_parser_t*) * n);
1938 
1939  va_start(va, n);
1940  for (i = 0; i < n; i++) {
1941  p->data.or.xs[i] = va_arg(va, mpc_parser_t*);
1942  }
1943  va_end(va);
1944 
1945  return p;
1946 }

References i, malloc(), MPC_TYPE_OR, mpc_undefined(), n, and p.

Referenced by mpc_alphanum(), mpc_char_lit(), mpc_ident(), mpc_number(), mpc_re_mode(), mpc_regex_lit(), mpc_string_lit(), mpca_grammar_st(), mpca_lang_st(), mpcf_re_escape(), and mpcf_re_or().

◆ mpc_parens()

mpc_parser_t* mpc_parens ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2099 of file mpc.c.

2099 { return mpc_between(a, ad, "(", ")"); }

References a, and mpc_between().

Referenced by mpc_re_mode().

◆ mpc_parse()

int mpc_parse ( const char *  filename,
const char *  string,
mpc_parser_t p,
mpc_result_t r 
)

Definition at line 1321 of file mpc.c.

1321  {
1322  int x;
1324  x = mpc_parse_input(i, p, r);
1326  return x;
1327 }
static mpc_input_t * mpc_input_new_string(const char *filename, const char *string)
Definition: mpc.c:103

References i, mpc_input_delete(), mpc_input_new_string(), mpc_parse_input(), p, r, and x.

Referenced by mpc_re_mode(), mpc_test_fail(), mpc_test_pass(), and mpca_grammar_st().

◆ mpc_parse_apply()

static mpc_val_t* mpc_parse_apply ( mpc_input_t i,
mpc_apply_t  f,
mpc_val_t x 
)
static

Definition at line 1020 of file mpc.c.

1020  {
1021  if (f == mpcf_free) { return mpcf_input_free(i, x); }
1022  if (f == mpcf_str_ast) { return mpcf_input_str_ast(i, x); }
1023  return f(mpc_export(i, x));
1024 }
mpc_val_t * mpcf_str_ast(mpc_val_t *c)
Definition: mpc.c:3250
static mpc_val_t * mpcf_input_str_ast(mpc_input_t *i, mpc_val_t *c)
Definition: mpc.c:1014
static mpc_val_t * mpcf_input_free(mpc_input_t *i, mpc_val_t *x)
Definition: mpc.c:1009

References f, i, mpc_export(), mpcf_free(), mpcf_input_free(), mpcf_input_str_ast(), mpcf_str_ast(), and x.

Referenced by mpc_parse_run().

◆ mpc_parse_apply_to()

static mpc_val_t* mpc_parse_apply_to ( mpc_input_t i,
mpc_apply_to_t  f,
mpc_val_t x,
mpc_val_t d 
)
static

Definition at line 1026 of file mpc.c.

1026  {
1027  return f(mpc_export(i, x), d);
1028 }

References d, f, i, mpc_export(), and x.

Referenced by mpc_parse_run().

◆ mpc_parse_contents()

int mpc_parse_contents ( const char *  filename,
mpc_parser_t p,
mpc_result_t r 
)

Definition at line 1353 of file mpc.c.

1353  {
1354 
1355  FILE *f = fopen(filename, "rb");
1356  int res;
1357 
1358  if (f == NULL) {
1359  r->output = NULL;
1360  r->error = mpc_err_file(filename, "Unable to open file!");
1361  return 0;
1362  }
1363 
1364  res = mpc_parse_file(filename, f, p, r);
1365  fclose(f);
1366  return res;
1367 }
static mpc_err_t * mpc_err_file(const char *filename, const char *failure)
Definition: mpc.c:697
int mpc_parse_file(const char *filename, FILE *file, mpc_parser_t *p, mpc_result_t *r)
Definition: mpc.c:1337
string FILE
Definition: benchmark.py:21

References f, benchmark::FILE, mpc_err_file(), mpc_parse_file(), NULL, p, and r.

Referenced by main().

◆ mpc_parse_dtor()

static void mpc_parse_dtor ( mpc_input_t i,
mpc_dtor_t  d,
mpc_val_t x 
)
static

Definition at line 1030 of file mpc.c.

1030  {
1031  if (d == free) { mpc_free(i, x); return; }
1032  d(mpc_export(i, x));
1033 }

References d, free(), i, mpc_export(), mpc_free(), and x.

Referenced by mpc_parse_run().

◆ mpc_parse_file()

int mpc_parse_file ( const char *  filename,
FILE *  file,
mpc_parser_t p,
mpc_result_t r 
)

Definition at line 1337 of file mpc.c.

1337  {
1338  int x;
1340  x = mpc_parse_input(i, p, r);
1342  return x;
1343 }
static mpc_input_t * mpc_input_new_file(const char *filename, FILE *file)
Definition: mpc.c:192
Definition: gzappend.c:170

References i, mpc_input_delete(), mpc_input_new_file(), mpc_parse_input(), p, r, and x.

Referenced by mpc_parse_contents().

◆ mpc_parse_fold()

static mpc_val_t* mpc_parse_fold ( mpc_input_t i,
mpc_fold_t  f,
int  n,
mpc_val_t **  xs 
)
static

Definition at line 994 of file mpc.c.

994  {
995  int j;
996  if (f == mpcf_null) { return mpcf_null(n, xs); }
997  if (f == mpcf_fst) { return mpcf_fst(n, xs); }
998  if (f == mpcf_snd) { return mpcf_snd(n, xs); }
999  if (f == mpcf_trd) { return mpcf_trd(n, xs); }
1000  if (f == mpcf_fst_free) { return mpcf_input_fst_free(i, n, xs); }
1001  if (f == mpcf_snd_free) { return mpcf_input_snd_free(i, n, xs); }
1002  if (f == mpcf_trd_free) { return mpcf_input_trd_free(i, n, xs); }
1003  if (f == mpcf_strfold) { return mpcf_input_strfold(i, n, xs); }
1004  if (f == mpcf_state_ast) { return mpcf_input_state_ast(i, n, xs); }
1005  for (j = 0; j < n; j++) { xs[j] = mpc_export(i, xs[j]); }
1006  return f(j, xs);
1007 }
static mpc_val_t * mpcf_input_fst_free(mpc_input_t *i, int n, mpc_val_t **xs)
Definition: mpc.c:971
mpc_val_t * mpcf_trd(int n, mpc_val_t **xs)
Definition: mpc.c:2627
static mpc_val_t * mpcf_input_snd_free(mpc_input_t *i, int n, mpc_val_t **xs)
Definition: mpc.c:972
mpc_val_t * mpcf_snd(int n, mpc_val_t **xs)
Definition: mpc.c:2626
static mpc_val_t * mpcf_input_state_ast(mpc_input_t *i, int n, mpc_val_t **xs)
Definition: mpc.c:985
mpc_val_t * mpcf_state_ast(int n, mpc_val_t **xs)
Definition: mpc.c:3256
mpc_val_t * mpcf_null(int n, mpc_val_t **xs)
Definition: mpc.c:2624
static mpc_val_t * mpcf_input_trd_free(mpc_input_t *i, int n, mpc_val_t **xs)
Definition: mpc.c:973
static mpc_val_t * mpcf_input_strfold(mpc_input_t *i, int n, mpc_val_t **xs)
Definition: mpc.c:975
mpc_val_t * mpcf_fst_free(int n, mpc_val_t **xs)
Definition: mpc.c:2637
mpc_val_t * mpcf_trd_free(int n, mpc_val_t **xs)
Definition: mpc.c:2639

References f, i, mpc_export(), mpcf_fst(), mpcf_fst_free(), mpcf_input_fst_free(), mpcf_input_snd_free(), mpcf_input_state_ast(), mpcf_input_strfold(), mpcf_input_trd_free(), mpcf_null(), mpcf_snd(), mpcf_snd_free(), mpcf_state_ast(), mpcf_strfold(), mpcf_trd(), mpcf_trd_free(), and n.

Referenced by mpc_parse_run().

◆ mpc_parse_input()

int mpc_parse_input ( mpc_input_t i,
mpc_parser_t p,
mpc_result_t r 
)

Definition at line 1307 of file mpc.c.

1307  {
1308  int x;
1309  mpc_err_t *e = mpc_err_fail(i, "Unknown Error");
1310  e->state = mpc_state_invalid();
1311  x = mpc_parse_run(i, p, r, &e, 0);
1312  if (x) {
1314  r->output = mpc_export(i, r->output);
1315  } else {
1316  r->error = mpc_err_export(i, mpc_err_merge(i, e, r->error));
1317  }
1318  return x;
1319 }
static mpc_err_t * mpc_err_merge(mpc_input_t *i, mpc_err_t *x, mpc_err_t *y)
Definition: mpc.c:872
static int mpc_parse_run(mpc_input_t *i, mpc_parser_t *p, mpc_result_t *r, mpc_err_t **e, int depth)
Definition: mpc.c:1047
static mpc_err_t * mpc_err_fail(mpc_input_t *i, const char *failure)
Definition: mpc.c:682
static mpc_err_t * mpc_err_export(mpc_input_t *i, mpc_err_t *x)
Definition: mpc.c:721

References e, i, mpc_err_delete_internal(), mpc_err_export(), mpc_err_fail(), mpc_err_merge(), mpc_export(), mpc_parse_run(), mpc_state_invalid(), p, r, and x.

Referenced by mpc_nparse(), mpc_parse(), mpc_parse_file(), mpc_parse_pipe(), and mpca_lang_st().

◆ mpc_parse_pipe()

int mpc_parse_pipe ( const char *  filename,
FILE *  pipe,
mpc_parser_t p,
mpc_result_t r 
)

Definition at line 1345 of file mpc.c.

1345  {
1346  int x;
1348  x = mpc_parse_input(i, p, r);
1350  return x;
1351 }
static mpc_input_t * mpc_input_new_pipe(const char *filename, FILE *pipe)
Definition: mpc.c:163

References i, mpc_input_delete(), mpc_input_new_pipe(), mpc_parse_input(), p, pipe, r, and x.

Referenced by main().

◆ mpc_parse_run()

static int mpc_parse_run ( mpc_input_t i,
mpc_parser_t p,
mpc_result_t r,
mpc_err_t **  e,
int  depth 
)
static

Definition at line 1047 of file mpc.c.

1047  {
1048 
1049  int j = 0, k = 0;
1050  mpc_result_t results_stk[MPC_PARSE_STACK_MIN];
1051  mpc_result_t *results;
1052  int results_slots = MPC_PARSE_STACK_MIN;
1053 
1054  if (depth == MPC_MAX_RECURSION_DEPTH)
1055  {
1056  MPC_FAILURE(mpc_err_fail(i, "Maximum recursion depth exceeded!"));
1057  }
1058 
1059  switch (p->type) {
1060 
1061  /* Basic Parsers */
1062 
1063  case MPC_TYPE_ANY: MPC_PRIMITIVE(mpc_input_any(i, (char**)&r->output));
1064  case MPC_TYPE_SINGLE: MPC_PRIMITIVE(mpc_input_char(i, p->data.single.x, (char**)&r->output));
1065  case MPC_TYPE_RANGE: MPC_PRIMITIVE(mpc_input_range(i, p->data.range.x, p->data.range.y, (char**)&r->output));
1066  case MPC_TYPE_ONEOF: MPC_PRIMITIVE(mpc_input_oneof(i, p->data.string.x, (char**)&r->output));
1067  case MPC_TYPE_NONEOF: MPC_PRIMITIVE(mpc_input_noneof(i, p->data.string.x, (char**)&r->output));
1068  case MPC_TYPE_SATISFY: MPC_PRIMITIVE(mpc_input_satisfy(i, p->data.satisfy.f, (char**)&r->output));
1069  case MPC_TYPE_STRING: MPC_PRIMITIVE(mpc_input_string(i, p->data.string.x, (char**)&r->output));
1070  case MPC_TYPE_ANCHOR: MPC_PRIMITIVE(mpc_input_anchor(i, p->data.anchor.f, (char**)&r->output));
1071  case MPC_TYPE_SOI: MPC_PRIMITIVE(mpc_input_soi(i, (char**)&r->output));
1072  case MPC_TYPE_EOI: MPC_PRIMITIVE(mpc_input_eoi(i, (char**)&r->output));
1073 
1074  /* Other parsers */
1075 
1076  case MPC_TYPE_UNDEFINED: MPC_FAILURE(mpc_err_fail(i, "Parser Undefined!"));
1078  case MPC_TYPE_FAIL: MPC_FAILURE(mpc_err_fail(i, p->data.fail.m));
1079  case MPC_TYPE_LIFT: MPC_SUCCESS(p->data.lift.lf());
1080  case MPC_TYPE_LIFT_VAL: MPC_SUCCESS(p->data.lift.x);
1082 
1083  /* Application Parsers */
1084 
1085  case MPC_TYPE_APPLY:
1086  if (mpc_parse_run(i, p->data.apply.x, r, e, depth+1)) {
1087  MPC_SUCCESS(mpc_parse_apply(i, p->data.apply.f, r->output));
1088  } else {
1089  MPC_FAILURE(r->output);
1090  }
1091 
1092  case MPC_TYPE_APPLY_TO:
1093  if (mpc_parse_run(i, p->data.apply_to.x, r, e, depth+1)) {
1094  MPC_SUCCESS(mpc_parse_apply_to(i, p->data.apply_to.f, r->output, p->data.apply_to.d));
1095  } else {
1096  MPC_FAILURE(r->error);
1097  }
1098 
1099  case MPC_TYPE_CHECK:
1100  if (mpc_parse_run(i, p->data.check.x, r, e, depth+1)) {
1101  if (p->data.check.f(&r->output)) {
1102  MPC_SUCCESS(r->output);
1103  } else {
1104  mpc_parse_dtor(i, p->data.check.dx, r->output);
1105  MPC_FAILURE(mpc_err_fail(i, p->data.check.e));
1106  }
1107  } else {
1108  MPC_FAILURE(r->error);
1109  }
1110 
1111  case MPC_TYPE_CHECK_WITH:
1112  if (mpc_parse_run(i, p->data.check_with.x, r, e, depth+1)) {
1113  if (p->data.check_with.f(&r->output, p->data.check_with.d)) {
1114  MPC_SUCCESS(r->output);
1115  } else {
1116  mpc_parse_dtor(i, p->data.check.dx, r->output);
1117  MPC_FAILURE(mpc_err_fail(i, p->data.check_with.e));
1118  }
1119  } else {
1120  MPC_FAILURE(r->error);
1121  }
1122 
1123  case MPC_TYPE_EXPECT:
1125  if (mpc_parse_run(i, p->data.expect.x, r, e, depth+1)) {
1127  MPC_SUCCESS(r->output);
1128  } else {
1130  MPC_FAILURE(mpc_err_new(i, p->data.expect.m));
1131  }
1132 
1133  case MPC_TYPE_PREDICT:
1135  if (mpc_parse_run(i, p->data.predict.x, r, e, depth+1)) {
1137  MPC_SUCCESS(r->output);
1138  } else {
1140  MPC_FAILURE(r->error);
1141  }
1142 
1143  /* Optional Parsers */
1144 
1145  /* TODO: Update Not Error Message */
1146 
1147  case MPC_TYPE_NOT:
1148  mpc_input_mark(i);
1150  if (mpc_parse_run(i, p->data.not.x, r, e, depth+1)) {
1153  mpc_parse_dtor(i, p->data.not.dx, r->output);
1154  MPC_FAILURE(mpc_err_new(i, "opposite"));
1155  } else {
1158  MPC_SUCCESS(p->data.not.lf());
1159  }
1160 
1161  case MPC_TYPE_MAYBE:
1162  if (mpc_parse_run(i, p->data.not.x, r, e, depth+1)) {
1163  MPC_SUCCESS(r->output);
1164  } else {
1165  *e = mpc_err_merge(i, *e, r->error);
1166  MPC_SUCCESS(p->data.not.lf());
1167  }
1168 
1169  /* Repeat Parsers */
1170 
1171  case MPC_TYPE_MANY:
1172 
1173  results = results_stk;
1174 
1175  while (mpc_parse_run(i, p->data.repeat.x, &results[j], e, depth+1)) {
1176  j++;
1177  if (j == MPC_PARSE_STACK_MIN) {
1178  results_slots = j + j / 2;
1179  results = mpc_malloc(i, sizeof(mpc_result_t) * results_slots);
1180  memcpy(results, results_stk, sizeof(mpc_result_t) * MPC_PARSE_STACK_MIN);
1181  } else if (j >= results_slots) {
1182  results_slots = j + j / 2;
1183  results = mpc_realloc(i, results, sizeof(mpc_result_t) * results_slots);
1184  }
1185  }
1186 
1187  *e = mpc_err_merge(i, *e, results[j].error);
1188 
1189  MPC_SUCCESS(
1190  mpc_parse_fold(i, p->data.repeat.f, j, (mpc_val_t**)results);
1191  if (j >= MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1192 
1193  case MPC_TYPE_MANY1:
1194 
1195  results = results_stk;
1196 
1197  while (mpc_parse_run(i, p->data.repeat.x, &results[j], e, depth+1)) {
1198  j++;
1199  if (j == MPC_PARSE_STACK_MIN) {
1200  results_slots = j + j / 2;
1201  results = mpc_malloc(i, sizeof(mpc_result_t) * results_slots);
1202  memcpy(results, results_stk, sizeof(mpc_result_t) * MPC_PARSE_STACK_MIN);
1203  } else if (j >= results_slots) {
1204  results_slots = j + j / 2;
1205  results = mpc_realloc(i, results, sizeof(mpc_result_t) * results_slots);
1206  }
1207  }
1208 
1209  if (j == 0) {
1210  MPC_FAILURE(
1211  mpc_err_many1(i, results[j].error);
1212  if (j >= MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1213  } else {
1214 
1215  *e = mpc_err_merge(i, *e, results[j].error);
1216 
1217  MPC_SUCCESS(
1218  mpc_parse_fold(i, p->data.repeat.f, j, (mpc_val_t**)results);
1219  if (j >= MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1220  }
1221 
1222  case MPC_TYPE_COUNT:
1223 
1224  results = p->data.repeat.n > MPC_PARSE_STACK_MIN
1225  ? mpc_malloc(i, sizeof(mpc_result_t) * p->data.repeat.n)
1226  : results_stk;
1227 
1228  while (mpc_parse_run(i, p->data.repeat.x, &results[j], e, depth+1)) {
1229  j++;
1230  if (j == p->data.repeat.n) { break; }
1231  }
1232 
1233  if (j == p->data.repeat.n) {
1234  MPC_SUCCESS(
1235  mpc_parse_fold(i, p->data.repeat.f, j, (mpc_val_t**)results);
1236  if (p->data.repeat.n > MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1237  } else {
1238  for (k = 0; k < j; k++) {
1239  mpc_parse_dtor(i, p->data.repeat.dx, results[k].output);
1240  }
1241  MPC_FAILURE(
1242  mpc_err_count(i, results[j].error, p->data.repeat.n);
1243  if (p->data.repeat.n > MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1244  }
1245 
1246  /* Combinatory Parsers */
1247 
1248  case MPC_TYPE_OR:
1249 
1250  if (p->data.or.n == 0) { MPC_SUCCESS(NULL); }
1251 
1252  results = p->data.or.n > MPC_PARSE_STACK_MIN
1253  ? mpc_malloc(i, sizeof(mpc_result_t) * p->data.or.n)
1254  : results_stk;
1255 
1256  for (j = 0; j < p->data.or.n; j++) {
1257  if (mpc_parse_run(i, p->data.or.xs[j], &results[j], e, depth+1)) {
1258  MPC_SUCCESS(results[j].output;
1259  if (p->data.or.n > MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1260  } else {
1261  *e = mpc_err_merge(i, *e, results[j].error);
1262  }
1263  }
1264 
1265  MPC_FAILURE(NULL;
1266  if (p->data.or.n > MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1267 
1268  case MPC_TYPE_AND:
1269 
1270  if (p->data.and.n == 0) { MPC_SUCCESS(NULL); }
1271 
1272  results = p->data.or.n > MPC_PARSE_STACK_MIN
1273  ? mpc_malloc(i, sizeof(mpc_result_t) * p->data.or.n)
1274  : results_stk;
1275 
1276  mpc_input_mark(i);
1277  for (j = 0; j < p->data.and.n; j++) {
1278  if (!mpc_parse_run(i, p->data.and.xs[j], &results[j], e, depth+1)) {
1280  for (k = 0; k < j; k++) {
1281  mpc_parse_dtor(i, p->data.and.dxs[k], results[k].output);
1282  }
1283  MPC_FAILURE(results[j].error;
1284  if (p->data.or.n > MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1285  }
1286  }
1288  MPC_SUCCESS(
1289  mpc_parse_fold(i, p->data.and.f, j, (mpc_val_t**)results);
1290  if (p->data.or.n > MPC_PARSE_STACK_MIN) { mpc_free(i, results); });
1291 
1292  /* End */
1293 
1294  default:
1295 
1296  MPC_FAILURE(mpc_err_fail(i, "Unknown Parser Type Id!"));
1297  }
1298 
1299  return 0;
1300 
1301 }
#define MPC_MAX_RECURSION_DEPTH
Definition: mpc.c:1045
static int mpc_input_soi(mpc_input_t *i, char **o)
Definition: mpc.c:548
static void mpc_input_suppress_disable(mpc_input_t *i)
Definition: mpc.c:298
static void mpc_input_backtrack_enable(mpc_input_t *i)
Definition: mpc.c:296
static int mpc_input_eoi(mpc_input_t *i, char **o)
Definition: mpc.c:553
static mpc_val_t * mpc_parse_apply(mpc_input_t *i, mpc_apply_t f, mpc_val_t *x)
Definition: mpc.c:1020
static void mpc_parse_dtor(mpc_input_t *i, mpc_dtor_t d, mpc_val_t *x)
Definition: mpc.c:1030
static int mpc_input_string(mpc_input_t *i, const char *c, char **o)
Definition: mpc.c:524
static int mpc_input_anchor(mpc_input_t *i, int(*f)(char, char), char **o)
Definition: mpc.c:543
static mpc_val_t * mpc_parse_apply_to(mpc_input_t *i, mpc_apply_to_t f, mpc_val_t *x, mpc_val_t *d)
Definition: mpc.c:1026
static mpc_err_t * mpc_err_count(mpc_input_t *i, mpc_err_t *x, int n)
Definition: mpc.c:861
static mpc_err_t * mpc_err_many1(mpc_input_t *i, mpc_err_t *x)
Definition: mpc.c:857
static int mpc_input_noneof(mpc_input_t *i, const char *c, char **o)
Definition: mpc.c:510
static mpc_val_t * mpc_parse_fold(mpc_input_t *i, mpc_fold_t f, int n, mpc_val_t **xs)
Definition: mpc.c:994
static mpc_err_t * mpc_err_new(mpc_input_t *i, const char *expected)
Definition: mpc.c:666
#define MPC_PRIMITIVE(x)
Definition: mpc.c:1041
static int mpc_input_satisfy(mpc_input_t *i, int(*cond)(char), char **o)
Definition: mpc.c:517
static mpc_state_t * mpc_input_state_copy(mpc_input_t *i)
Definition: mpc.c:565
static int mpc_input_oneof(mpc_input_t *i, const char *c, char **o)
Definition: mpc.c:503
static int mpc_input_range(mpc_input_t *i, char c, char d, char **o)
Definition: mpc.c:496
static void mpc_input_suppress_enable(mpc_input_t *i)
Definition: mpc.c:299
static void mpc_input_backtrack_disable(mpc_input_t *i)
Definition: mpc.c:295
static int mpc_input_any(mpc_input_t *i, char **o)
Definition: mpc.c:482
void mpc_val_t
Definition: mpc.h:58
void error(const char *msg)
Definition: untgz.c:593
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
diff_output_t output
Definition: zipcmp.c:237

References e, error(), i, if(), k, memcpy(), mpc_err_count(), mpc_err_fail(), mpc_err_many1(), mpc_err_merge(), mpc_err_new(), MPC_FAILURE, mpc_free(), mpc_input_anchor(), mpc_input_any(), mpc_input_backtrack_disable(), mpc_input_backtrack_enable(), mpc_input_char(), mpc_input_eoi(), mpc_input_mark(), mpc_input_noneof(), mpc_input_oneof(), mpc_input_range(), mpc_input_rewind(), mpc_input_satisfy(), mpc_input_soi(), mpc_input_state_copy(), mpc_input_string(), mpc_input_suppress_disable(), mpc_input_suppress_enable(), mpc_input_unmark(), mpc_malloc(), MPC_MAX_RECURSION_DEPTH, mpc_parse_apply(), mpc_parse_apply_to(), mpc_parse_dtor(), mpc_parse_fold(), MPC_PARSE_STACK_MIN, MPC_PRIMITIVE, mpc_realloc(), MPC_SUCCESS, MPC_TYPE_ANCHOR, MPC_TYPE_AND, MPC_TYPE_ANY, MPC_TYPE_APPLY, MPC_TYPE_APPLY_TO, MPC_TYPE_CHECK, MPC_TYPE_CHECK_WITH, MPC_TYPE_COUNT, MPC_TYPE_EOI, MPC_TYPE_EXPECT, MPC_TYPE_FAIL, MPC_TYPE_LIFT, MPC_TYPE_LIFT_VAL, MPC_TYPE_MANY, MPC_TYPE_MANY1, MPC_TYPE_MAYBE, MPC_TYPE_NONEOF, MPC_TYPE_NOT, MPC_TYPE_ONEOF, MPC_TYPE_OR, MPC_TYPE_PASS, MPC_TYPE_PREDICT, MPC_TYPE_RANGE, MPC_TYPE_SATISFY, MPC_TYPE_SINGLE, MPC_TYPE_SOI, MPC_TYPE_STATE, MPC_TYPE_STRING, MPC_TYPE_UNDEFINED, NULL, output, p, and r.

Referenced by mpc_parse_input().

◆ mpc_pass()

mpc_parser_t* mpc_pass ( void  )

Definition at line 1610 of file mpc.c.

1610  {
1612  p->type = MPC_TYPE_PASS;
1613  return p;
1614 }

References MPC_TYPE_PASS, mpc_undefined(), and p.

Referenced by mpc_re_mode(), mpca_grammar_st(), mpca_lang_st(), and mpcaf_grammar_and().

◆ mpc_predictive()

mpc_parser_t* mpc_predictive ( mpc_parser_t a)

Definition at line 1870 of file mpc.c.

1870  {
1872  p->type = MPC_TYPE_PREDICT;
1873  p->data.predict.x = a;
1874  return p;
1875 }

References a, MPC_TYPE_PREDICT, mpc_undefined(), and p.

Referenced by mpc_re_mode(), mpca_grammar_st(), mpca_lang_st(), and mpca_stmt_list_apply_to().

◆ mpc_print()

void mpc_print ( mpc_parser_t p)

Definition at line 2811 of file mpc.c.

2811  {
2812  mpc_print_unretained(p, 1);
2813  printf("\n");
2814 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static void mpc_print_unretained(mpc_parser_t *p, int force)
Definition: mpc.c:2688

References mpc_print_unretained(), p, and printf().

◆ mpc_print_unretained()

static void mpc_print_unretained ( mpc_parser_t p,
int  force 
)
static

Definition at line 2688 of file mpc.c.

2688  {
2689 
2690  /* TODO: Print Everything Escaped */
2691 
2692  int i;
2693  char *s, *e;
2694  char buff[2];
2695 
2696  if (p->retained && !force) {;
2697  if (p->name) { printf("<%s>", p->name); }
2698  else { printf("<anon>"); }
2699  return;
2700  }
2701 
2702  if (p->type == MPC_TYPE_UNDEFINED) { printf("<?>"); }
2703  if (p->type == MPC_TYPE_PASS) { printf("<:>"); }
2704  if (p->type == MPC_TYPE_FAIL) { printf("<!>"); }
2705  if (p->type == MPC_TYPE_LIFT) { printf("<#>"); }
2706  if (p->type == MPC_TYPE_STATE) { printf("<S>"); }
2707  if (p->type == MPC_TYPE_ANCHOR) { printf("<@>"); }
2708  if (p->type == MPC_TYPE_EXPECT) {
2709  printf("%s", p->data.expect.m);
2710  /*mpc_print_unretained(p->data.expect.x, 0);*/
2711  }
2712 
2713  if (p->type == MPC_TYPE_ANY) { printf("<.>"); }
2714  if (p->type == MPC_TYPE_SATISFY) { printf("<f>"); }
2715 
2716  if (p->type == MPC_TYPE_SINGLE) {
2717  buff[0] = p->data.single.x; buff[1] = '\0';
2718  s = mpcf_escape_new(
2719  buff,
2722  printf("'%s'", s);
2723  free(s);
2724  }
2725 
2726  if (p->type == MPC_TYPE_RANGE) {
2727  buff[0] = p->data.range.x; buff[1] = '\0';
2728  s = mpcf_escape_new(
2729  buff,
2732  buff[0] = p->data.range.y; buff[1] = '\0';
2733  e = mpcf_escape_new(
2734  buff,
2737  printf("[%s-%s]", s, e);
2738  free(s);
2739  free(e);
2740  }
2741 
2742  if (p->type == MPC_TYPE_ONEOF) {
2743  s = mpcf_escape_new(
2744  p->data.string.x,
2747  printf("[%s]", s);
2748  free(s);
2749  }
2750 
2751  if (p->type == MPC_TYPE_NONEOF) {
2752  s = mpcf_escape_new(
2753  p->data.string.x,
2756  printf("[^%s]", s);
2757  free(s);
2758  }
2759 
2760  if (p->type == MPC_TYPE_STRING) {
2761  s = mpcf_escape_new(
2762  p->data.string.x,
2765  printf("\"%s\"", s);
2766  free(s);
2767  }
2768 
2769  if (p->type == MPC_TYPE_APPLY) { mpc_print_unretained(p->data.apply.x, 0); }
2770  if (p->type == MPC_TYPE_APPLY_TO) { mpc_print_unretained(p->data.apply_to.x, 0); }
2771  if (p->type == MPC_TYPE_PREDICT) { mpc_print_unretained(p->data.predict.x, 0); }
2772 
2773  if (p->type == MPC_TYPE_NOT) { mpc_print_unretained(p->data.not.x, 0); printf("!"); }
2774  if (p->type == MPC_TYPE_MAYBE) { mpc_print_unretained(p->data.not.x, 0); printf("?"); }
2775 
2776  if (p->type == MPC_TYPE_MANY) { mpc_print_unretained(p->data.repeat.x, 0); printf("*"); }
2777  if (p->type == MPC_TYPE_MANY1) { mpc_print_unretained(p->data.repeat.x, 0); printf("+"); }
2778  if (p->type == MPC_TYPE_COUNT) { mpc_print_unretained(p->data.repeat.x, 0); printf("{%i}", p->data.repeat.n); }
2779 
2780  if (p->type == MPC_TYPE_OR) {
2781  printf("(");
2782  for(i = 0; i < p->data.or.n-1; i++) {
2783  mpc_print_unretained(p->data.or.xs[i], 0);
2784  printf(" | ");
2785  }
2786  mpc_print_unretained(p->data.or.xs[p->data.or.n-1], 0);
2787  printf(")");
2788  }
2789 
2790  if (p->type == MPC_TYPE_AND) {
2791  printf("(");
2792  for(i = 0; i < p->data.and.n-1; i++) {
2793  mpc_print_unretained(p->data.and.xs[i], 0);
2794  printf(" ");
2795  }
2796  mpc_print_unretained(p->data.and.xs[p->data.and.n-1], 0);
2797  printf(")");
2798  }
2799 
2800  if (p->type == MPC_TYPE_CHECK) {
2801  mpc_print_unretained(p->data.check.x, 0);
2802  printf("->?");
2803  }
2804  if (p->type == MPC_TYPE_CHECK_WITH) {
2805  mpc_print_unretained(p->data.check_with.x, 0);
2806  printf("->?");
2807  }
2808 
2809 }
static const char mpc_escape_input_c[]
Definition: mpc.c:2483
static const char * mpc_escape_output_c[]
Definition: mpc.c:2487
static mpc_val_t * mpcf_escape_new(mpc_val_t *x, const char *input, const char **output)
Definition: mpc.c:2500

References e, free(), i, mpc_escape_input_c, mpc_escape_output_c, MPC_TYPE_ANCHOR, MPC_TYPE_AND, MPC_TYPE_ANY, MPC_TYPE_APPLY, MPC_TYPE_APPLY_TO, MPC_TYPE_CHECK, MPC_TYPE_CHECK_WITH, MPC_TYPE_COUNT, MPC_TYPE_EXPECT, MPC_TYPE_FAIL, MPC_TYPE_LIFT, MPC_TYPE_MANY, MPC_TYPE_MANY1, MPC_TYPE_MAYBE, MPC_TYPE_NONEOF, MPC_TYPE_NOT, MPC_TYPE_ONEOF, MPC_TYPE_OR, MPC_TYPE_PASS, MPC_TYPE_PREDICT, MPC_TYPE_RANGE, MPC_TYPE_SATISFY, MPC_TYPE_SINGLE, MPC_TYPE_STATE, MPC_TYPE_STRING, MPC_TYPE_UNDEFINED, mpcf_escape_new(), p, printf(), and s.

Referenced by mpc_print().

◆ mpc_range()

mpc_parser_t* mpc_range ( char  s,
char  e 
)

Definition at line 1754 of file mpc.c.

1754  {
1756  p->type = MPC_TYPE_RANGE;
1757  p->data.range.x = s;
1758  p->data.range.y = e;
1759  return mpc_expectf(p, "character between '%c' and '%c'", s, e);
1760 }

References e, mpc_expectf(), MPC_TYPE_RANGE, mpc_undefined(), p, and s.

◆ mpc_re()

mpc_parser_t* mpc_re ( const char *  re)

Definition at line 2353 of file mpc.c.

2353  {
2354  return mpc_re_mode(re, MPC_RE_DEFAULT);
2355 }
mpc_parser_t * mpc_re_mode(const char *re, int mode)
Definition: mpc.c:2357
@ MPC_RE_DEFAULT
Definition: mpc.h:270

References MPC_RE_DEFAULT, and mpc_re_mode().

◆ mpc_re_escape_char()

static mpc_parser_t* mpc_re_escape_char ( char  c)
static

Definition at line 2197 of file mpc.c.

2197  {
2198  switch (c) {
2199  case 'a': return mpc_char('\a');
2200  case 'f': return mpc_char('\f');
2201  case 'n': return mpc_char('\n');
2202  case 'r': return mpc_char('\r');
2203  case 't': return mpc_char('\t');
2204  case 'v': return mpc_char('\v');
2205  case 'b': return mpc_and(2, mpcf_snd, mpc_boundary(), mpc_lift(mpcf_ctor_str), free);
2206  case 'B': return mpc_not_lift(mpc_boundary(), free, mpcf_ctor_str);
2207  case 'A': return mpc_and(2, mpcf_snd, mpc_soi(), mpc_lift(mpcf_ctor_str), free);
2208  case 'Z': return mpc_and(2, mpcf_snd, mpc_eoi(), mpc_lift(mpcf_ctor_str), free);
2209  case 'd': return mpc_digit();
2210  case 'D': return mpc_not_lift(mpc_digit(), free, mpcf_ctor_str);
2211  case 's': return mpc_whitespace();
2212  case 'S': return mpc_not_lift(mpc_whitespace(), free, mpcf_ctor_str);
2213  case 'w': return mpc_alphanum();
2214  case 'W': return mpc_not_lift(mpc_alphanum(), free, mpcf_ctor_str);
2215  default: return NULL;
2216  }
2217 }
mpc_parser_t * mpc_whitespace(void)
Definition: mpc.c:2008
mpc_parser_t * mpc_lift(mpc_ctor_t lf)
Definition: mpc.c:1670
mpc_parser_t * mpc_boundary(void)
Definition: mpc.c:2005
mpc_parser_t * mpc_soi(void)
Definition: mpc.c:1977

References c, free(), mpc_alphanum(), mpc_and(), mpc_boundary(), mpc_char(), mpc_digit(), mpc_eoi(), mpc_lift(), mpc_not_lift(), mpc_soi(), mpc_whitespace(), mpcf_ctor_str(), mpcf_snd(), and NULL.

Referenced by mpcf_re_escape().

◆ mpc_re_mode()

mpc_parser_t* mpc_re_mode ( const char *  re,
int  mode 
)

Definition at line 2357 of file mpc.c.

2357  {
2358 
2359  char *err_msg;
2360  mpc_parser_t *err_out;
2361  mpc_result_t r;
2362  mpc_parser_t *Regex, *Term, *Factor, *Base, *Range, *RegexEnclose;
2363 
2364  Regex = mpc_new("regex");
2365  Term = mpc_new("term");
2366  Factor = mpc_new("factor");
2367  Base = mpc_new("base");
2368  Range = mpc_new("range");
2369 
2370  mpc_define(Regex, mpc_and(2, mpcf_re_or,
2371  Term,
2372  mpc_maybe(mpc_and(2, mpcf_snd_free, mpc_char('|'), Regex, free)),
2374  ));
2375 
2376  mpc_define(Term, mpc_many(mpcf_re_and, Factor));
2377 
2378  mpc_define(Factor, mpc_and(2, mpcf_re_repeat,
2379  Base,
2380  mpc_or(5,
2381  mpc_char('*'), mpc_char('+'), mpc_char('?'),
2383  mpc_pass()),
2385  ));
2386 
2387  mpc_define(Base, mpc_or(4,
2388  mpc_parens(Regex, (mpc_dtor_t)mpc_delete),
2392  ));
2393 
2394  mpc_define(Range, mpc_apply(
2397  ));
2398 
2399  RegexEnclose = mpc_whole(mpc_predictive(Regex), (mpc_dtor_t)mpc_delete);
2400 
2401  mpc_optimise(RegexEnclose);
2402  mpc_optimise(Regex);
2403  mpc_optimise(Term);
2404  mpc_optimise(Factor);
2405  mpc_optimise(Base);
2406  mpc_optimise(Range);
2407 
2408  if(!mpc_parse("<mpc_re_compiler>", re, RegexEnclose, &r)) {
2409  err_msg = mpc_err_string(r.error);
2410  err_out = mpc_failf("Invalid Regex: %s", err_msg);
2411  mpc_err_delete(r.error);
2412  free(err_msg);
2413  r.output = err_out;
2414  }
2415 
2416  mpc_cleanup(6, RegexEnclose, Regex, Term, Factor, Base, Range);
2417 
2418  mpc_optimise(r.output);
2419 
2420  return r.output;
2421 
2422 }
const char int mode
Definition: ioapi.h:137
mpc_parser_t * mpc_define(mpc_parser_t *p, mpc_parser_t *a)
Definition: mpc.c:1580
void mpc_optimise(mpc_parser_t *p)
Definition: mpc.c:4064
mpc_parser_t * mpc_noneof(const char *s)
Definition: mpc.c:1770
static mpc_val_t * mpcf_re_or(int n, mpc_val_t **xs)
Definition: mpc.c:2165
mpc_parser_t * mpc_brackets(mpc_parser_t *a, mpc_dtor_t ad)
Definition: mpc.c:2101
static mpc_val_t * mpcf_re_escape(mpc_val_t *x, void *data)
Definition: mpc.c:2219
mpc_parser_t * mpc_parens(mpc_parser_t *a, mpc_dtor_t ad)
Definition: mpc.c:2099
mpc_parser_t * mpc_predictive(mpc_parser_t *a)
Definition: mpc.c:1870
int mpc_parse(const char *filename, const char *string, mpc_parser_t *p, mpc_result_t *r)
Definition: mpc.c:1321
static mpc_val_t * mpcf_re_range(mpc_val_t *x)
Definition: mpc.c:2290
mpc_parser_t * mpc_new(const char *name)
Definition: mpc.c:1480
mpc_parser_t * mpc_apply_to(mpc_parser_t *a, mpc_apply_to_t f, void *x)
Definition: mpc.c:1806
static mpc_val_t * mpcf_re_repeat(int n, mpc_val_t **xs)
Definition: mpc.c:2180
mpc_parser_t * mpc_squares(mpc_parser_t *a, mpc_dtor_t ad)
Definition: mpc.c:2102
static mpc_val_t * mpcf_re_and(int n, mpc_val_t **xs)
Definition: mpc.c:2171
void mpc_cleanup(int n,...)
Definition: mpc.c:1596
mpc_parser_t * mpc_whole(mpc_parser_t *a, mpc_dtor_t da)
Definition: mpc.c:2083
mpc_parser_t * mpc_maybe(mpc_parser_t *a)
Definition: mpc.c:1898
mpc_parser_t * mpc_pass(void)
Definition: mpc.c:1610
void mpc_err_delete(mpc_err_t *x)
Definition: mpc.c:575

References free(), mpc_and(), mpc_apply(), mpc_apply_to(), mpc_brackets(), mpc_char(), mpc_cleanup(), mpc_define(), mpc_delete(), mpc_err_delete(), mpc_err_string(), mpc_escape(), mpc_failf(), mpc_int(), mpc_many(), mpc_maybe(), mpc_new(), mpc_noneof(), mpc_optimise(), mpc_or(), mpc_parens(), mpc_parse(), mpc_pass(), mpc_predictive(), mpc_squares(), mpc_whole(), mpcf_re_and(), mpcf_re_escape(), mpcf_re_or(), mpcf_re_range(), mpcf_re_repeat(), mpcf_snd_free(), mpcf_strfold(), and r.

Referenced by mpc_re(), and mpcaf_fold_regex().

◆ mpc_re_range_escape_char()

static const char* mpc_re_range_escape_char ( char  c)
static

Definition at line 2273 of file mpc.c.

2273  {
2274  switch (c) {
2275  case '-': return "-";
2276  case 'a': return "\a";
2277  case 'f': return "\f";
2278  case 'n': return "\n";
2279  case 'r': return "\r";
2280  case 't': return "\t";
2281  case 'v': return "\v";
2282  case 'b': return "\b";
2283  case 'd': return "0123456789";
2284  case 's': return " \f\n\r\t\v";
2285  case 'w': return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
2286  default: return NULL;
2287  }
2288 }

References c, and NULL.

Referenced by mpcf_re_range().

◆ mpc_real()

mpc_parser_t* mpc_real ( void  )

Definition at line 2034 of file mpc.c.

2034  {
2035 
2036  /* [+-]?\d+(\.\d+)?([eE][+-]?[0-9]+)? */
2037 
2038  mpc_parser_t *p0, *p1, *p2, *p30, *p31, *p32, *p3;
2039 
2040  p0 = mpc_maybe_lift(mpc_oneof("+-"), mpcf_ctor_str);
2041  p1 = mpc_digits();
2043  p30 = mpc_oneof("eE");
2044  p31 = mpc_maybe_lift(mpc_oneof("+-"), mpcf_ctor_str);
2045  p32 = mpc_digits();
2046  p3 = mpc_maybe_lift(mpc_and(3, mpcf_strfold, p30, p31, p32, free, free), mpcf_ctor_str);
2047 
2048  return mpc_expect(mpc_and(4, mpcf_strfold, p0, p1, p2, p3, free, free, free), "real");
2049 
2050 }

References free(), mpc_and(), mpc_char(), mpc_digits(), mpc_expect(), mpc_maybe_lift(), mpc_oneof(), mpcf_ctor_str(), and mpcf_strfold().

Referenced by mpc_float().

◆ mpc_realloc()

static void* mpc_realloc ( mpc_input_t i,
void *  p,
size_t  n 
)
static

Definition at line 270 of file mpc.c.

270  {
271 
272  char *q = NULL;
273 
274  if (!mpc_mem_ptr(i, p)) { return realloc(p, n); }
275 
276  if (n > sizeof(mpc_mem_t)) {
277  q = malloc(n);
278  memcpy(q, p, sizeof(mpc_mem_t));
279  mpc_free(i, p);
280  return q;
281  }
282 
283  return p;
284 }

References i, malloc(), memcpy(), mpc_free(), mpc_mem_ptr(), n, NULL, p, and realloc().

Referenced by mpc_err_add_expected(), mpc_err_repeat(), mpc_parse_run(), and mpcf_input_strfold().

◆ mpc_regex_lit()

mpc_parser_t* mpc_regex_lit ( void  )

Definition at line 2065 of file mpc.c.

2065  {
2066  mpc_parser_t *regexchar = mpc_or(2, mpc_escape(), mpc_noneof("/"));
2067  return mpc_expect(mpc_between(mpc_many(mpcf_strfold, regexchar), free, "/", "/"), "regex");
2068 }

References free(), mpc_between(), mpc_escape(), mpc_expect(), mpc_many(), mpc_noneof(), mpc_or(), and mpcf_strfold().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_satisfy()

mpc_parser_t* mpc_satisfy ( int(*)(char)  f)

Definition at line 1779 of file mpc.c.

1779  {
1781  p->type = MPC_TYPE_SATISFY;
1782  p->data.satisfy.f = f;
1783  return mpc_expectf(p, "character satisfying function %p", f);
1784 }

References f, mpc_expectf(), MPC_TYPE_SATISFY, mpc_undefined(), and p.

◆ mpc_soft_delete()

static void mpc_soft_delete ( mpc_val_t x)
static

Definition at line 1468 of file mpc.c.

1468  {
1470 }

References mpc_undefine_unretained(), and x.

Referenced by mpca_grammar_st(), mpca_lang_st(), and mpca_stmt_list_delete().

◆ mpc_soi()

mpc_parser_t* mpc_soi ( void  )

Definition at line 1977 of file mpc.c.

1977  {
1979  p->type = MPC_TYPE_SOI;
1980  return mpc_expect(p, "start of input");
1981 }

References mpc_expect(), MPC_TYPE_SOI, mpc_undefined(), and p.

Referenced by mpc_re_escape_char(), mpc_startwith(), mpc_whole(), and mpcf_re_escape().

◆ mpc_squares()

mpc_parser_t* mpc_squares ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2102 of file mpc.c.

2102 { return mpc_between(a, ad, "[", "]"); }

References a, and mpc_between().

Referenced by mpc_re_mode().

◆ mpc_startwith()

mpc_parser_t* mpc_startwith ( mpc_parser_t a)

Definition at line 2081 of file mpc.c.

2081 { return mpc_and(2, mpcf_snd, mpc_soi(), a, mpcf_dtor_null); }
void mpcf_dtor_null(mpc_val_t *x)
Definition: mpc.c:2428

References a, mpc_and(), mpc_soi(), mpcf_dtor_null(), and mpcf_snd().

◆ mpc_state()

mpc_parser_t* mpc_state ( void  )

Definition at line 1684 of file mpc.c.

1684  {
1686  p->type = MPC_TYPE_STATE;
1687  return p;
1688 }

References MPC_TYPE_STATE, mpc_undefined(), and p.

Referenced by mpca_state().

◆ mpc_state_invalid()

static mpc_state_t mpc_state_invalid ( void  )
static

Definition at line 7 of file mpc.c.

7  {
9  s.pos = -1;
10  s.row = -1;
11  s.col = -1;
12  s.term = 0;
13  return s;
14 }

References s.

Referenced by mpc_err_or(), and mpc_parse_input().

◆ mpc_state_new()

static mpc_state_t mpc_state_new ( void  )
static

Definition at line 16 of file mpc.c.

16  {
17  mpc_state_t s;
18  s.pos = 0;
19  s.row = 0;
20  s.col = 0;
21  s.term = 0;
22  return s;
23 }

References s.

Referenced by mpc_ast_new(), mpc_err_file(), mpc_input_new_file(), mpc_input_new_nstring(), mpc_input_new_pipe(), and mpc_input_new_string().

◆ mpc_stats()

void mpc_stats ( mpc_parser_t p)

Definition at line 3889 of file mpc.c.

3889  {
3890  printf("Stats\n");
3891  printf("=====\n");
3892  printf("Node Count: %i\n", mpc_nodecount_unretained(p, 1));
3893 }

References mpc_nodecount_unretained(), p, and printf().

◆ mpc_string()

mpc_parser_t* mpc_string ( const char *  s)

Definition at line 1786 of file mpc.c.

1786  {
1788  p->type = MPC_TYPE_STRING;
1789  p->data.string.x = malloc(strlen(s) + 1);
1790  strcpy(p->data.string.x, s);
1791  return mpc_expectf(p, "\"%s\"", s);
1792 }

References malloc(), mpc_expectf(), MPC_TYPE_STRING, mpc_undefined(), p, and s.

Referenced by mpc_between(), mpc_sym(), and mpcaf_grammar_string().

◆ mpc_string_lit()

mpc_parser_t* mpc_string_lit ( void  )

Definition at line 2060 of file mpc.c.

2060  {
2061  mpc_parser_t *strchar = mpc_or(2, mpc_escape(), mpc_noneof("\""));
2062  return mpc_expect(mpc_between(mpc_many(mpcf_strfold, strchar), free, "\"", "\""), "string");
2063 }

References free(), mpc_between(), mpc_escape(), mpc_expect(), mpc_many(), mpc_noneof(), mpc_or(), and mpcf_strfold().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_strip()

mpc_parser_t* mpc_strip ( mpc_parser_t a)

Definition at line 2087 of file mpc.c.

mpc_parser_t * mpc_blank(void)
Definition: mpc.c:2010

References a, mpc_and(), mpc_blank(), mpcf_dtor_null(), and mpcf_snd().

Referenced by mpc_total().

◆ mpc_stripl()

mpc_parser_t* mpc_stripl ( mpc_parser_t a)

Definition at line 2085 of file mpc.c.

2085 { return mpc_and(2, mpcf_snd, mpc_blank(), a, mpcf_dtor_null); }

References a, mpc_and(), mpc_blank(), mpcf_dtor_null(), and mpcf_snd().

◆ mpc_stripr()

mpc_parser_t* mpc_stripr ( mpc_parser_t a)

Definition at line 2086 of file mpc.c.

2086 { return mpc_and(2, mpcf_fst, a, mpc_blank(), mpcf_dtor_null); }

References a, mpc_and(), mpc_blank(), mpcf_dtor_null(), and mpcf_fst().

◆ mpc_sym()

mpc_parser_t* mpc_sym ( const char *  s)

Definition at line 2089 of file mpc.c.

2089 { return mpc_tok(mpc_string(s)); }
mpc_parser_t * mpc_tok(mpc_parser_t *a)
Definition: mpc.c:2088

References mpc_string(), mpc_tok(), and s.

Referenced by mpc_tok_between(), mpca_grammar_st(), and mpca_lang_st().

◆ mpc_tab()

mpc_parser_t* mpc_tab ( void  )

Definition at line 2013 of file mpc.c.

2013 { return mpc_expect(mpc_char('\t'), "tab"); }

References mpc_char(), and mpc_expect().

◆ mpc_test_fail()

int mpc_test_fail ( mpc_parser_t p,
const char *  s,
const void *  d,
int(*)(const void *, const void *)  tester,
mpc_dtor_t  destructor,
void(*)(const void *)  printer 
)

Definition at line 2831 of file mpc.c.

2834  {
2835  mpc_result_t r;
2836  (void) printer;
2837  if (mpc_parse("<test>", s, p, &r)) {
2838 
2839  if (tester(r.output, d)) {
2840  destructor(r.output);
2841  return 0;
2842  } else {
2843  destructor(r.output);
2844  return 1;
2845  }
2846 
2847  } else {
2848  mpc_err_delete(r.error);
2849  return 1;
2850  }
2851 
2852 }

References d, mpc_err_delete(), mpc_parse(), p, r, and s.

◆ mpc_test_pass()

int mpc_test_pass ( mpc_parser_t p,
const char *  s,
const void *  d,
int(*)(const void *, const void *)  tester,
mpc_dtor_t  destructor,
void(*)(const void *)  printer 
)

Definition at line 2854 of file mpc.c.

2857  {
2858 
2859  mpc_result_t r;
2860  if (mpc_parse("<test>", s, p, &r)) {
2861 
2862  if (tester(r.output, d)) {
2863  destructor(r.output);
2864  return 1;
2865  } else {
2866  printf("Got "); printer(r.output); printf("\n");
2867  printf("Expected "); printer(d); printf("\n");
2868  destructor(r.output);
2869  return 0;
2870  }
2871 
2872  } else {
2873  mpc_err_print(r.error);
2874  mpc_err_delete(r.error);
2875  return 0;
2876 
2877  }
2878 
2879 }
void mpc_err_print(mpc_err_t *x)
Definition: mpc.c:584

References d, mpc_err_delete(), mpc_err_print(), mpc_parse(), p, printf(), r, and s.

◆ mpc_tok()

◆ mpc_tok_between()

mpc_parser_t* mpc_tok_between ( mpc_parser_t a,
mpc_dtor_t  ad,
const char *  o,
const char *  c 
)

Definition at line 2104 of file mpc.c.

2104  {
2105  return mpc_and(3, mpcf_snd_free,
2106  mpc_sym(o), mpc_tok(a), mpc_sym(c),
2107  free, ad);
2108 }
mpc_parser_t * mpc_sym(const char *s)
Definition: mpc.c:2089

References a, c, free(), mpc_and(), mpc_sym(), mpc_tok(), and mpcf_snd_free().

Referenced by mpc_tok_braces(), mpc_tok_brackets(), mpc_tok_parens(), and mpc_tok_squares().

◆ mpc_tok_braces()

mpc_parser_t* mpc_tok_braces ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2111 of file mpc.c.

2111 { return mpc_tok_between(a, ad, "<", ">"); }
mpc_parser_t * mpc_tok_between(mpc_parser_t *a, mpc_dtor_t ad, const char *o, const char *c)
Definition: mpc.c:2104

References a, and mpc_tok_between().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_tok_brackets()

mpc_parser_t* mpc_tok_brackets ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2112 of file mpc.c.

2112 { return mpc_tok_between(a, ad, "{", "}"); }

References a, and mpc_tok_between().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_tok_parens()

mpc_parser_t* mpc_tok_parens ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2110 of file mpc.c.

2110 { return mpc_tok_between(a, ad, "(", ")"); }

References a, and mpc_tok_between().

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpc_tok_squares()

mpc_parser_t* mpc_tok_squares ( mpc_parser_t a,
mpc_dtor_t  ad 
)

Definition at line 2113 of file mpc.c.

2113 { return mpc_tok_between(a, ad, "[", "]"); }

References a, and mpc_tok_between().

◆ mpc_total()

mpc_parser_t* mpc_total ( mpc_parser_t a,
mpc_dtor_t  da 
)

Definition at line 2091 of file mpc.c.

2091 { return mpc_whole(mpc_strip(a), da); }
mpc_parser_t * mpc_strip(mpc_parser_t *a)
Definition: mpc.c:2087

References a, mpc_strip(), and mpc_whole().

Referenced by mpca_grammar_st(), mpca_lang_st(), and mpca_total().

◆ mpc_undefine()

mpc_parser_t* mpc_undefine ( mpc_parser_t p)

Definition at line 1574 of file mpc.c.

1574  {
1576  p->type = MPC_TYPE_UNDEFINED;
1577  return p;
1578 }

References MPC_TYPE_UNDEFINED, mpc_undefine_unretained(), and p.

Referenced by mpc_cleanup().

◆ mpc_undefine_and()

static void mpc_undefine_and ( mpc_parser_t p)
static

Definition at line 1385 of file mpc.c.

1385  {
1386 
1387  int i;
1388  for (i = 0; i < p->data.and.n; i++) {
1389  mpc_undefine_unretained(p->data.and.xs[i], 0);
1390  }
1391  free(p->data.and.xs);
1392  free(p->data.and.dxs);
1393 
1394 }

References free(), i, mpc_undefine_unretained(), and p.

Referenced by mpc_undefine_unretained().

◆ mpc_undefine_or()

static void mpc_undefine_or ( mpc_parser_t p)
static

Definition at line 1375 of file mpc.c.

1375  {
1376 
1377  int i;
1378  for (i = 0; i < p->data.or.n; i++) {
1379  mpc_undefine_unretained(p->data.or.xs[i], 0);
1380  }
1381  free(p->data.or.xs);
1382 
1383 }

References free(), i, mpc_undefine_unretained(), and p.

Referenced by mpc_undefine_unretained().

◆ mpc_undefine_unretained()

static void mpc_undefine_unretained ( mpc_parser_t p,
int  force 
)
static

Definition at line 1396 of file mpc.c.

1396  {
1397 
1398  if (p->retained && !force) { return; }
1399 
1400  switch (p->type) {
1401 
1402  case MPC_TYPE_FAIL: free(p->data.fail.m); break;
1403 
1404  case MPC_TYPE_ONEOF:
1405  case MPC_TYPE_NONEOF:
1406  case MPC_TYPE_STRING:
1407  free(p->data.string.x);
1408  break;
1409 
1410  case MPC_TYPE_APPLY: mpc_undefine_unretained(p->data.apply.x, 0); break;
1411  case MPC_TYPE_APPLY_TO: mpc_undefine_unretained(p->data.apply_to.x, 0); break;
1412  case MPC_TYPE_PREDICT: mpc_undefine_unretained(p->data.predict.x, 0); break;
1413 
1414  case MPC_TYPE_MAYBE:
1415  case MPC_TYPE_NOT:
1416  mpc_undefine_unretained(p->data.not.x, 0);
1417  break;
1418 
1419  case MPC_TYPE_EXPECT:
1420  mpc_undefine_unretained(p->data.expect.x, 0);
1421  free(p->data.expect.m);
1422  break;
1423 
1424  case MPC_TYPE_MANY:
1425  case MPC_TYPE_MANY1:
1426  case MPC_TYPE_COUNT:
1427  mpc_undefine_unretained(p->data.repeat.x, 0);
1428  break;
1429 
1430  case MPC_TYPE_OR: mpc_undefine_or(p); break;
1431  case MPC_TYPE_AND: mpc_undefine_and(p); break;
1432 
1433  case MPC_TYPE_CHECK:
1434  mpc_undefine_unretained(p->data.check.x, 0);
1435  free(p->data.check.e);
1436  break;
1437 
1438  case MPC_TYPE_CHECK_WITH:
1439  mpc_undefine_unretained(p->data.check_with.x, 0);
1440  free(p->data.check_with.e);
1441  break;
1442 
1443  default: break;
1444  }
1445 
1446  if (!force) {
1447  free(p->name);
1448  free(p);
1449  }
1450 
1451 }
static void mpc_undefine_or(mpc_parser_t *p)
Definition: mpc.c:1375
static void mpc_undefine_and(mpc_parser_t *p)
Definition: mpc.c:1385

References free(), MPC_TYPE_AND, MPC_TYPE_APPLY, MPC_TYPE_APPLY_TO, MPC_TYPE_CHECK, MPC_TYPE_CHECK_WITH, MPC_TYPE_COUNT, MPC_TYPE_EXPECT, MPC_TYPE_FAIL, MPC_TYPE_MANY, MPC_TYPE_MANY1, MPC_TYPE_MAYBE, MPC_TYPE_NONEOF, MPC_TYPE_NOT, MPC_TYPE_ONEOF, MPC_TYPE_OR, MPC_TYPE_PREDICT, MPC_TYPE_STRING, mpc_undefine_and(), mpc_undefine_or(), and p.

Referenced by mpc_delete(), mpc_soft_delete(), mpc_undefine(), mpc_undefine_and(), and mpc_undefine_or().

◆ mpc_undefined()

◆ mpc_underscore()

mpc_parser_t* mpc_underscore ( void  )

Definition at line 2026 of file mpc.c.

2026 { return mpc_expect(mpc_char('_'), "underscore"); }

References mpc_char(), and mpc_expect().

Referenced by mpc_alphanum(), and mpc_ident().

◆ mpc_upper()

mpc_parser_t* mpc_upper ( void  )

Definition at line 2024 of file mpc.c.

2024 { return mpc_expect(mpc_oneof("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "uppercase letter"); }

References mpc_expect(), and mpc_oneof().

◆ mpc_whitespace()

mpc_parser_t* mpc_whitespace ( void  )

Definition at line 2008 of file mpc.c.

2008 { return mpc_expect(mpc_oneof(" \f\n\r\t\v"), "whitespace"); }

References mpc_expect(), and mpc_oneof().

Referenced by mpc_re_escape_char(), and mpc_whitespaces().

◆ mpc_whitespaces()

mpc_parser_t* mpc_whitespaces ( void  )

Definition at line 2009 of file mpc.c.

2009 { return mpc_expect(mpc_many(mpcf_strfold, mpc_whitespace()), "spaces"); }

References mpc_expect(), mpc_many(), mpc_whitespace(), and mpcf_strfold().

Referenced by mpc_blank().

◆ mpc_whole()

mpc_parser_t* mpc_whole ( mpc_parser_t a,
mpc_dtor_t  da 
)

Definition at line 2083 of file mpc.c.

2083 { return mpc_and(3, mpcf_snd, mpc_soi(), a, mpc_eoi(), mpcf_dtor_null, da); }

References a, mpc_and(), mpc_eoi(), mpc_soi(), mpcf_dtor_null(), and mpcf_snd().

Referenced by mpc_re_mode(), and mpc_total().

◆ mpca_add_tag()

mpc_parser_t* mpca_add_tag ( mpc_parser_t a,
const char *  t 
)

Definition at line 3273 of file mpc.c.

3273  {
3274  return mpc_apply_to(a, (mpc_apply_to_t)mpc_ast_add_tag, (void*)t);
3275 }
mpc_ast_t * mpc_ast_add_tag(mpc_ast_t *a, const char *t)
Definition: mpc.c:2981
mpc_val_t *(* mpc_apply_to_t)(mpc_val_t *, void *)
Definition: mpc.h:82

References a, mpc_apply_to(), and mpc_ast_add_tag().

Referenced by mpcaf_grammar_id().

◆ mpca_and()

mpc_parser_t* mpca_and ( int  n,
  ... 
)

Definition at line 3308 of file mpc.c.

3308  {
3309 
3310  int i;
3311  va_list va;
3312 
3314 
3315  p->type = MPC_TYPE_AND;
3316  p->data.and.n = n;
3317  p->data.and.f = mpcf_fold_ast;
3318  p->data.and.xs = malloc(sizeof(mpc_parser_t*) * n);
3319  p->data.and.dxs = malloc(sizeof(mpc_dtor_t) * (n-1));
3320 
3321  va_start(va, n);
3322  for (i = 0; i < n; i++) {
3323  p->data.and.xs[i] = va_arg(va, mpc_parser_t*);
3324  }
3325  for (i = 0; i < (n-1); i++) {
3326  p->data.and.dxs[i] = (mpc_dtor_t)mpc_ast_delete;
3327  }
3328  va_end(va);
3329 
3330  return p;
3331 }

References i, malloc(), mpc_ast_delete(), MPC_TYPE_AND, mpc_undefined(), mpcf_fold_ast(), n, and p.

Referenced by mpcaf_grammar_and().

◆ mpca_count()

mpc_parser_t* mpca_count ( int  n,
mpc_parser_t a 
)

Definition at line 3285 of file mpc.c.

mpc_parser_t * mpc_count(int n, mpc_fold_t f, mpc_parser_t *a, mpc_dtor_t da)
Definition: mpc.c:1918

References a, mpc_ast_delete(), mpc_count(), mpcf_fold_ast(), and n.

Referenced by mpcaf_grammar_repeat().

◆ mpca_grammar()

mpc_parser_t* mpca_grammar ( int  flags,
const char *  grammar,
  ... 
)

Definition at line 3588 of file mpc.c.

3588  {
3589  mpca_grammar_st_t st;
3590  mpc_parser_t *res;
3591  va_list va;
3592  va_start(va, grammar);
3593 
3594  st.va = &va;
3595  st.parsers_num = 0;
3596  st.parsers = NULL;
3597  st.flags = flags;
3598 
3599  res = mpca_grammar_st(grammar, &st);
3600  free(st.parsers);
3601  va_end(va);
3602  return res;
3603 }
mpc_parser_t * mpca_grammar_st(const char *grammar, mpca_grammar_st_t *st)
Definition: mpc.c:3521
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
va_list * va
Definition: mpc.c:3380
int parsers_num
Definition: mpc.c:3381
mpc_parser_t ** parsers
Definition: mpc.c:3382

References flags, mpca_grammar_st_t::flags, free(), mpca_grammar_st(), NULL, mpca_grammar_st_t::parsers, mpca_grammar_st_t::parsers_num, and mpca_grammar_st_t::va.

◆ mpca_grammar_find_parser()

static mpc_parser_t* mpca_grammar_find_parser ( char *  x,
mpca_grammar_st_t st 
)
static

Definition at line 3459 of file mpc.c.

3459  {
3460 
3461  int i;
3462  mpc_parser_t *p;
3463 
3464  /* Case of Number */
3465  if (is_number(x)) {
3466 
3467  i = strtol(x, NULL, 10);
3468 
3469  while (st->parsers_num <= i) {
3470  st->parsers_num++;
3471  st->parsers = realloc(st->parsers, sizeof(mpc_parser_t*) * st->parsers_num);
3472  st->parsers[st->parsers_num-1] = va_arg(*st->va, mpc_parser_t*);
3473  if (st->parsers[st->parsers_num-1] == NULL) {
3474  return mpc_failf("No Parser in position %i! Only supplied %i Parsers!", i, st->parsers_num);
3475  }
3476  }
3477 
3478  return st->parsers[st->parsers_num-1];
3479 
3480  /* Case of Identifier */
3481  } else {
3482 
3483  /* Search Existing Parsers */
3484  for (i = 0; i < st->parsers_num; i++) {
3485  mpc_parser_t *q = st->parsers[i];
3486  if (q == NULL) { return mpc_failf("Unknown Parser '%s'!", x); }
3487  if (q->name && strcmp(q->name, x) == 0) { return q; }
3488  }
3489 
3490  /* Search New Parsers */
3491  while (1) {
3492 
3493  p = va_arg(*st->va, mpc_parser_t*);
3494 
3495  st->parsers_num++;
3496  st->parsers = realloc(st->parsers, sizeof(mpc_parser_t*) * st->parsers_num);
3497  st->parsers[st->parsers_num-1] = p;
3498 
3499  if (p == NULL || p->name == NULL) { return mpc_failf("Unknown Parser '%s'!", x); }
3500  if (p->name && strcmp(p->name, x) == 0) { return p; }
3501 
3502  }
3503 
3504  }
3505 
3506 }
static int is_number(const char *s)
Definition: mpc.c:3453

References i, is_number(), mpc_failf(), mpc_parser_t::name, NULL, p, mpca_grammar_st_t::parsers, mpca_grammar_st_t::parsers_num, realloc(), mpca_grammar_st_t::va, and x.

Referenced by mpca_stmt_list_apply_to(), and mpcaf_grammar_id().

◆ mpca_grammar_st()

mpc_parser_t* mpca_grammar_st ( const char *  grammar,
mpca_grammar_st_t st 
)

Definition at line 3521 of file mpc.c.

3521  {
3522 
3523  char *err_msg;
3524  mpc_parser_t *err_out;
3525  mpc_result_t r;
3526  mpc_parser_t *GrammarTotal, *Grammar, *Term, *Factor, *Base;
3527 
3528  GrammarTotal = mpc_new("grammar_total");
3529  Grammar = mpc_new("grammar");
3530  Term = mpc_new("term");
3531  Factor = mpc_new("factor");
3532  Base = mpc_new("base");
3533 
3534  mpc_define(GrammarTotal,
3536  );
3537 
3538  mpc_define(Grammar, mpc_and(2, mpcaf_grammar_or,
3539  Term,
3540  mpc_maybe(mpc_and(2, mpcf_snd_free, mpc_sym("|"), Grammar, free)),
3542  ));
3543 
3544  mpc_define(Term, mpc_many1(mpcaf_grammar_and, Factor));
3545 
3547  Base,
3548  mpc_or(6,
3549  mpc_sym("*"),
3550  mpc_sym("+"),
3551  mpc_sym("?"),
3552  mpc_sym("!"),
3554  mpc_pass()),
3556  ));
3557 
3558  mpc_define(Base, mpc_or(5,
3564  ));
3565 
3566  mpc_optimise(GrammarTotal);
3567  mpc_optimise(Grammar);
3568  mpc_optimise(Factor);
3569  mpc_optimise(Term);
3570  mpc_optimise(Base);
3571 
3572  if(!mpc_parse("<mpc_grammar_compiler>", grammar, GrammarTotal, &r)) {
3573  err_msg = mpc_err_string(r.error);
3574  err_out = mpc_failf("Invalid Grammar: %s", err_msg);
3575  mpc_err_delete(r.error);
3576  free(err_msg);
3577  r.output = err_out;
3578  }
3579 
3580  mpc_cleanup(5, GrammarTotal, Grammar, Term, Factor, Base);
3581 
3582  mpc_optimise(r.output);
3583 
3584  return (st->flags & MPCA_LANG_PREDICTIVE) ? mpc_predictive(r.output) : r.output;
3585 
3586 }
mpc_parser_t * mpc_lift_val(mpc_val_t *x)
Definition: mpc.c:1663
static void mpc_soft_delete(mpc_val_t *x)
Definition: mpc.c:1468
static mpc_val_t * mpcaf_grammar_string(mpc_val_t *x, void *s)
Definition: mpc.c:3418
mpc_parser_t * mpc_tok_parens(mpc_parser_t *a, mpc_dtor_t ad)
Definition: mpc.c:2110
static mpc_val_t * mpcaf_grammar_and(int n, mpc_val_t **xs)
Definition: mpc.c:3392
mpc_parser_t * mpc_string_lit(void)
Definition: mpc.c:2060
mpc_parser_t * mpc_ident(void)
Definition: mpc.c:2070
mpc_parser_t * mpc_total(mpc_parser_t *a, mpc_dtor_t da)
Definition: mpc.c:2091
static mpc_val_t * mpcaf_grammar_id(mpc_val_t *x, void *s)
Definition: mpc.c:3508
mpc_parser_t * mpc_char_lit(void)
Definition: mpc.c:2056
static mpc_val_t * mpcaf_fold_regex(int n, mpc_val_t **xs)
Definition: mpc.c:3434
static mpc_val_t * mpcaf_grammar_repeat(int n, mpc_val_t **xs)
Definition: mpc.c:3401
mpc_parser_t * mpc_tok_brackets(mpc_parser_t *a, mpc_dtor_t ad)
Definition: mpc.c:2112
static mpc_val_t * mpcaf_grammar_char(mpc_val_t *x, void *s)
Definition: mpc.c:3426
mpc_parser_t * mpc_tok_braces(mpc_parser_t *a, mpc_dtor_t ad)
Definition: mpc.c:2111
mpc_parser_t * mpc_regex_lit(void)
Definition: mpc.c:2065
static mpc_val_t * mpcaf_grammar_or(int n, mpc_val_t **xs)
Definition: mpc.c:3386
@ MPCA_LANG_PREDICTIVE
Definition: mpc.h:356

References mpca_grammar_st_t::flags, free(), mpc_and(), mpc_apply_to(), mpc_char_lit(), mpc_cleanup(), mpc_define(), mpc_digits(), mpc_err_delete(), mpc_err_string(), mpc_failf(), mpc_ident(), mpc_int(), mpc_lift_val(), mpc_many(), mpc_many1(), mpc_maybe(), mpc_new(), mpc_oneof(), mpc_optimise(), mpc_or(), mpc_parse(), mpc_pass(), mpc_predictive(), mpc_regex_lit(), mpc_soft_delete(), mpc_string_lit(), mpc_sym(), mpc_tok(), mpc_tok_braces(), mpc_tok_brackets(), mpc_tok_parens(), mpc_total(), MPCA_LANG_PREDICTIVE, mpcaf_fold_regex(), mpcaf_grammar_and(), mpcaf_grammar_char(), mpcaf_grammar_id(), mpcaf_grammar_or(), mpcaf_grammar_repeat(), mpcaf_grammar_string(), mpcf_snd_free(), mpcf_strfold(), and r.

Referenced by mpca_grammar().

◆ mpca_lang()

mpc_err_t* mpca_lang ( int  flags,
const char *  language,
  ... 
)

Definition at line 3790 of file mpc.c.

3790  {
3791 
3792  mpca_grammar_st_t st;
3793  mpc_input_t *i;
3794  mpc_err_t *err;
3795 
3796  va_list va;
3797  va_start(va, language);
3798 
3799  st.va = &va;
3800  st.parsers_num = 0;
3801  st.parsers = NULL;
3802  st.flags = flags;
3803 
3804  i = mpc_input_new_string("<mpca_lang>", language);
3805  err = mpca_lang_st(i, &st);
3807 
3808  free(st.parsers);
3809  va_end(va);
3810  return err;
3811 }
static bool err
Definition: armass.c:435
static mpc_err_t * mpca_lang_st(mpc_input_t *i, mpca_grammar_st_t *st)
Definition: mpc.c:3677

References err, flags, mpca_grammar_st_t::flags, free(), i, mpc_input_delete(), mpc_input_new_string(), mpca_lang_st(), NULL, mpca_grammar_st_t::parsers, mpca_grammar_st_t::parsers_num, and mpca_grammar_st_t::va.

Referenced by main().

◆ mpca_lang_contents()

mpc_err_t* mpca_lang_contents ( int  flags,
const char *  filename,
  ... 
)

Definition at line 3813 of file mpc.c.

3813  {
3814 
3815  mpca_grammar_st_t st;
3816  mpc_input_t *i;
3817  mpc_err_t *err;
3818 
3819  va_list va;
3820 
3821  FILE *f = fopen(filename, "rb");
3822 
3823  if (f == NULL) {
3824  err = mpc_err_file(filename, "Unable to open file!");
3825  return err;
3826  }
3827 
3828  va_start(va, filename);
3829 
3830  st.va = &va;
3831  st.parsers_num = 0;
3832  st.parsers = NULL;
3833  st.flags = flags;
3834 
3836  err = mpca_lang_st(i, &st);
3838 
3839  free(st.parsers);
3840  va_end(va);
3841 
3842  fclose(f);
3843 
3844  return err;
3845 }

References err, f, benchmark::FILE, flags, mpca_grammar_st_t::flags, free(), i, mpc_err_file(), mpc_input_delete(), mpc_input_new_file(), mpca_lang_st(), NULL, mpca_grammar_st_t::parsers, mpca_grammar_st_t::parsers_num, and mpca_grammar_st_t::va.

◆ mpca_lang_file()

mpc_err_t* mpca_lang_file ( int  flags,
FILE *  f,
  ... 
)

Definition at line 3746 of file mpc.c.

3746  {
3747  mpca_grammar_st_t st;
3748  mpc_input_t *i;
3749  mpc_err_t *err;
3750 
3751  va_list va;
3752  va_start(va, f);
3753 
3754  st.va = &va;
3755  st.parsers_num = 0;
3756  st.parsers = NULL;
3757  st.flags = flags;
3758 
3759  i = mpc_input_new_file("<mpca_lang_file>", f);
3760  err = mpca_lang_st(i, &st);
3762 
3763  free(st.parsers);
3764  va_end(va);
3765  return err;
3766 }

References err, f, flags, mpca_grammar_st_t::flags, free(), i, mpc_input_delete(), mpc_input_new_file(), mpca_lang_st(), NULL, mpca_grammar_st_t::parsers, mpca_grammar_st_t::parsers_num, and mpca_grammar_st_t::va.

◆ mpca_lang_pipe()

mpc_err_t* mpca_lang_pipe ( int  flags,
FILE *  p,
  ... 
)

Definition at line 3768 of file mpc.c.

3768  {
3769  mpca_grammar_st_t st;
3770  mpc_input_t *i;
3771  mpc_err_t *err;
3772 
3773  va_list va;
3774  va_start(va, p);
3775 
3776  st.va = &va;
3777  st.parsers_num = 0;
3778  st.parsers = NULL;
3779  st.flags = flags;
3780 
3781  i = mpc_input_new_pipe("<mpca_lang_pipe>", p);
3782  err = mpca_lang_st(i, &st);
3784 
3785  free(st.parsers);
3786  va_end(va);
3787  return err;
3788 }

References err, flags, mpca_grammar_st_t::flags, free(), i, mpc_input_delete(), mpc_input_new_pipe(), mpca_lang_st(), NULL, p, mpca_grammar_st_t::parsers, mpca_grammar_st_t::parsers_num, and mpca_grammar_st_t::va.

◆ mpca_lang_st()

static mpc_err_t* mpca_lang_st ( mpc_input_t i,
mpca_grammar_st_t st 
)
static

Definition at line 3677 of file mpc.c.

3677  {
3678 
3679  mpc_result_t r;
3680  mpc_err_t *e;
3681  mpc_parser_t *Lang, *Stmt, *Grammar, *Term, *Factor, *Base;
3682 
3683  Lang = mpc_new("lang");
3684  Stmt = mpc_new("stmt");
3685  Grammar = mpc_new("grammar");
3686  Term = mpc_new("term");
3687  Factor = mpc_new("factor");
3688  Base = mpc_new("base");
3689 
3690  mpc_define(Lang, mpc_apply_to(
3693  ));
3694 
3696  mpc_tok(mpc_ident()), mpc_maybe(mpc_tok(mpc_string_lit())), mpc_sym(":"), Grammar, mpc_sym(";"),
3698  ));
3699 
3700  mpc_define(Grammar, mpc_and(2, mpcaf_grammar_or,
3701  Term,
3702  mpc_maybe(mpc_and(2, mpcf_snd_free, mpc_sym("|"), Grammar, free)),
3704  ));
3705 
3706  mpc_define(Term, mpc_many1(mpcaf_grammar_and, Factor));
3707 
3709  Base,
3710  mpc_or(6,
3711  mpc_sym("*"),
3712  mpc_sym("+"),
3713  mpc_sym("?"),
3714  mpc_sym("!"),
3716  mpc_pass()),
3718  ));
3719 
3720  mpc_define(Base, mpc_or(5,
3726  ));
3727 
3728  mpc_optimise(Lang);
3729  mpc_optimise(Stmt);
3730  mpc_optimise(Grammar);
3731  mpc_optimise(Term);
3732  mpc_optimise(Factor);
3733  mpc_optimise(Base);
3734 
3735  if (!mpc_parse_input(i, Lang, &r)) {
3736  e = r.error;
3737  } else {
3738  e = NULL;
3739  }
3740 
3741  mpc_cleanup(6, Lang, Stmt, Grammar, Term, Factor, Base);
3742 
3743  return e;
3744 }
static mpc_val_t * mpca_stmt_afold(int n, mpc_val_t **xs)
Definition: mpc.c:3611
static mpc_val_t * mpca_stmt_fold(int n, mpc_val_t **xs)
Definition: mpc.c:3623
static void mpca_stmt_list_delete(mpc_val_t *x)
Definition: mpc.c:3636
static mpc_val_t * mpca_stmt_list_apply_to(mpc_val_t *x, void *s)
Definition: mpc.c:3652

References e, free(), i, mpc_and(), mpc_apply_to(), mpc_char_lit(), mpc_cleanup(), mpc_define(), mpc_digits(), mpc_ident(), mpc_int(), mpc_lift_val(), mpc_many(), mpc_many1(), mpc_maybe(), mpc_new(), mpc_oneof(), mpc_optimise(), mpc_or(), mpc_parse_input(), mpc_pass(), mpc_predictive(), mpc_regex_lit(), mpc_soft_delete(), mpc_string_lit(), mpc_sym(), mpc_tok(), mpc_tok_braces(), mpc_tok_brackets(), mpc_tok_parens(), mpc_total(), mpca_stmt_afold(), mpca_stmt_fold(), mpca_stmt_list_apply_to(), mpca_stmt_list_delete(), mpcaf_fold_regex(), mpcaf_grammar_and(), mpcaf_grammar_char(), mpcaf_grammar_id(), mpcaf_grammar_or(), mpcaf_grammar_repeat(), mpcaf_grammar_string(), mpcf_snd_free(), mpcf_strfold(), NULL, and r.

Referenced by mpca_lang(), mpca_lang_contents(), mpca_lang_file(), and mpca_lang_pipe().

◆ mpca_many()

mpc_parser_t* mpca_many ( mpc_parser_t a)

Definition at line 3283 of file mpc.c.

3283 { return mpc_many(mpcf_fold_ast, a); }

References a, mpc_many(), and mpcf_fold_ast().

Referenced by mpcaf_grammar_repeat().

◆ mpca_many1()

mpc_parser_t* mpca_many1 ( mpc_parser_t a)

Definition at line 3284 of file mpc.c.

3284 { return mpc_many1(mpcf_fold_ast, a); }

References a, mpc_many1(), and mpcf_fold_ast().

Referenced by mpcaf_grammar_repeat().

◆ mpca_maybe()

mpc_parser_t* mpca_maybe ( mpc_parser_t a)

Definition at line 3282 of file mpc.c.

3282 { return mpc_maybe(a); }

References a, and mpc_maybe().

Referenced by mpcaf_grammar_repeat().

◆ mpca_not()

mpc_parser_t* mpca_not ( mpc_parser_t a)

Definition at line 3281 of file mpc.c.

3281 { return mpc_not(a, (mpc_dtor_t)mpc_ast_delete); }
mpc_parser_t * mpc_not(mpc_parser_t *a, mpc_dtor_t da)
Definition: mpc.c:1886

References a, mpc_ast_delete(), and mpc_not().

Referenced by mpcaf_grammar_repeat().

◆ mpca_or()

mpc_parser_t* mpca_or ( int  n,
  ... 
)

Definition at line 3287 of file mpc.c.

3287  {
3288 
3289  int i;
3290  va_list va;
3291 
3293 
3294  p->type = MPC_TYPE_OR;
3295  p->data.or.n = n;
3296  p->data.or.xs = malloc(sizeof(mpc_parser_t*) * n);
3297 
3298  va_start(va, n);
3299  for (i = 0; i < n; i++) {
3300  p->data.or.xs[i] = va_arg(va, mpc_parser_t*);
3301  }
3302  va_end(va);
3303 
3304  return p;
3305 
3306 }

References i, malloc(), MPC_TYPE_OR, mpc_undefined(), n, and p.

Referenced by mpcaf_grammar_or().

◆ mpca_root()

mpc_parser_t* mpca_root ( mpc_parser_t a)

Definition at line 3277 of file mpc.c.

3277  {
3279 }
mpc_ast_t * mpc_ast_add_root(mpc_ast_t *a)
Definition: mpc.c:2946
mpc_val_t *(* mpc_apply_t)(mpc_val_t *)
Definition: mpc.h:81

References a, mpc_apply(), and mpc_ast_add_root().

Referenced by mpcaf_grammar_id().

◆ mpca_state()

mpc_parser_t* mpca_state ( mpc_parser_t a)

Definition at line 3265 of file mpc.c.

3265  {
3266  return mpc_and(2, mpcf_state_ast, mpc_state(), a, free);
3267 }
mpc_parser_t * mpc_state(void)
Definition: mpc.c:1684

References a, free(), mpc_and(), mpc_state(), and mpcf_state_ast().

Referenced by mpcaf_fold_regex(), mpcaf_grammar_char(), mpcaf_grammar_id(), and mpcaf_grammar_string().

◆ mpca_stmt_afold()

static mpc_val_t* mpca_stmt_afold ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 3611 of file mpc.c.

3611  {
3612  mpca_stmt_t *stmt = malloc(sizeof(mpca_stmt_t));
3613  stmt->ident = ((char**)xs)[0];
3614  stmt->name = ((char**)xs)[1];
3615  stmt->grammar = ((mpc_parser_t**)xs)[3];
3616  (void) n;
3617  free(((char**)xs)[2]);
3618  free(((char**)xs)[4]);
3619 
3620  return stmt;
3621 }
mpc_parser_t * grammar
Definition: mpc.c:3608
char * ident
Definition: mpc.c:3606
char * name
Definition: mpc.c:3607

References free(), mpca_stmt_t::grammar, mpca_stmt_t::ident, malloc(), n, and mpca_stmt_t::name.

Referenced by mpca_lang_st().

◆ mpca_stmt_fold()

static mpc_val_t* mpca_stmt_fold ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 3623 of file mpc.c.

3623  {
3624 
3625  int i;
3626  mpca_stmt_t **stmts = malloc(sizeof(mpca_stmt_t*) * (n+1));
3627 
3628  for (i = 0; i < n; i++) {
3629  stmts[i] = xs[i];
3630  }
3631  stmts[n] = NULL;
3632 
3633  return stmts;
3634 }

References i, malloc(), n, and NULL.

Referenced by mpca_lang_st().

◆ mpca_stmt_list_apply_to()

static mpc_val_t* mpca_stmt_list_apply_to ( mpc_val_t x,
void *  s 
)
static

Definition at line 3652 of file mpc.c.

3652  {
3653 
3654  mpca_grammar_st_t *st = s;
3655  mpca_stmt_t *stmt;
3656  mpca_stmt_t **stmts = x;
3657  mpc_parser_t *left;
3658 
3659  while(*stmts) {
3660  stmt = *stmts;
3661  left = mpca_grammar_find_parser(stmt->ident, st);
3662  if (st->flags & MPCA_LANG_PREDICTIVE) { stmt->grammar = mpc_predictive(stmt->grammar); }
3663  if (stmt->name) { stmt->grammar = mpc_expect(stmt->grammar, stmt->name); }
3664  mpc_optimise(stmt->grammar);
3665  mpc_define(left, stmt->grammar);
3666  free(stmt->ident);
3667  free(stmt->name);
3668  free(stmt);
3669  stmts++;
3670  }
3671 
3672  free(x);
3673 
3674  return NULL;
3675 }
static mpc_parser_t * mpca_grammar_find_parser(char *x, mpca_grammar_st_t *st)
Definition: mpc.c:3459

References mpca_grammar_st_t::flags, free(), mpca_stmt_t::grammar, mpca_stmt_t::ident, mpc_define(), mpc_expect(), mpc_optimise(), mpc_predictive(), mpca_grammar_find_parser(), MPCA_LANG_PREDICTIVE, mpca_stmt_t::name, NULL, s, and x.

Referenced by mpca_lang_st().

◆ mpca_stmt_list_delete()

static void mpca_stmt_list_delete ( mpc_val_t x)
static

Definition at line 3636 of file mpc.c.

3636  {
3637 
3638  mpca_stmt_t **stmts = x;
3639 
3640  while(*stmts) {
3641  mpca_stmt_t *stmt = *stmts;
3642  free(stmt->ident);
3643  free(stmt->name);
3644  mpc_soft_delete(stmt->grammar);
3645  free(stmt);
3646  stmts++;
3647  }
3648  free(x);
3649 
3650 }

References free(), mpca_stmt_t::grammar, mpca_stmt_t::ident, mpc_soft_delete(), mpca_stmt_t::name, and x.

Referenced by mpca_lang_st().

◆ mpca_tag()

mpc_parser_t* mpca_tag ( mpc_parser_t a,
const char *  t 
)

Definition at line 3269 of file mpc.c.

3269  {
3270  return mpc_apply_to(a, (mpc_apply_to_t)mpc_ast_tag, (void*)t);
3271 }
mpc_ast_t * mpc_ast_tag(mpc_ast_t *a, const char *t)
Definition: mpc.c:2998

References a, mpc_apply_to(), and mpc_ast_tag().

Referenced by mpcaf_fold_regex(), mpcaf_grammar_char(), and mpcaf_grammar_string().

◆ mpca_total()

mpc_parser_t* mpca_total ( mpc_parser_t a)

Definition at line 3333 of file mpc.c.

3333 { return mpc_total(a, (mpc_dtor_t)mpc_ast_delete); }

References a, mpc_ast_delete(), and mpc_total().

◆ mpcaf_fold_regex()

static mpc_val_t* mpcaf_fold_regex ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 3434 of file mpc.c.

3434  {
3435  char *y = xs[0];
3436  char *m = xs[1];
3437  mpca_grammar_st_t *st = xs[2];
3438  mpc_parser_t *p;
3439  int mode = MPC_RE_DEFAULT;
3440 
3441  (void)n;
3442  if (strchr(m, 'm')) { mode |= MPC_RE_MULTILINE; }
3443  if (strchr(m, 's')) { mode |= MPC_RE_DOTALL; }
3444  y = mpcf_unescape_regex(y);
3446  free(y);
3447  free(m);
3448 
3449  return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "regex"));
3450 }
mpc_parser_t * mpca_tag(mpc_parser_t *a, const char *t)
Definition: mpc.c:3269
mpc_val_t * mpcf_unescape_regex(mpc_val_t *x)
Definition: mpc.c:2594
mpc_parser_t * mpca_state(mpc_parser_t *a)
Definition: mpc.c:3265
@ MPCA_LANG_WHITESPACE_SENSITIVE
Definition: mpc.h:357
@ MPC_RE_MULTILINE
Definition: mpc.h:273
@ MPC_RE_DOTALL
Definition: mpc.h:274

References mpca_grammar_st_t::flags, free(), regress::m, mpc_apply(), MPC_RE_DEFAULT, MPC_RE_DOTALL, mpc_re_mode(), MPC_RE_MULTILINE, mpc_tok(), MPCA_LANG_WHITESPACE_SENSITIVE, mpca_state(), mpca_tag(), mpcf_str_ast(), mpcf_unescape_regex(), n, and p.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcaf_grammar_and()

static mpc_val_t* mpcaf_grammar_and ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 3392 of file mpc.c.

3392  {
3393  int i;
3394  mpc_parser_t *p = mpc_pass();
3395  for (i = 0; i < n; i++) {
3396  if (xs[i] != NULL) { p = mpca_and(2, p, xs[i]); }
3397  }
3398  return p;
3399 }
mpc_parser_t * mpca_and(int n,...)
Definition: mpc.c:3308

References i, mpc_pass(), mpca_and(), n, NULL, and p.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcaf_grammar_char()

static mpc_val_t* mpcaf_grammar_char ( mpc_val_t x,
void *  s 
)
static

Definition at line 3426 of file mpc.c.

3426  {
3427  mpca_grammar_st_t *st = s;
3428  char *y = mpcf_unescape(x);
3430  free(y);
3431  return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "char"));
3432 }
mpc_val_t * mpcf_unescape(mpc_val_t *x)
Definition: mpc.c:2582

References mpca_grammar_st_t::flags, free(), mpc_apply(), mpc_char(), mpc_tok(), MPCA_LANG_WHITESPACE_SENSITIVE, mpca_state(), mpca_tag(), mpcf_str_ast(), mpcf_unescape(), p, s, and x.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcaf_grammar_id()

static mpc_val_t* mpcaf_grammar_id ( mpc_val_t x,
void *  s 
)
static

Definition at line 3508 of file mpc.c.

3508  {
3509 
3510  mpca_grammar_st_t *st = s;
3512  free(x);
3513 
3514  if (p->name) {
3515  return mpca_state(mpca_root(mpca_add_tag(p, p->name)));
3516  } else {
3517  return mpca_state(mpca_root(p));
3518  }
3519 }
mpc_parser_t * mpca_add_tag(mpc_parser_t *a, const char *t)
Definition: mpc.c:3273
mpc_parser_t * mpca_root(mpc_parser_t *a)
Definition: mpc.c:3277

References free(), mpca_add_tag(), mpca_grammar_find_parser(), mpca_root(), mpca_state(), p, s, and x.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcaf_grammar_or()

static mpc_val_t* mpcaf_grammar_or ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 3386 of file mpc.c.

3386  {
3387  (void) n;
3388  if (xs[1] == NULL) { return xs[0]; }
3389  else { return mpca_or(2, xs[0], xs[1]); }
3390 }
mpc_parser_t * mpca_or(int n,...)
Definition: mpc.c:3287

References mpca_or(), n, and NULL.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcaf_grammar_repeat()

static mpc_val_t* mpcaf_grammar_repeat ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 3401 of file mpc.c.

3401  {
3402  int num;
3403  (void) n;
3404  if (xs[1] == NULL) { return xs[0]; }
3405  switch(((char*)xs[1])[0])
3406  {
3407  case '*': { free(xs[1]); return mpca_many(xs[0]); }; break;
3408  case '+': { free(xs[1]); return mpca_many1(xs[0]); }; break;
3409  case '?': { free(xs[1]); return mpca_maybe(xs[0]); }; break;
3410  case '!': { free(xs[1]); return mpca_not(xs[0]); }; break;
3411  default:
3412  num = *((int*)xs[1]);
3413  free(xs[1]);
3414  }
3415  return mpca_count(num, xs[0]);
3416 }
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
mpc_parser_t * mpca_not(mpc_parser_t *a)
Definition: mpc.c:3281
mpc_parser_t * mpca_many(mpc_parser_t *a)
Definition: mpc.c:3283
mpc_parser_t * mpca_maybe(mpc_parser_t *a)
Definition: mpc.c:3282
mpc_parser_t * mpca_count(int n, mpc_parser_t *a)
Definition: mpc.c:3285
mpc_parser_t * mpca_many1(mpc_parser_t *a)
Definition: mpc.c:3284

References free(), mpca_count(), mpca_many(), mpca_many1(), mpca_maybe(), mpca_not(), n, NULL, and num.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcaf_grammar_string()

static mpc_val_t* mpcaf_grammar_string ( mpc_val_t x,
void *  s 
)
static

Definition at line 3418 of file mpc.c.

3418  {
3419  mpca_grammar_st_t *st = s;
3420  char *y = mpcf_unescape(x);
3422  free(y);
3423  return mpca_state(mpca_tag(mpc_apply(p, mpcf_str_ast), "string"));
3424 }

References mpca_grammar_st_t::flags, free(), mpc_apply(), mpc_string(), mpc_tok(), MPCA_LANG_WHITESPACE_SENSITIVE, mpca_state(), mpca_tag(), mpcf_str_ast(), mpcf_unescape(), p, s, and x.

Referenced by mpca_grammar_st(), and mpca_lang_st().

◆ mpcf_all_free()

mpc_val_t* mpcf_all_free ( int  n,
mpc_val_t **  xs 
)

Definition at line 2640 of file mpc.c.

2640  {
2641  int i;
2642  for (i = 0; i < n; i++) {
2643  free(xs[i]);
2644  }
2645  return NULL;
2646 }

References free(), i, n, and NULL.

◆ mpcf_ctor_null()

mpc_val_t* mpcf_ctor_null ( void  )

Definition at line 2430 of file mpc.c.

2430 { return NULL; }

References NULL.

Referenced by mpc_maybe(), and mpc_not().

◆ mpcf_ctor_str()

mpc_val_t* mpcf_ctor_str ( void  )

Definition at line 2431 of file mpc.c.

2431 { return calloc(1, 1); }

References calloc().

Referenced by mpc_optimise_unretained(), mpc_re_escape_char(), mpc_real(), mpcf_re_and(), mpcf_re_escape(), and mpcf_re_repeat().

◆ mpcf_dtor_null()

void mpcf_dtor_null ( mpc_val_t x)

Definition at line 2428 of file mpc.c.

2428 { (void) x; return; }

References x.

Referenced by mpc_startwith(), mpc_strip(), mpc_stripl(), mpc_stripr(), mpc_tok(), and mpc_whole().

◆ mpcf_escape()

mpc_val_t* mpcf_escape ( mpc_val_t x)

Definition at line 2576 of file mpc.c.

2576  {
2578  free(x);
2579  return y;
2580 }

References free(), mpc_escape_input_c, mpc_escape_output_c, mpcf_escape_new(), and x.

◆ mpcf_escape_char_raw()

mpc_val_t* mpcf_escape_char_raw ( mpc_val_t x)

Definition at line 2612 of file mpc.c.

2612  {
2614  free(x);
2615  return y;
2616 }
static const char * mpc_escape_output_raw_cchar[]
Definition: mpc.c:2498
static const char mpc_escape_input_raw_cchar[]
Definition: mpc.c:2497

References free(), mpc_escape_input_raw_cchar, mpc_escape_output_raw_cchar, mpcf_escape_new(), and x.

◆ mpcf_escape_new()

static mpc_val_t* mpcf_escape_new ( mpc_val_t x,
const char *  input,
const char **  output 
)
static

Definition at line 2500 of file mpc.c.

2500  {
2501 
2502  int i;
2503  int found;
2504  char buff[2];
2505  char *s = x;
2506  char *y = calloc(1, 1);
2507 
2508  while (*s) {
2509 
2510  i = 0;
2511  found = 0;
2512 
2513  while (output[i]) {
2514  if (*s == input[i]) {
2515  y = realloc(y, strlen(y) + strlen(output[i]) + 1);
2516  strcat(y, output[i]);
2517  found = 1;
2518  break;
2519  }
2520  i++;
2521  }
2522 
2523  if (!found) {
2524  y = realloc(y, strlen(y) + 2);
2525  buff[0] = *s; buff[1] = '\0';
2526  strcat(y, buff);
2527  }
2528 
2529  s++;
2530  }
2531 
2532 
2533  return y;
2534 }
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)

References calloc(), found, i, input(), output, realloc(), s, and x.

Referenced by mpc_print_unretained(), mpcf_escape(), mpcf_escape_char_raw(), mpcf_escape_regex(), and mpcf_escape_string_raw().

◆ mpcf_escape_regex()

mpc_val_t* mpcf_escape_regex ( mpc_val_t x)

Definition at line 2588 of file mpc.c.

2588  {
2590  free(x);
2591  return y;
2592 }
static const char mpc_escape_input_raw_re[]
Definition: mpc.c:2491
static const char * mpc_escape_output_raw_re[]
Definition: mpc.c:2492

References free(), mpc_escape_input_raw_re, mpc_escape_output_raw_re, mpcf_escape_new(), and x.

◆ mpcf_escape_string_raw()

mpc_val_t* mpcf_escape_string_raw ( mpc_val_t x)

Definition at line 2600 of file mpc.c.

2600  {
2602  free(x);
2603  return y;
2604 }
static const char * mpc_escape_output_raw_cstr[]
Definition: mpc.c:2495
static const char mpc_escape_input_raw_cstr[]
Definition: mpc.c:2494

References free(), mpc_escape_input_raw_cstr, mpc_escape_output_raw_cstr, mpcf_escape_new(), and x.

◆ mpcf_float()

mpc_val_t* mpcf_float ( mpc_val_t x)

Definition at line 2455 of file mpc.c.

2455  {
2456  float *y = malloc(sizeof(float));
2457  *y = strtod(x, NULL);
2458  free(x);
2459  return y;
2460 }

References free(), malloc(), NULL, and x.

Referenced by mpc_float().

◆ mpcf_fold_ast()

mpc_val_t* mpcf_fold_ast ( int  n,
mpc_val_t **  xs 
)

Definition at line 3212 of file mpc.c.

3212  {
3213 
3214  int i, j;
3215  mpc_ast_t** as = (mpc_ast_t**)xs;
3216  mpc_ast_t *r;
3217 
3218  if (n == 0) { return NULL; }
3219  if (n == 1) { return xs[0]; }
3220  if (n == 2 && xs[1] == NULL) { return xs[0]; }
3221  if (n == 2 && xs[0] == NULL) { return xs[1]; }
3222 
3223  r = mpc_ast_new(">", "");
3224 
3225  for (i = 0; i < n; i++) {
3226 
3227  if (as[i] == NULL) { continue; }
3228 
3229  if (as[i] && as[i]->children_num == 0) {
3230  mpc_ast_add_child(r, as[i]);
3231  } else if (as[i] && as[i]->children_num == 1) {
3232  mpc_ast_add_child(r, mpc_ast_add_root_tag(as[i]->children[0], as[i]->tag));
3234  } else if (as[i] && as[i]->children_num >= 2) {
3235  for (j = 0; j < as[i]->children_num; j++) {
3236  mpc_ast_add_child(r, as[i]->children[j]);
3237  }
3239  }
3240 
3241  }
3242 
3243  if (r->children_num) {
3244  r->state = r->children[0]->state;
3245  }
3246 
3247  return r;
3248 }
static void mpc_ast_delete_no_children(mpc_ast_t *a)
Definition: mpc.c:2903
mpc_ast_t * mpc_ast_add_root_tag(mpc_ast_t *a, const char *t)
Definition: mpc.c:2990

References mpc_ast_t::children_num, i, mpc_ast_add_child(), mpc_ast_add_root_tag(), mpc_ast_delete_no_children(), mpc_ast_new(), n, NULL, r, and test-lz4-versions::tag.

Referenced by mpc_optimise_unretained(), mpca_and(), mpca_count(), mpca_many(), and mpca_many1().

◆ mpcf_free()

mpc_val_t* mpcf_free ( mpc_val_t x)

Definition at line 2432 of file mpc.c.

2432 { free(x); return NULL; }

References free(), NULL, and x.

Referenced by mpc_blank(), and mpc_parse_apply().

◆ mpcf_fst()

mpc_val_t* mpcf_fst ( int  n,
mpc_val_t **  xs 
)

Definition at line 2625 of file mpc.c.

2625 { (void) n; return xs[0]; }

References n.

Referenced by mpc_endwith(), mpc_parse_fold(), mpc_stripr(), mpc_tok(), and mpcf_re_escape().

◆ mpcf_fst_free()

mpc_val_t* mpcf_fst_free ( int  n,
mpc_val_t **  xs 
)

Definition at line 2637 of file mpc.c.

2637 { return mpcf_nth_free(n, xs, 0); }
static mpc_val_t * mpcf_nth_free(int n, mpc_val_t **xs, int x)
Definition: mpc.c:2629

References mpcf_nth_free(), and n.

Referenced by mpc_parse_fold().

◆ mpcf_hex()

mpc_val_t* mpcf_hex ( mpc_val_t x)

Definition at line 2441 of file mpc.c.

2441  {
2442  int *y = malloc(sizeof(int));
2443  *y = strtol(x, NULL, 16);
2444  free(x);
2445  return y;
2446 }

References free(), malloc(), NULL, and x.

Referenced by mpc_hex().

◆ mpcf_input_free()

static mpc_val_t* mpcf_input_free ( mpc_input_t i,
mpc_val_t x 
)
static

Definition at line 1009 of file mpc.c.

1009  {
1010  mpc_free(i, x);
1011  return NULL;
1012 }

References i, mpc_free(), NULL, and x.

Referenced by mpc_parse_apply().

◆ mpcf_input_fst_free()

static mpc_val_t* mpcf_input_fst_free ( mpc_input_t i,
int  n,
mpc_val_t **  xs 
)
static

Definition at line 971 of file mpc.c.

971 { return mpcf_input_nth_free(i, n, xs, 0); }
static mpc_val_t * mpcf_input_nth_free(mpc_input_t *i, int n, mpc_val_t **xs, int x)
Definition: mpc.c:965

References i, mpcf_input_nth_free(), and n.

Referenced by mpc_parse_fold().

◆ mpcf_input_nth_free()

static mpc_val_t* mpcf_input_nth_free ( mpc_input_t i,
int  n,
mpc_val_t **  xs,
int  x 
)
static

Definition at line 965 of file mpc.c.

965  {
966  int j;
967  for (j = 0; j < n; j++) { if (j != x) { mpc_free(i, xs[j]); } }
968  return xs[x];
969 }

References i, mpc_free(), n, and x.

Referenced by mpcf_input_fst_free(), mpcf_input_snd_free(), and mpcf_input_trd_free().

◆ mpcf_input_snd_free()

static mpc_val_t* mpcf_input_snd_free ( mpc_input_t i,
int  n,
mpc_val_t **  xs 
)
static

Definition at line 972 of file mpc.c.

972 { return mpcf_input_nth_free(i, n, xs, 1); }

References i, mpcf_input_nth_free(), and n.

Referenced by mpc_parse_fold().

◆ mpcf_input_state_ast()

static mpc_val_t* mpcf_input_state_ast ( mpc_input_t i,
int  n,
mpc_val_t **  xs 
)
static

Definition at line 985 of file mpc.c.

985  {
986  mpc_state_t *s = ((mpc_state_t**)xs)[0];
987  mpc_ast_t *a = ((mpc_ast_t**)xs)[1];
988  a = mpc_ast_state(a, *s);
989  mpc_free(i, s);
990  (void) n;
991  return a;
992 }
mpc_ast_t * mpc_ast_state(mpc_ast_t *a, mpc_state_t s)
Definition: mpc.c:3004

References a, i, mpc_ast_state(), mpc_free(), n, and s.

Referenced by mpc_parse_fold().

◆ mpcf_input_str_ast()

static mpc_val_t* mpcf_input_str_ast ( mpc_input_t i,
mpc_val_t c 
)
static

Definition at line 1014 of file mpc.c.

1014  {
1015  mpc_ast_t *a = mpc_ast_new("", c);
1016  mpc_free(i, c);
1017  return a;
1018 }

References a, c, i, mpc_ast_new(), and mpc_free().

Referenced by mpc_parse_apply().

◆ mpcf_input_strfold()

static mpc_val_t* mpcf_input_strfold ( mpc_input_t i,
int  n,
mpc_val_t **  xs 
)
static

Definition at line 975 of file mpc.c.

975  {
976  int j;
977  size_t l = 0;
978  if (n == 0) { return mpc_calloc(i, 1, 1); }
979  for (j = 0; j < n; j++) { l += strlen(xs[j]); }
980  xs[0] = mpc_realloc(i, xs[0], l + 1);
981  for (j = 1; j < n; j++) { strcat(xs[0], xs[j]); mpc_free(i, xs[j]); }
982  return xs[0];
983 }

References i, mpc_calloc(), mpc_free(), mpc_realloc(), and n.

Referenced by mpc_parse_fold().

◆ mpcf_input_trd_free()

static mpc_val_t* mpcf_input_trd_free ( mpc_input_t i,
int  n,
mpc_val_t **  xs 
)
static

Definition at line 973 of file mpc.c.

973 { return mpcf_input_nth_free(i, n, xs, 2); }

References i, mpcf_input_nth_free(), and n.

Referenced by mpc_parse_fold().

◆ mpcf_int()

mpc_val_t* mpcf_int ( mpc_val_t x)

Definition at line 2434 of file mpc.c.

2434  {
2435  int *y = malloc(sizeof(int));
2436  *y = strtol(x, NULL, 10);
2437  free(x);
2438  return y;
2439 }

References free(), malloc(), NULL, and x.

Referenced by mpc_int().

◆ mpcf_maths()

mpc_val_t* mpcf_maths ( int  n,
mpc_val_t **  xs 
)

Definition at line 2665 of file mpc.c.

2665  {
2666  int **vs = (int**)xs;
2667  (void) n;
2668 
2669  switch(((char*)xs[1])[0])
2670  {
2671  case '*': { *vs[0] *= *vs[2]; }; break;
2672  case '/': { *vs[0] /= *vs[2]; }; break;
2673  case '%': { *vs[0] %= *vs[2]; }; break;
2674  case '+': { *vs[0] += *vs[2]; }; break;
2675  case '-': { *vs[0] -= *vs[2]; }; break;
2676  default: break;
2677  }
2678 
2679  free(xs[1]); free(xs[2]);
2680 
2681  return xs[0];
2682 }

References free(), and n.

◆ mpcf_nth_free()

static mpc_val_t* mpcf_nth_free ( int  n,
mpc_val_t **  xs,
int  x 
)
static

Definition at line 2629 of file mpc.c.

2629  {
2630  int i;
2631  for (i = 0; i < n; i++) {
2632  if (i != x) { free(xs[i]); }
2633  }
2634  return xs[x];
2635 }

References free(), i, n, and x.

Referenced by mpcf_fst_free(), mpcf_snd_free(), and mpcf_trd_free().

◆ mpcf_null()

mpc_val_t* mpcf_null ( int  n,
mpc_val_t **  xs 
)

Definition at line 2624 of file mpc.c.

2624 { (void) n; (void) xs; return NULL; }

References n, and NULL.

Referenced by mpc_parse_fold().

◆ mpcf_oct()

mpc_val_t* mpcf_oct ( mpc_val_t x)

Definition at line 2448 of file mpc.c.

2448  {
2449  int *y = malloc(sizeof(int));
2450  *y = strtol(x, NULL, 8);
2451  free(x);
2452  return y;
2453 }

References free(), malloc(), NULL, and x.

Referenced by mpc_oct().

◆ mpcf_re_and()

static mpc_val_t* mpcf_re_and ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 2171 of file mpc.c.

2171  {
2172  int i;
2174  for (i = 0; i < n; i++) {
2175  p = mpc_and(2, mpcf_strfold, p, xs[i], free);
2176  }
2177  return p;
2178 }

References free(), i, mpc_and(), mpc_lift(), mpcf_ctor_str(), mpcf_strfold(), n, and p.

Referenced by mpc_re_mode().

◆ mpcf_re_escape()

static mpc_val_t* mpcf_re_escape ( mpc_val_t x,
void *  data 
)
static

Definition at line 2219 of file mpc.c.

2219  {
2220 
2221  int mode = *((int*)data);
2222  char *s = x;
2223  mpc_parser_t *p;
2224 
2225  /* Any Character */
2226  if (s[0] == '.') {
2227  free(s);
2228  if (mode & MPC_RE_DOTALL) {
2229  return mpc_any();
2230  } else {
2231  return mpc_expect(mpc_noneof("\n"), "any character except a newline");
2232  }
2233  }
2234 
2235  /* Start of Input */
2236  if (s[0] == '^') {
2237  free(s);
2238  if (mode & MPC_RE_MULTILINE) {
2240  } else {
2242  }
2243  }
2244 
2245  /* End of Input */
2246  if (s[0] == '$') {
2247  free(s);
2248  if (mode & MPC_RE_MULTILINE) {
2249  return mpc_or(2,
2250  mpc_newline(),
2252  } else {
2253  return mpc_or(2,
2256  }
2257  }
2258 
2259  /* Regex Escape */
2260  if (s[0] == '\\') {
2261  p = mpc_re_escape_char(s[1]);
2262  p = (p == NULL) ? mpc_char(s[1]) : p;
2263  free(s);
2264  return p;
2265  }
2266 
2267  /* Regex Standard */
2268  p = mpc_char(s[0]);
2269  free(s);
2270  return p;
2271 }
static mpc_parser_t * mpc_re_escape_char(char c)
Definition: mpc.c:2197
mpc_parser_t * mpc_boundary_newline(void)
Definition: mpc.c:2006
mpc_parser_t * mpc_newline(void)
Definition: mpc.c:2012

References free(), mpc_and(), mpc_any(), mpc_boundary_newline(), mpc_char(), mpc_eoi(), mpc_expect(), mpc_lift(), mpc_newline(), mpc_noneof(), mpc_or(), MPC_RE_DOTALL, mpc_re_escape_char(), MPC_RE_MULTILINE, mpc_soi(), mpcf_ctor_str(), mpcf_fst(), mpcf_snd(), NULL, p, s, and x.

Referenced by mpc_re_mode().

◆ mpcf_re_or()

static mpc_val_t* mpcf_re_or ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 2165 of file mpc.c.

2165  {
2166  (void) n;
2167  if (xs[1] == NULL) { return xs[0]; }
2168  else { return mpc_or(2, xs[0], xs[1]); }
2169 }

References mpc_or(), n, and NULL.

Referenced by mpc_re_mode().

◆ mpcf_re_range()

static mpc_val_t* mpcf_re_range ( mpc_val_t x)
static

Definition at line 2290 of file mpc.c.

2290  {
2291 
2292  mpc_parser_t *out;
2293  size_t i, j;
2294  size_t start, end;
2295  const char *tmp = NULL;
2296  const char *s = x;
2297  int comp = s[0] == '^' ? 1 : 0;
2298  char *range = calloc(1,1);
2299 
2300  if (s[0] == '\0') { free(range); free(x); return mpc_fail("Invalid Regex Range Expression"); }
2301  if (s[0] == '^' &&
2302  s[1] == '\0') { free(range); free(x); return mpc_fail("Invalid Regex Range Expression"); }
2303 
2304  for (i = comp; i < strlen(s); i++){
2305 
2306  /* Regex Range Escape */
2307  if (s[i] == '\\') {
2309  if (tmp != NULL) {
2310  range = realloc(range, strlen(range) + strlen(tmp) + 1);
2311  strcat(range, tmp);
2312  } else {
2313  range = realloc(range, strlen(range) + 1 + 1);
2314  range[strlen(range) + 1] = '\0';
2315  range[strlen(range) + 0] = s[i+1];
2316  }
2317  i++;
2318  }
2319 
2320  /* Regex Range...Range */
2321  else if (s[i] == '-') {
2322  if (s[i+1] == '\0' || i == 0) {
2323  range = realloc(range, strlen(range) + strlen("-") + 1);
2324  strcat(range, "-");
2325  } else {
2326  start = s[i-1]+1;
2327  end = s[i+1]-1;
2328  for (j = start; j <= end; j++) {
2329  range = realloc(range, strlen(range) + 1 + 1 + 1);
2330  range[strlen(range) + 1] = '\0';
2331  range[strlen(range) + 0] = (char)j;
2332  }
2333  }
2334  }
2335 
2336  /* Regex Range Normal */
2337  else {
2338  range = realloc(range, strlen(range) + 1 + 1);
2339  range[strlen(range) + 1] = '\0';
2340  range[strlen(range) + 0] = s[i];
2341  }
2342 
2343  }
2344 
2345  out = comp == 1 ? mpc_noneof(range) : mpc_oneof(range);
2346 
2347  free(x);
2348  free(range);
2349 
2350  return out;
2351 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
Definition: sflib.h:133
mpc_parser_t * mpc_fail(const char *m)
Definition: mpc.c:1616
static const char * mpc_re_range_escape_char(char c)
Definition: mpc.c:2273

References calloc(), test_evm::end, free(), i, mpc_fail(), mpc_noneof(), mpc_oneof(), mpc_re_range_escape_char(), NULL, out, capstone::range, realloc(), s, start, autogen_x86imm::tmp, and x.

Referenced by mpc_re_mode().

◆ mpcf_re_repeat()

static mpc_val_t* mpcf_re_repeat ( int  n,
mpc_val_t **  xs 
)
static

Definition at line 2180 of file mpc.c.

2180  {
2181  int num;
2182  (void) n;
2183  if (xs[1] == NULL) { return xs[0]; }
2184  switch(((char*)xs[1])[0])
2185  {
2186  case '*': { free(xs[1]); return mpc_many(mpcf_strfold, xs[0]); }; break;
2187  case '+': { free(xs[1]); return mpc_many1(mpcf_strfold, xs[0]); }; break;
2188  case '?': { free(xs[1]); return mpc_maybe_lift(xs[0], mpcf_ctor_str); }; break;
2189  default:
2190  num = *(int*)xs[1];
2191  free(xs[1]);
2192  }
2193 
2194  return mpc_count(num, mpcf_strfold, xs[0], free);
2195 }

References free(), mpc_count(), mpc_many(), mpc_many1(), mpc_maybe_lift(), mpcf_ctor_str(), mpcf_strfold(), n, NULL, and num.

Referenced by mpc_re_mode().

◆ mpcf_snd()

mpc_val_t* mpcf_snd ( int  n,
mpc_val_t **  xs 
)

Definition at line 2626 of file mpc.c.

2626 { (void) n; return xs[1]; }

References n.

Referenced by mpc_parse_fold(), mpc_re_escape_char(), mpc_startwith(), mpc_strip(), mpc_stripl(), mpc_whole(), and mpcf_re_escape().

◆ mpcf_snd_free()

mpc_val_t* mpcf_snd_free ( int  n,
mpc_val_t **  xs 
)

Definition at line 2638 of file mpc.c.

2638 { return mpcf_nth_free(n, xs, 1); }

References mpcf_nth_free(), and n.

Referenced by mpc_between(), mpc_parse_fold(), mpc_re_mode(), mpc_tok_between(), mpca_grammar_st(), and mpca_lang_st().

◆ mpcf_state_ast()

mpc_val_t* mpcf_state_ast ( int  n,
mpc_val_t **  xs 
)

Definition at line 3256 of file mpc.c.

3256  {
3257  mpc_state_t *s = ((mpc_state_t**)xs)[0];
3258  mpc_ast_t *a = ((mpc_ast_t**)xs)[1];
3259  (void)n;
3260  a = mpc_ast_state(a, *s);
3261  free(s);
3262  return a;
3263 }

References a, free(), mpc_ast_state(), n, and s.

Referenced by mpc_parse_fold(), and mpca_state().

◆ mpcf_str_ast()

mpc_val_t* mpcf_str_ast ( mpc_val_t c)

Definition at line 3250 of file mpc.c.

3250  {
3251  mpc_ast_t *a = mpc_ast_new("", c);
3252  free(c);
3253  return a;
3254 }

References a, c, free(), and mpc_ast_new().

Referenced by mpc_parse_apply(), mpcaf_fold_regex(), mpcaf_grammar_char(), and mpcaf_grammar_string().

◆ mpcf_strfold()

mpc_val_t* mpcf_strfold ( int  n,
mpc_val_t **  xs 
)

Definition at line 2648 of file mpc.c.

2648  {
2649  int i;
2650  size_t l = 0;
2651 
2652  if (n == 0) { return calloc(1, 1); }
2653 
2654  for (i = 0; i < n; i++) { l += strlen(xs[i]); }
2655 
2656  xs[0] = realloc(xs[0], l + 1);
2657 
2658  for (i = 1; i < n; i++) {
2659  strcat(xs[0], xs[i]); free(xs[i]);
2660  }
2661 
2662  return xs[0];
2663 }

References calloc(), free(), i, n, and realloc().

Referenced by mpc_digits(), mpc_escape(), mpc_hexdigits(), mpc_ident(), mpc_octdigits(), mpc_optimise_unretained(), mpc_parse_fold(), mpc_re_mode(), mpc_real(), mpc_regex_lit(), mpc_string_lit(), mpc_whitespaces(), mpca_grammar_st(), mpca_lang_st(), mpcf_re_and(), and mpcf_re_repeat().

◆ mpcf_strtrim()

mpc_val_t* mpcf_strtrim ( mpc_val_t x)

Definition at line 2479 of file mpc.c.

2479  {
2480  return mpcf_strtriml(mpcf_strtrimr(x));
2481 }
mpc_val_t * mpcf_strtrimr(mpc_val_t *x)
Definition: mpc.c:2470
mpc_val_t * mpcf_strtriml(mpc_val_t *x)
Definition: mpc.c:2462

References mpcf_strtriml(), mpcf_strtrimr(), and x.

◆ mpcf_strtriml()

mpc_val_t* mpcf_strtriml ( mpc_val_t x)

Definition at line 2462 of file mpc.c.

2462  {
2463  char *s = x;
2464  while (isspace((unsigned char)*s)) {
2465  memmove(s, s+1, strlen(s));
2466  }
2467  return s;
2468 }
#define isspace(c)
Definition: safe-ctype.h:141

References isspace, s, and x.

Referenced by mpcf_strtrim().

◆ mpcf_strtrimr()

mpc_val_t* mpcf_strtrimr ( mpc_val_t x)

Definition at line 2470 of file mpc.c.

2470  {
2471  char *s = x;
2472  size_t l = strlen(s);
2473  while (l > 0 && isspace((unsigned char)s[l-1])) {
2474  s[l-1] = '\0'; l--;
2475  }
2476  return s;
2477 }

References isspace, s, and x.

Referenced by mpcf_strtrim().

◆ mpcf_trd()

mpc_val_t* mpcf_trd ( int  n,
mpc_val_t **  xs 
)

Definition at line 2627 of file mpc.c.

2627 { (void) n; return xs[2]; }

References n.

Referenced by mpc_parse_fold().

◆ mpcf_trd_free()

mpc_val_t* mpcf_trd_free ( int  n,
mpc_val_t **  xs 
)

Definition at line 2639 of file mpc.c.

2639 { return mpcf_nth_free(n, xs, 2); }

References mpcf_nth_free(), and n.

Referenced by mpc_parse_fold().

◆ mpcf_unescape()

mpc_val_t* mpcf_unescape ( mpc_val_t x)

Definition at line 2582 of file mpc.c.

2582  {
2584  free(x);
2585  return y;
2586 }
static mpc_val_t * mpcf_unescape_new(mpc_val_t *x, const char *input, const char **output)
Definition: mpc.c:2536

References free(), mpc_escape_input_c, mpc_escape_output_c, mpcf_unescape_new(), and x.

Referenced by mpcaf_grammar_char(), and mpcaf_grammar_string().

◆ mpcf_unescape_char_raw()

mpc_val_t* mpcf_unescape_char_raw ( mpc_val_t x)

Definition at line 2618 of file mpc.c.

2618  {
2620  free(x);
2621  return y;
2622 }

References free(), mpc_escape_input_raw_cchar, mpc_escape_output_raw_cchar, mpcf_unescape_new(), and x.

◆ mpcf_unescape_new()

static mpc_val_t* mpcf_unescape_new ( mpc_val_t x,
const char *  input,
const char **  output 
)
static

Definition at line 2536 of file mpc.c.

2536  {
2537 
2538  int i;
2539  int found = 0;
2540  char buff[2];
2541  char *s = x;
2542  char *y = calloc(1, 1);
2543 
2544  while (*s) {
2545 
2546  i = 0;
2547  found = 0;
2548 
2549  while (output[i]) {
2550  if ((*(s+0)) == output[i][0] &&
2551  (*(s+1)) == output[i][1]) {
2552  y = realloc(y, strlen(y) + 1 + 1);
2553  buff[0] = input[i]; buff[1] = '\0';
2554  strcat(y, buff);
2555  found = 1;
2556  s++;
2557  break;
2558  }
2559  i++;
2560  }
2561 
2562  if (!found) {
2563  y = realloc(y, strlen(y) + 1 + 1);
2564  buff[0] = *s; buff[1] = '\0';
2565  strcat(y, buff);
2566  }
2567 
2568  if (*s == '\0') { break; }
2569  else { s++; }
2570  }
2571 
2572  return y;
2573 
2574 }

References calloc(), found, i, input(), output, realloc(), s, and x.

Referenced by mpcf_unescape(), mpcf_unescape_char_raw(), mpcf_unescape_regex(), and mpcf_unescape_string_raw().

◆ mpcf_unescape_regex()

mpc_val_t* mpcf_unescape_regex ( mpc_val_t x)

Definition at line 2594 of file mpc.c.

2594  {
2596  free(x);
2597  return y;
2598 }

References free(), mpc_escape_input_raw_re, mpc_escape_output_raw_re, mpcf_unescape_new(), and x.

Referenced by mpcaf_fold_regex().

◆ mpcf_unescape_string_raw()

mpc_val_t* mpcf_unescape_string_raw ( mpc_val_t x)

Definition at line 2606 of file mpc.c.

2606  {
2608  free(x);
2609  return y;
2610 }

References free(), mpc_escape_input_raw_cstr, mpc_escape_output_raw_cstr, mpcf_unescape_new(), and x.

Variable Documentation

◆ char_unescape_buffer

char char_unescape_buffer[4]
static

Definition at line 604 of file mpc.c.

Referenced by mpc_err_char_unescape().

◆ mpc_escape_input_c

const char mpc_escape_input_c[]
static
Initial value:
= {
'\a', '\b', '\f', '\n', '\r',
'\t', '\v', '\\', '\'', '\"', '\0'}

Definition at line 2483 of file mpc.c.

Referenced by mpc_print_unretained(), mpcf_escape(), and mpcf_unescape().

◆ mpc_escape_input_raw_cchar

const char mpc_escape_input_raw_cchar[] = { '\'' }
static

Definition at line 2497 of file mpc.c.

Referenced by mpcf_escape_char_raw(), and mpcf_unescape_char_raw().

◆ mpc_escape_input_raw_cstr

const char mpc_escape_input_raw_cstr[] = { '"' }
static

Definition at line 2494 of file mpc.c.

Referenced by mpcf_escape_string_raw(), and mpcf_unescape_string_raw().

◆ mpc_escape_input_raw_re

const char mpc_escape_input_raw_re[] = { '/' }
static

Definition at line 2491 of file mpc.c.

Referenced by mpcf_escape_regex(), and mpcf_unescape_regex().

◆ mpc_escape_output_c

const char* mpc_escape_output_c[]
static
Initial value:
= {
"\\a", "\\b", "\\f", "\\n", "\\r", "\\t",
"\\v", "\\\\", "\\'", "\\\"", "\\0", NULL}

Definition at line 2487 of file mpc.c.

Referenced by mpc_print_unretained(), mpcf_escape(), and mpcf_unescape().

◆ mpc_escape_output_raw_cchar

const char* mpc_escape_output_raw_cchar[] = { "\\'", NULL }
static

Definition at line 2498 of file mpc.c.

Referenced by mpcf_escape_char_raw(), and mpcf_unescape_char_raw().

◆ mpc_escape_output_raw_cstr

const char* mpc_escape_output_raw_cstr[] = { "\\\"", NULL }
static

Definition at line 2495 of file mpc.c.

Referenced by mpcf_escape_string_raw(), and mpcf_unescape_string_raw().

◆ mpc_escape_output_raw_re

const char* mpc_escape_output_raw_re[] = { "\\/", NULL }
static

Definition at line 2492 of file mpc.c.

Referenced by mpcf_escape_regex(), and mpcf_unescape_regex().