sexp.h 698 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef __sti__sexp_h__
  2. #define __sti__sexp_h__
  3. // Public Domain.
  4. #include <stdint.h>
  5. #include "vec.h"
  6. // A simple S-Expression parser
  7. // Supports (, [, {, and < as brace characters
  8. typedef struct sexp {
  9. char type; // 0 = list, 1 = literal
  10. char brace;
  11. char* str;
  12. VEC(struct sexp*) args;
  13. } sexp;
  14. sexp* sexp_parse(char* source);
  15. void sexp_free(sexp* x);
  16. int64_t sexp_asInt(sexp* x);
  17. double sexp_asDouble(sexp* x);
  18. int64_t sexp_argAsInt(sexp* x, size_t argn);
  19. double sexp_argAsDouble(sexp* x, size_t argn);
  20. // returns internally managed string, user must dup
  21. char* sexp_argAsStr(sexp* x, size_t argn);
  22. sexp* sexp_argAsSexp(sexp* x, size_t argn);
  23. #endif // __sti__sexp_h__