Skip to content

API ? #2

Open
Open
@jwerle

Description

@jwerle

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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions