59 assert(nob <= ctx->fc_remain);
61 for (; nob > 0; --nob, --
ctx->fc_remain, ++
ctx->fc_pt) {
62 if (*
ctx->fc_pt ==
'\n') {
75 #define SAFE(ctx, cond) ((ctx)->fc_remain > 0 && (cond)) 84 return ctx->fc_remain >=
n && memcmp(
ctx->fc_pt,
s,
n) == 0;
89 return (
'a' <=
c &&
c <=
'z') || (
'A' <=
c &&
c <=
'Z') ||
c ==
'_';
104 static const char space[] =
" \t\v\n\r";
115 if (
ctx->fc_remain < 2)
116 errx(2,
"Unterminated comment");
146 if (
ctx->fc_depth > 0) {
147 *tok =
ctx->fc_stack[--
ctx->fc_depth];
152 if (
ctx->fc_remain == 0)
155 size_t len = strlen(kw->
k_name);
156 const char *pt =
ctx->fc_pt;
158 if (
ctx->fc_remain >= len && !memcmp(pt, kw->
k_name, len)) {
172 warnx(
"\":\" must be followed by a tag");
175 }
else if (
at(
ctx,
'[')) {
184 warnx(
"\"[\" must be followed by an escape and \"]\"");
186 }
else if (
at(
ctx,
'*')) {
191 warnx(
"\"*\" must be followed by a type name");
194 }
else if (
at(
ctx,
'"')) {
221 ctx->fc_stack[
ctx->fc_depth++] = *tok;
236 return snprintf(
buf,
nr,
"[%i:%i] %zu/%zu: '%c'",
238 ctx->fc_size, *
ctx->fc_pt);
static void ctx_step(struct ff2c_context *ctx)
void ff2c_context_fini(struct ff2c_context *ctx)
static void skip_space(struct ff2c_context *ctx)
void ff2c_token_put(struct ff2c_context *ctx, struct ff2c_token *tok)
int ff2c_token_get(struct ff2c_context *ctx, struct ff2c_token *tok)
static void tok_end(struct ff2c_context *ctx, struct ff2c_token *tok)
static bool is_start(char c)
enum ff2c_token_type ft_type
static bool at_string(struct ff2c_context *ctx, const char *s, size_t n)
const char * ff2c_token_type_name[]
static struct m0_addb2_callback c
int ff2c_context_loc(struct ff2c_context *ctx, int nr, char *buf)
static const struct keyword keywords[]
static bool is_middle(char c)
static void ctx_move(struct ff2c_context *ctx, size_t nob)
static bool at(struct ff2c_context *ctx, char c)
static bool get_literal(struct ff2c_context *ctx, struct ff2c_token *tok)
static int start(struct m0_fom *fom)
enum ff2c_token_type k_type
static struct m0_addb2_source * s
void ff2c_context_init(struct ff2c_context *ctx, const char *buf, size_t size)