Nice skeleton of parser.
This commit is contained in:
parent
6694d3d596
commit
9762502ea6
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
|
|
||||||
const char *BLANKS = " \t";
|
const char *BLANKS = " \t";
|
||||||
const char *TEXT = " hi there fr[ie]nd";
|
const char *TEXT = " hi there fr[ie]nd";
|
||||||
/* 01234567890123456789
|
/* 01234567890123456789
|
||||||
^ ^
|
^ ^
|
||||||
*/
|
*/
|
||||||
|
|
@ -30,12 +30,20 @@ main(void)
|
||||||
text = trim_leading_blanks((char *)TEXT);
|
text = trim_leading_blanks((char *)TEXT);
|
||||||
rest = strpbrk(text, " []");
|
rest = strpbrk(text, " []");
|
||||||
while (NULL != rest) {
|
while (NULL != rest) {
|
||||||
|
/* How many chars have we got? */
|
||||||
diff = rest - text;
|
diff = rest - text;
|
||||||
printf("%ld\n", diff);
|
printf("%ld\n", diff);
|
||||||
|
|
||||||
|
/* Allocate and copy out the substring. */
|
||||||
snip = (char *)GC_malloc(diff + 1);
|
snip = (char *)GC_malloc(diff + 1);
|
||||||
strncat(snip, text, diff);
|
strncat(snip, text, diff);
|
||||||
printf("%s <%c>\n", snip, rest[0]);
|
printf("%s\n", snip);
|
||||||
text = ++rest;
|
|
||||||
|
/* The next char is a space or '[' or ']'. */
|
||||||
|
printf("<%c>\n", rest[0]);
|
||||||
|
|
||||||
|
/* */
|
||||||
|
text = trim_leading_blanks(++rest);
|
||||||
rest = strpbrk(text, " []");
|
rest = strpbrk(text, " []");
|
||||||
}
|
}
|
||||||
printf("%s\n", text);
|
printf("%s\n", text);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue