5 #define FL_INIT(l, f) (l) = (f) /* Specific flags location. */
6 #define FL_SET(l, f) ((l) |= (f))
7 #define FL_CLR(l, f) ((l) &= ~(f))
8 #define FL_ISSET(l, f) ((l) & (f))
10 #define F_INIT(p, f) FL_INIT((p)->flags, f) /* Structure element flags. */
11 #define F_SET(p, f) FL_SET((p)->flags, f)
12 #define F_CLR(p, f) FL_CLR((p)->flags, f)
13 #define F_ISSET(p, f) FL_ISSET((p)->flags, f)
15 static void yll_emit_space(YllEmitter
*e
)
17 if (F_ISSET(e
->stack
, YLL_ADD_SPACE
))
19 F_CLR(e
->stack
, YLL_ADD_SPACE
);
22 static void yll_emit_transfer(YllEmitter
*e
)
26 fprintf(e
->out
, "!%s", e
->transfer
);
28 F_SET(e
->stack
, YLL_ADD_SPACE
);
32 static void yll_push(YllEmitter
*e
, YllEmitterNode
*n
)
41 static void yll_pop(YllEmitter
*e
)
43 YllEmitterNode
*n
= e
->stack
;
44 e
->stack
= e
->stack
->next
;
49 static void next_doc(YllEmitter
*e
)
51 fprintf(e
->out
, "--- ");
54 static void next_anchor(YllEmitter
*e
)
56 YllAnchorNode
*n
= (YllAnchorNode
*) e
->stack
;
60 fprintf(e
->out
, "&%d", a
);
61 F_SET(e
->stack
, YLL_ADD_SPACE
);
64 static void next_seq(YllEmitter
*e
)
66 YllSeqNode
*n
= (YllSeqNode
*) e
->stack
;
67 if (F_ISSET(e
->stack
, YLL_INLINE_SEQ
)) {
69 fprintf(e
->out
, ", ");
71 fprintf(e
->out
, "\n%*s- ", e
->indent
, "");
75 static void next_map_val(YllEmitter
*e
);
77 static void next_map_key(YllEmitter
*e
)
79 F_CLR(e
->stack
, YLL_ADD_SPACE
);
80 fprintf(e
->out
, "\n%*s", e
->indent
, "");
81 e
->stack
->nextf
= next_map_val
;
84 static void next_map_val(YllEmitter
*e
)
86 fprintf(e
->out
, ": ");
87 e
->stack
->nextf
= next_map_key
;
90 YllEmitter
* yll_new_emitter() {
93 e
= S_ALLOC(YllEmitter
);
94 n
= S_ALLOC(YllEmitterNode
);
105 void yll_emitter_handler(YllEmitter
*e
, YllOutputHandler hdlr
)
109 void yll_free_emitter(YllEmitter
*e
)
111 fprintf(e
->out
, "\n");
116 void yll_emitter_start_seq(YllEmitter
*e
)
120 n
= S_ALLOC(YllSeqNode
);
121 n
->en
.nextf
= next_seq
;
123 yll_push(e
, (YllEmitterNode
*)n
);
124 yll_emit_transfer(e
);
125 if (F_ISSET(&n
->en
, YLL_INLINE_SEQ
))
126 fprintf(e
->out
, "[");
129 void yll_emitter_end_seq(YllEmitter
*e
)
131 YllSeqNode
*n
= (YllSeqNode
*) e
->stack
;
132 if (F_ISSET(e
->stack
, YLL_INLINE_SEQ
))
133 fprintf(e
->out
, "]");
135 if (F_ISSET(e
->stack
, YLL_ADD_SPACE
))
136 fprintf(e
->out
, " ");
137 fprintf(e
->out
, "[]");
142 void yll_emitter_start_map(YllEmitter
*e
)
146 n
= S_ALLOC(YllEmitterNode
);
147 n
->nextf
= next_map_key
;
149 yll_emit_transfer(e
);
152 void yll_emitter_end_map(YllEmitter
*e
)
157 SYMID
yll_emitter_anchor(YllEmitter
*e
)
160 SYMID a
= ++e
->last_anchor
;
161 n
= S_ALLOC(YllAnchorNode
);
163 n
->en
.nextf
= next_anchor
;
164 yll_push(e
, (YllEmitterNode
*)n
);
168 void yll_emitter_alias(YllEmitter
*e
, SYMID id
)
171 fprintf(e
->out
, "*%d", id
);
174 void yll_emitter_write_string(YllEmitter
*e
, const char *str
)
177 yll_emit_transfer(e
);
179 if (strpbrk(str
, "[]#:-"))
181 fprintf(e
->out
, "%s", str
);
182 if (strpbrk(str
, "[]#:-"))
186 void yll_emitter_write_int(YllEmitter
*e
, int i
)
189 yll_emit_transfer(e
);
191 fprintf(e
->out
, "%d", i
);
194 void yll_emitter_write_null(YllEmitter
*e
)
197 yll_emit_transfer(e
);
199 fprintf(e
->out
, "~");
202 void yll_emitter_set_options(YllEmitter
*e
, YllOption o
)
207 void yll_emitter_set_transfer(YllEmitter
*e
, const char *t
)