Ejemplo n.º 1
0
// Process any deferred token we have
static void process_deferred_ast(parser_t* parser, rule_state_t* state)
{
  assert(parser != NULL);
  assert(state != NULL);

  if(state->deferred)
  {
    token_t* deferred_token = token_new(state->deferred_id);
    token_set_pos(deferred_token, parser->source, state->line, state->pos);
    state->ast = ast_token(deferred_token);
    state->deferred = false;
  }
}
Ejemplo n.º 2
0
static void fetch_next_lexer_token(parser_t* parser, bool free_prev_token)
{
  token_t* old_token = parser->token;
  token_t* new_token = lexer_next(parser->lexer);

  if(old_token != NULL)
    parser->last_token_line = token_line_number(old_token);

  if(old_token != NULL && token_get_id(new_token) == TK_EOF)
  {
    // Use location of last token for EOF to get better error reporting
    token_set_pos(new_token, token_source(old_token),
      token_line_number(old_token), token_line_position(old_token));
  }

  if(free_prev_token)
    token_free(old_token);

  parser->token = new_token;
}
Ejemplo n.º 3
0
// Make a token with the specified ID and no token text
static token_t* make_token(lexer_t* lexer, token_id id)
{
  token_t* t = token_new(id);
  token_set_pos(t, lexer->source, lexer->token_line, lexer->token_pos);
  return t;
}
Ejemplo n.º 4
0
void ast_setpos(ast_t* ast, source_t* source, size_t line, size_t pos)
{
  assert(ast != NULL);
  token_set_pos(ast->t, source, line, pos);
}