My Project
Loading...
Searching...
No Matches
pparg.c File Reference
#include "gwion_util.h"
#include "gwion_ast.h"

Go to the source code of this file.

Functions

static ANN Macro pparg_def (PPArg *ppa, const m_str str)
 
static ANN MacroArg pparg_arg (PPArg *ppa, m_str src)
 
static ANN GwText * pparg_body (PPArg *ppa, const m_str str)
 
 ANN2 (1)
 
ANN void pparg_ini (MemPool mp, PPArg *a)
 
ANN void pparg_end (PPArg *a)
 

Function Documentation

◆ ANN2()

ANN2 ( 1 )

Definition at line 46 of file pparg.c.

46 {
47 if (!ppa->hash.table) hini(&ppa->hash, 127);
48 DECL_B(const Macro, m, = pparg_def(ppa, str));
49 const m_str arg = strchr(str, '(');
50 if (arg) m->base = pparg_arg(ppa, arg + 1);
51 const m_str body = strchr(str, '=');
52 if (body) m->text = pparg_body(ppa, body + 1);
53 m->file = "command line";
54 return true;
55}
static ANN GwText * pparg_body(PPArg *ppa, const m_str str)
Definition pparg.c:40
static ANN Macro pparg_def(PPArg *ppa, const m_str str)
Definition pparg.c:4
static ANN MacroArg pparg_arg(PPArg *ppa, m_str src)
Definition pparg.c:20
const m_str str
Definition pparg.h:27
return macro_rem & ppa
Definition pparg.h:30
Definition macro.h:22

◆ pparg_arg()

static ANN MacroArg pparg_arg ( PPArg * ppa,
m_str src )
static

Definition at line 20 of file pparg.c.

20 {
21 const size_t sz = strlen(src);
22 char buf[sz + 1];
23 for (m_uint i = 0; i < sz; ++i) {
24 const char c = src[i];
25 if (c == ')') {
26 buf[i] = '\0';
27 return new_macroarg(ppa->hash.p, buf);
28 }
29 if (c == ',') {
30 buf[i] = '\0';
31 MacroArg arg = new_macroarg(ppa->hash.p, buf);
32 arg->next = pparg_arg(ppa, src + i + 1);
33 return arg;
34 }
35 buf[i] = c;
36 }
37 return NULL;
38}
return NULL
Definition macro.c:41
MacroArg new_macroarg(MemPool p, const m_str name)
Definition macro.c:4
MacroArg next
Definition macro.h:14

◆ pparg_body()

static ANN GwText * pparg_body ( PPArg * ppa,
const m_str str )
static

Definition at line 40 of file pparg.c.

40 {
41 GwText *text = new_text(ppa->hash.p);
42 text_add(text, str);
43 return text;
44}

◆ pparg_def()

static ANN Macro pparg_def ( PPArg * ppa,
const m_str str )
static

Definition at line 4 of file pparg.c.

4 {
5 const ssize_t sz = strlen(str);
6 char base[sz + 1];
7 m_str def = strchr(str, '(') ?: strchr(str, '=');
8 const ssize_t idx = def ? (def - str) : sz;
9 strncpy(base, str, idx);
10 base[idx] = '\0';
11 Macro m = macro_add(&ppa->hash, base);
12 if (m) {
13 m->pos = (pos_t){ 1, 1};
14 return m;
15 }
16 gw_err(MACRO_DEFINED);
17 return NULL;
18}
struct pos_t pos_t
#define MACRO_DEFINED
Definition macro.h:7
Macro macro_add(const Hash, m_str)
struct pos_t pos
Definition macro.h:29

◆ pparg_end()

ANN void pparg_end ( PPArg * a)

Definition at line 62 of file pparg.c.

62 {
63 vector_release(&a->path);
64 if (a->hash.table) {
65 macro_del(&a->hash);
66 hend(&a->hash);
67 }
68}
void macro_del(const Hash)
struct Vector_ path
Definition pparg.h:8
struct Hash_ hash
Definition pparg.h:9

◆ pparg_ini()

ANN void pparg_ini ( MemPool mp,
PPArg * a )

Definition at line 57 of file pparg.c.

57 {
58 a->hash.p = mp;
59 vector_init(&a->path);
60}