Rizin
unix-like reverse engineering framework and cli tools
mpc.h File Reference
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>

Go to the source code of this file.

Classes

struct  mpc_state_t
 
struct  mpc_err_t
 
union  mpc_result_t
 
struct  mpc_ast_t
 
struct  mpc_ast_trav_t
 

Typedefs

typedef void mpc_val_t
 
typedef struct mpc_parser_t mpc_parser_t
 
typedef void(* mpc_dtor_t) (mpc_val_t *)
 
typedef mpc_val_t *(* mpc_ctor_t) (void)
 
typedef mpc_val_t *(* mpc_apply_t) (mpc_val_t *)
 
typedef mpc_val_t *(* mpc_apply_to_t) (mpc_val_t *, void *)
 
typedef mpc_val_t *(* mpc_fold_t) (int, mpc_val_t **)
 
typedef int(* mpc_check_t) (mpc_val_t **)
 
typedef int(* mpc_check_with_t) (mpc_val_t **, void *)
 
typedef struct mpc_ast_t mpc_ast_t
 
typedef struct mpc_ast_trav_t mpc_ast_trav_t
 

Enumerations

enum  {
  MPC_RE_DEFAULT = 0 , MPC_RE_M = 1 , MPC_RE_S = 2 , MPC_RE_MULTILINE = 1 ,
  MPC_RE_DOTALL = 2
}
 
enum  mpc_ast_trav_order_t { mpc_ast_trav_order_pre , mpc_ast_trav_order_post }
 
enum  { MPCA_LANG_DEFAULT = 0 , MPCA_LANG_PREDICTIVE = 1 , MPCA_LANG_WHITESPACE_SENSITIVE = 2 }
 

Functions

void mpc_err_delete (mpc_err_t *e)
 
char * mpc_err_string (mpc_err_t *e)
 
void mpc_err_print (mpc_err_t *e)
 
void mpc_err_print_to (mpc_err_t *e, FILE *f)
 
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)
 
mpc_parser_tmpc_new (const char *name)
 
mpc_parser_tmpc_copy (mpc_parser_t *a)
 
mpc_parser_tmpc_define (mpc_parser_t *p, mpc_parser_t *a)
 
mpc_parser_tmpc_undefine (mpc_parser_t *p)
 
void mpc_delete (mpc_parser_t *p)
 
void mpc_cleanup (int n,...)
 
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_pass (void)
 
mpc_parser_tmpc_fail (const char *m)
 
mpc_parser_tmpc_failf (const char *fmt,...)
 
mpc_parser_tmpc_lift (mpc_ctor_t f)
 
mpc_parser_tmpc_lift_val (mpc_val_t *x)
 
mpc_parser_tmpc_anchor (int(*f)(char, char))
 
mpc_parser_tmpc_state (void)
 
mpc_parser_tmpc_expect (mpc_parser_t *a, const char *e)
 
mpc_parser_tmpc_expectf (mpc_parser_t *a, const char *fmt,...)
 
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_not (mpc_parser_t *a, mpc_dtor_t da)
 
mpc_parser_tmpc_not_lift (mpc_parser_t *a, mpc_dtor_t da, mpc_ctor_t lf)
 
mpc_parser_tmpc_maybe (mpc_parser_t *a)
 
mpc_parser_tmpc_maybe_lift (mpc_parser_t *a, mpc_ctor_t lf)
 
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_predictive (mpc_parser_t *a)
 
mpc_parser_tmpc_eoi (void)
 
mpc_parser_tmpc_soi (void)
 
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)
 
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)
 
mpc_val_tmpcf_escape (mpc_val_t *x)
 
mpc_val_tmpcf_escape_regex (mpc_val_t *x)
 
mpc_val_tmpcf_escape_string_raw (mpc_val_t *x)
 
mpc_val_tmpcf_escape_char_raw (mpc_val_t *x)
 
mpc_val_tmpcf_unescape (mpc_val_t *x)
 
mpc_val_tmpcf_unescape_regex (mpc_val_t *x)
 
mpc_val_tmpcf_unescape_string_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)
 
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_freefold (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)
 
mpc_parser_tmpc_re (const char *re)
 
mpc_parser_tmpc_re_mode (const char *re, int mode)
 
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)
 
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)
 
