Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API ? #2

Open
jwerle opened this issue Feb 22, 2015 · 0 comments
Open

API ? #2

jwerle opened this issue Feb 22, 2015 · 0 comments

Comments

@jwerle
Copy link
Member

jwerle commented Feb 22, 2015

What should the api be ?

#define X(T) XX(HF_##T)

enum {
#define XX(T) T
  X(UNKNOWN) = -1,
  X(NULL) = 0,
  X(LABEL),
  X(COMMAND),
  X(ARGUMENT)
#undef XX
};

char hf_type_str[] = {
#define XX(T) # T
  X(NULL),
  X(LABEL),
  X(COMMAND),
  X(ARGUMENT)
#undef XX
};

#undef X

typedef struct hf_token hf_token_t;
struct hf_token {
  int type;
  const char *data;
};

typedef struct hf_lexer hf_lexer_t;
struct hf_lexer {
  const char *src;
  int lineno;
  int offset;
  hf_token_t current;
};

int
hf_lexer_scan (hf_lexer_t *self);

usage:

int
main (void) {
  hf_lexer_t lexer = {
    .src = "/path/to/hackfile",
    .lineno = 1,
    .offset = 1
  };

  while (hf_lexer_scan(&lexer)) {
    printf("type=%s data=%s\n", hf_type_str[lexer.current.type], lexer.current.data);
  }
  return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant