kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

link.c (985B)


      1 /* Link check for --lexer-standalone: a tokenizer-only program built from the
      2  * generated jsonsa.c plus this driver and linked WITHOUT libgram, proving the
      3  * standalone lexer carries zero runtime-lexer dependency. The only libgram symbol
      4  * in the generated object is the table parser_init constructor (always emitted),
      5  * which is unused here and removed by the linker's dead-strip. */
      6 #include "jsonsa.h"
      7 
      8 #include <stdio.h>
      9 #include <string.h>
     10 
     11 int main(void) {
     12     const char *s = "[1, 2, {\"k\": true, \"v\": [null, -3.5e2]}, \"x\"]";
     13     jsonsa_lex lx;
     14     jsonsa_lex_init(&lx, (const unsigned char *)s, strlen(s));
     15     size_t n = 0;
     16     KitGramToken tok;
     17     KitGramLexStatus st;
     18     while ((st = jsonsa_lex_next(&lx, &tok)) == KIT_GRAM_LEX_TOKEN) n++;
     19     if (st != KIT_GRAM_LEX_EOF) {
     20         fprintf(stderr, "standalone link check: lex error\n");
     21         return 1;
     22     }
     23     printf("standalone link check: %zu tokens, linked without libgram\n", n);
     24     return n ? 0 : 1;
     25 }