void mpc_ast_delete (mpc_ast_t *a)
 
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)
 
int mpc_ast_eq (mpc_ast_t *a, mpc_ast_t *b)
 
mpc_val_tmpcf_fold_ast (int n, mpc_val_t **as)
 
mpc_val_tmpcf_str_ast (mpc_val_t *c)
 
mpc_val_tmpcf_state_ast (int n, mpc_val_t **xs)
 
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_state (mpc_parser_t *a)
 
mpc_parser_tmpca_total (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_grammar (int flags, const char *grammar,...)
 
mpc_err_tmpca_lang (int flags, const char *language,...)
 
mpc_err_tmpca_lang_file (int flags, FILE *f,...)
 
mpc_err_tmpca_lang_pipe (int flags, FILE *f,...)
 
mpc_err_tmpca_lang_contents (int flags, const char *filename,...)
 
void mpc_print (mpc_parser_t *p)
 
void mpc_optimise (mpc_parser_t *p)
 
void mpc_stats (mpc_parser_t *p)
 
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 *))
 
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 *))
 

Typedef Documentation

◆ mpc_apply_t

typedef mpc_val_t*(* mpc_apply_t) (mpc_val_t *)

Definition at line 81 of file mpc.h.

◆ mpc_apply_to_t

typedef mpc_val_t*(* mpc_apply_to_t) (mpc_val_t *, void *)

Definition at line 82 of file mpc.h.

◆ mpc_ast_t

typedef struct mpc_ast_t mpc_ast_t

◆ mpc_ast_trav_t

◆ mpc_check_t

typedef int(* mpc_check_t) (mpc_val_t **)

Definition at line 85 of file mpc.h.

◆ mpc_check_with_t

typedef int(* mpc_check_with_t) (mpc_val_t **, void *)

Definition at line 86 of file mpc.h.

◆ mpc_ctor_t

typedef mpc_val_t*(* mpc_ctor_t) (void)

Definition at line 79 of file mpc.h.

◆ mpc_dtor_t

typedef void(* mpc_dtor_t) (mpc_val_t *)

Definition at line 78 of file mpc.h.

◆ mpc_fold_t

typedef mpc_val_t*(* mpc_fold_t) (int, mpc_val_t **)

Definition at line 83 of file mpc.h.

◆ mpc_parser_t

typedef struct mpc_parser_t mpc_parser_t

Definition at line 58 of file mpc.h.

◆ mpc_val_t

typedef void mpc_val_t

Definition at line 58 of file mpc.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MPC_RE_DEFAULT 
MPC_RE_M 
MPC_RE_S 
MPC_RE_MULTILINE 
MPC_RE_DOTALL 

Definition at line 269 of file mpc.h.

269  {
270  MPC_RE_DEFAULT = 0,
271  MPC_RE_M = 1,
272  MPC_RE_S = 2,
273  MPC_RE_MULTILINE = 1,
274  MPC_RE_DOTALL = 2
275 };
@ MPC_RE_M
Definition: mpc.h:271
@ MPC_RE_S
Definition: mpc.h:272
@ MPC_RE_MULTILINE
Definition: mpc.h:273
@ MPC_RE_DEFAULT
Definition: mpc.h:270
@ MPC_RE_DOTALL
Definition: mpc.h:274

◆ anonymous enum

anonymous enum
Enumerator
MPCA_LANG_DEFAULT 
MPCA_LANG_PREDICTIVE 
MPCA_LANG_WHITESPACE_SENSITIVE 

Definition at line 354 of file mpc.h.

354  {
355  MPCA_LANG_DEFAULT = 0,
358 };
@ MPCA_LANG_PREDICTIVE
Definition: mpc.h:356
@ MPCA_LANG_WHITESPACE_SENSITIVE
Definition: mpc.h:357
@ MPCA_LANG_DEFAULT
Definition: mpc.h:355

◆ mpc_ast_trav_order_t

Enumerator
mpc_ast_trav_order_pre 
mpc_ast_trav_order_post 

Definition at line 310 of file mpc.h.

310  {
mpc_ast_trav_order_t
Definition: mpc.h:310
@ mpc_ast_trav_order_pre
Definition: mpc.h:311
@ mpc_ast_trav_order_post
Definition: mpc.h:312

Function Documentation

◆ 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
@ MPC_TYPE_ANCHOR
Definition: mpc.c:890
#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 }
lzma_index ** i
Definition: index.h:629
void * malloc(size_t size)
Definition: malloc.c:123
int n
Definition: mipsasm.c:19
@ MPC_TYPE_AND
Definition: mpc.c:911
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 }
@ MPC_TYPE_ANY
Definition: mpc.c:893

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 }
@ MPC_TYPE_APPLY
Definition: mpc.c:901
#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 }
int x
Definition: mipsasm.c:20
@ MPC_TYPE_APPLY_TO
Definition: mpc.c:902

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 }
#define r
Definition: crypto_rc6.c:12
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 }
#define NULL
Definition: cris-opc.c:27
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_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_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 }
static RzSocket * s
Definition: rtr.c:28

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_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_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_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_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
@ MPC_TYPE_SINGLE
Definition: mpc.c:894

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)
@ MPC_TYPE_CHECK
Definition: mpc.c:913

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 }
@ MPC_TYPE_CHECK_WITH
Definition: mpc.c:914

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
@ 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_MAYBE
Definition: mpc.c:905
@ MPC_TYPE_STRING
Definition: mpc.c:899
@ MPC_TYPE_MANY
Definition: mpc.c:906
@ MPC_TYPE_COUNT
Definition: mpc.c:908
@ MPC_TYPE_EXPECT
Definition: mpc.c:889
@ MPC_TYPE_OR
Definition: mpc.c:910
@ MPC_TYPE_ONEOF
Definition: mpc.c:895
@ MPC_TYPE_MANY1
Definition: mpc.c:907

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 }
@ MPC_TYPE_UNDEFINED
Definition: mpc.c:884
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 }
@ MPC_TYPE_EOI
Definition: mpc.c:917

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_delete()

void mpc_err_delete ( mpc_err_t e)

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_print()

void mpc_err_print ( mpc_err_t e)

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 e,
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_string()

char* mpc_err_string ( mpc_err_t e)

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_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_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_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_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  f)

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 }
@ MPC_TYPE_LIFT
Definition: mpc.c:887

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 }
@ MPC_TYPE_LIFT_VAL
Definition: mpc.c:888

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_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_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_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 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
const char * filename
Definition: ioapi.h:137
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_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_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_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_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 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
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_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 }
@ MPC_TYPE_PASS
Definition: mpc.c:885

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_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 }
@ MPC_TYPE_RANGE
Definition: mpc.c:897

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

References MPC_RE_DEFAULT, and mpc_re_mode().

◆ 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_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 }
mpc_val_t * mpcf_ctor_str(void)
Definition: mpc.c:2431

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_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 }
@ MPC_TYPE_SATISFY
Definition: mpc.c:898

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

◆ 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 }
@ MPC_TYPE_SOI
Definition: mpc.c:916

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
mpc_val_t * mpcf_snd(int n, mpc_val_t **xs)
Definition: mpc.c:2626
mpc_parser_t * mpc_soi(void)
Definition: mpc.c:1977

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 }
@ MPC_TYPE_STATE
Definition: mpc.c:891

References MPC_TYPE_STATE, mpc_undefined(), and p.

Referenced by mpca_state().

◆ 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 }
static int mpc_nodecount_unretained(mpc_parser_t *p, int force)
Definition: mpc.c:3847

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 }
#define d(i)
Definition: sha256.c:44

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_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"); }
mpc_parser_t * mpc_whitespace(void)
Definition: mpc.c:2008

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 }
mpc_val_t * mpcf_fold_ast(int n, mpc_val_t **xs)
Definition: mpc.c:3212

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_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
Definition: mpc.h:40

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 *  f,
  ... 
)

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_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_val_t * mpcf_state_ast(int n, mpc_val_t **xs)
Definition: mpc.c:3256
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_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); }
mpc_parser_t * mpc_total(mpc_parser_t *a, mpc_dtor_t da)
Definition: mpc.c:2091

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

◆ 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 }
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
void mpc_val_t
Definition: mpc.h:58

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_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 **  as 
)

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_freefold()

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

◆ 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_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_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_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 }
mpc_ast_t * mpc_ast_state(mpc_ast_t *a, mpc_state_t s)
Definition: mpc.c:3004

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_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.