on master help sign in
Adjust so all insertion pieces start with P_
e875e0aNeil Mitchell
gen/Lib.hs+3−7
@@ -171,11 +171,7 @@ runC = f 0
171prettyC :: Show o => [C o] -> [String]
171prettyC :: Show o => [C o] -> [String]
172prettyC xs =
172prettyC xs =
173 prefix ++
173 prefix ++
174− ["static const char* parser(const char* p ARGUMENTS){"
174+ concatMap f xs
175− ," VARIABLES;"] ++
176− fi xs ++
177− [" return NULL;"
178− ,"}"]
179 where
175 where
180 (prefix, cond) = charSetC $ concatMap charSets xs
176 (prefix, cond) = charSetC $ concatMap charSets xs
181 charSets (While c x) = c : concatMap charSets x
177 charSets (While c x) = c : concatMap charSets x
@@ -183,9 +179,9 @@ prettyC xs =
183 charSets _ = []
179 charSets _ = []
184
180
185 fi = map (" "++) . concatMap f
181 fi = map (" "++) . concatMap f
186− f (Abort x) = ["abort(" ++ show x ++ ");"]
182+ f (Abort x) = ["P_Abort(" ++ show x ++ ");"]
187 f Next = ["p++;"]
183 f Next = ["p++;"]
188− f (Stmt x) = [show x ++ ";"]
184+ f (Stmt x) = ["P_" ++ show x ++ ";"]
189 f (If c true []) = ["if (" ++ cond c ++ "){"] ++ fi true ++ ["}"]
185 f (If c true []) = ["if (" ++ cond c ++ "){"] ++ fi true ++ ["}"]
190 f (If c true [false@If{}]) = ["if (" ++ cond c ++ "){"] ++ fi true ++ ["} else " ++ f1] ++ fs
186 f (If c true [false@If{}]) = ["if (" ++ cond c ++ "){"] ++ fi true ++ ["} else " ++ f1] ++ fs
191 where f1:fs = f false
187 where f1:fs = f false
gen/test.c+18−16
@@ -257,35 +257,37 @@ static void set_error(document* d, const char* msg)
257 strcpy(d->error_message, msg);
257 strcpy(d->error_message, msg);
258}
258}
259
259
260−#define ARGUMENTS , document* d
261−#define VARIABLES const char *tag_start, *name_start, *name_end, *quote_start, *quote_end
262−
263static inline str gap(const char* ref, const char* start, const char* end)
260static inline str gap(const char* ref, const char* start, const char* end)
264{
261{
265 return start_end(start - ref, end - ref);
262 return start_end(start - ref, end - ref);
266}
263}
267
264
268−#define abort(x) return x
265+#define P_Abort(x) return x
269−#define NameStart name_start = p
266+#define P_NameStart name_start = p
270−#define NameEnd name_end = p
267+#define P_NameEnd name_end = p
271−#define QuoteStart quote_start = p
268+#define P_QuoteStart quote_start = p
272−#define QuoteEnd \
269+#define P_QuoteEnd \
273 quote_end = p; \
270 quote_end = p; \
274 attr_alloc(&d->attrs, 1); \
271 attr_alloc(&d->attrs, 1); \
275 d->attrs.attrs[d->attrs.used].name = gap(d->body, name_start, name_end); \
272 d->attrs.attrs[d->attrs.used].name = gap(d->body, name_start, name_end); \
276 d->attrs.attrs[d->attrs.used].value = gap(d->body, quote_start, quote_end); \
273 d->attrs.attrs[d->attrs.used].value = gap(d->body, quote_start, quote_end); \
277 d->attrs.used++;
274 d->attrs.used++;
278−#define AttribsStart printf("AttribsStart %s\n", p)
275+#define P_AttribsStart printf("AttribsStart %s\n", p)
279−#define AttribsEnd printf("AttribsEnd %s\n", p)
276+#define P_AttribsEnd printf("AttribsEnd %s\n", p)
280−#define Tag tag_start = p
277+#define P_Tag tag_start = p
281−#define TagComment printf("TagComment %s\n", p)
278+#define P_TagComment printf("TagComment %s\n", p)
282−#define TagOpen printf("TagOpen %s\n", p)
279+#define P_TagOpen printf("TagOpen %s\n", p)
283−#define TagClose printf("TagClose %s\n", p)
280+#define P_TagClose printf("TagClose %s\n", p)
284−#define TagOpenClose \
281+#define P_TagOpenClose \
285 d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
282 d->nodes.nodes[d->nodes.used_front].outer = gap(d->body, tag_start, p); \
286 printf("TagOpenClose %s\n", p)
283 printf("TagOpenClose %s\n", p)
287
284
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"
288+# include "test.h"
289+ return NULL;
290+}
289
291
290// Based on looking at ~50Kb XML documents, they seem to have ~700 attributes
292// Based on looking at ~50Kb XML documents, they seem to have ~700 attributes
291// and ~300 nodes, so size appropriately to cope with that.
293// and ~300 nodes, so size appropriately to cope with that.