on master help sign in
Adjust so all insertion pieces start with P_
commite875e0aad74a4a82783f4c8d97dbc6ec3f5b64a6 authorNeil Mitchell <ndmitchell@gmail.com> dateWed 3 Jan 2018, 22:31 (9 years ago) parent04b3bd0
2 files changed+21−23
gen/Lib.hs+3−7 gen/test.c+18−16
gen/Lib.hs+3−7
@@ -171,11 +171,7 @@ runC = f 0
171171prettyC :: Show o => [C o] -> [String]
172172prettyC xs =
173173 prefix ++
174− ["static const char* parser(const char* p ARGUMENTS){"
175− ," VARIABLES;"] ++
176− fi xs ++
177− [" return NULL;"
178− ,"}"]
174+ concatMap f xs
179175 where
180176 (prefix, cond) = charSetC $ concatMap charSets xs
181177 charSets (While c x) = c : concatMap charSets x
@@ -183,9 +179,9 @@ prettyC xs =
183179 charSets _ = []
184180
185181 fi = map (" "++) . concatMap f
186− f (Abort x) = ["abort(" ++ show x ++ ");"]
182+ f (Abort x) = ["P_Abort(" ++ show x ++ ");"]
187183 f Next = ["p++;"]
188− f (Stmt x) = [show x ++ ";"]
184+ f (Stmt x) = ["P_" ++ show x ++ ";"]
189185 f (If c true []) = ["if (" ++ cond c ++ "){"] ++ fi true ++ ["}"]
190186 f (If c true [false@If{}]) = ["if (" ++ cond c ++ "){"] ++ fi true ++ ["} else " ++ f1] ++ fs
191187 where f1:fs = f false
gen/test.c+18−16
@@ -257,35 +257,37 @@ static void set_error(document* d, const char* msg)
257257 strcpy(d->error_message, msg);
258258}
259259
260−#define ARGUMENTS , document* d
261−#define VARIABLES const char *tag_start, *name_start, *name_end, *quote_start, *quote_end
262−
263260static inline str gap(const char* ref, const char* start, const char* end)
264261{
265262 return start_end(start - ref, end - ref);
266263}
267264
268−#define abort(x) return x
269−#define NameStart name_start = p
270−#define NameEnd name_end = p
271−#define QuoteStart quote_start = p
272−#define QuoteEnd \
265+#define P_Abort(x) return x
266+#define P_NameStart name_start = p
267+#define P_NameEnd name_end = p
268+#define P_QuoteStart quote_start = p
269+#define P_QuoteEnd \
273270 quote_end = p; \
274271 attr_alloc(&d->attrs, 1); \
275272 d->attrs.attrs[d->attrs.used].name = gap(d->body, name_start, name_end); \
276273 d->attrs.attrs[d->attrs.used].value = gap(d->body, quote_start, quote_end); \
277274 d->attrs.used++;
278−#define AttribsStart printf("AttribsStart %s\n", p)
279−#define AttribsEnd printf("AttribsEnd %s\n", p)
280−#define Tag tag_start = p
281−#define TagComment printf("TagComment %s\n", p)
282−#define TagOpen printf("TagOpen %s\n", p)
283−#define TagClose printf("TagClose %s\n", p)
284−#define TagOpenClose \
275+#define P_AttribsStart printf("AttribsStart %s\n", p)
276+#define P_AttribsEnd printf("AttribsEnd %s\n", p)
277+#define P_Tag tag_start = p
278+#define P_TagComment printf("TagComment %s\n", p)
279+#define P_TagOpen printf("TagOpen %s\n", p)
280+#define P_TagClose printf("TagClose %s\n", p)
281+#define P_TagOpenClose \
285282 d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
286283 printf("TagOpenClose %s\n", p)
287284
288−#include "test.h"
285+static const char* parser(const char* p, document* d)
286+{
287+ const char *tag_start, *name_start, *name_end, *quote_start, *quote_end;
288+# include "test.h"
289+ return NULL;
290+}
289291
290292// Based on looking at ~50Kb XML documents, they seem to have ~700 attributes
291293// and ~300 nodes, so size appropriately to cope with that.