doc Makefile: issue warning about chars that cannot be output
[pgsql.git] / src / backend / replication / syncrep_gram.y
blobe4d9962226c411a5f0f7bfd19b03539e302253da
1 %{
2 /*-------------------------------------------------------------------------
4 * syncrep_gram.y - Parser for synchronous_standby_names
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * src/backend/replication/syncrep_gram.y
13 *-------------------------------------------------------------------------
15 #include "postgres.h"
17 #include "nodes/pg_list.h"
18 #include "replication/syncrep.h"
20 #include "syncrep_gram.h"
22 /* Result of parsing is returned in one of these two variables */
23 SyncRepConfigData *syncrep_parse_result;
24 char *syncrep_parse_error_msg;
26 static SyncRepConfigData *create_syncrep_config(const char *num_sync,
27 List *members, uint8 syncrep_method);
29 /* silence -Wmissing-variable-declarations */
30 extern int syncrep_yychar;
31 extern int syncrep_yynerrs;
34 * Bison doesn't allocate anything that needs to live across parser calls,
35 * so we can easily have it use palloc instead of malloc. This prevents
36 * memory leaks if we error out during parsing.
38 #define YYMALLOC palloc
39 #define YYFREE pfree
43 %expect 0
44 %name-prefix="syncrep_yy"
46 %union
48 char *str;
49 List *list;
50 SyncRepConfigData *config;
53 %token <str> NAME NUM JUNK ANY FIRST
55 %type <config> result standby_config
56 %type <list> standby_list
57 %type <str> standby_name
59 %start result
62 result:
63 standby_config { syncrep_parse_result = $1; }
66 standby_config:
67 standby_list { $$ = create_syncrep_config("1", $1, SYNC_REP_PRIORITY); }
68 | NUM '(' standby_list ')' { $$ = create_syncrep_config($1, $3, SYNC_REP_PRIORITY); }
69 | ANY NUM '(' standby_list ')' { $$ = create_syncrep_config($2, $4, SYNC_REP_QUORUM); }
70 | FIRST NUM '(' standby_list ')' { $$ = create_syncrep_config($2, $4, SYNC_REP_PRIORITY); }
73 standby_list:
74 standby_name { $$ = list_make1($1); }
75 | standby_list ',' standby_name { $$ = lappend($1, $3); }
78 standby_name:
79 NAME { $$ = $1; }
80 | NUM { $$ = $1; }
84 static SyncRepConfigData *
85 create_syncrep_config(const char *num_sync, List *members, uint8 syncrep_method)
87 SyncRepConfigData *config;
88 int size;
89 ListCell *lc;
90 char *ptr;
92 /* Compute space needed for flat representation */
93 size = offsetof(SyncRepConfigData, member_names);
94 foreach(lc, members)
96 char *standby_name = (char *) lfirst(lc);
98 size += strlen(standby_name) + 1;
101 /* And transform the data into flat representation */
102 config = (SyncRepConfigData *) palloc(size);
104 config->config_size = size;
105 config->num_sync = atoi(num_sync);
106 config->syncrep_method = syncrep_method;
107 config->nmembers = list_length(members);
108 ptr = config->member_names;
109 foreach(lc, members)
111 char *standby_name = (char *) lfirst(lc);
113 strcpy(ptr, standby_name);
114 ptr += strlen(standby_name) + 1;
117 return config;