示例#1
0
static void
phase8_get (token_ty *tp)
{
  phase5_get (tp);
  if (tp->type != token_type_string_literal)
    return;
  for (;;)
    {
      token_ty tmp;
      size_t len;

      phase5_get (&tmp);
      if (tmp.type != token_type_string_literal)
        {
          phase5_unget (&tmp);
          return;
        }
      len = strlen (tp->string);
      tp->string = xrealloc (tp->string, len + strlen (tmp.string) + 1);
      strcpy (tp->string + len, tmp.string);
      free_token (&tmp);
    }
}
示例#2
0
文件: x-c.c 项目: alan707/senuti
static void
phaseX_get (token_ty *tp)
{
  static bool middle;	/* false at the beginning of a line, true otherwise.  */

  phase5_get (tp);

  if (tp->type == token_type_eoln || tp->type == token_type_eof)
    middle = false;
  else
    {
      if (middle)
	{
	  /* Turn hash in the middle of a line into a plain symbol token.  */
	  if (tp->type == token_type_hash)
	    tp->type = token_type_symbol;
	}
      else
	{
	  /* When we see leading whitespace followed by a hash sign,
	     discard the leading white space token.  The hash is all
	     phase 6 is interested in.  */
	  if (tp->type == token_type_white_space)
	    {
	      token_ty next;

	      phase5_get (&next);
	      if (next.type == token_type_hash)
		*tp = next;
	      else
		phase5_unget (&next);
	    }
	  middle = true;
	}
    }
}
示例#3
0
/* Extract messages until the next balanced closing parenthesis.
   Extracted messages are added to MLP.
   Return true upon eof, false upon closing parenthesis.  */
static bool
extract_parenthesized (message_list_ty *mlp,
                       flag_context_ty outer_context,
                       flag_context_list_iterator_ty context_iter,
                       bool in_i18n)
{
  int state; /* 1 or 2 inside _( ... ), otherwise 0 */
  int plural_state = 0; /* defined only when in states 1 and 2 */
  message_ty *plural_mp = NULL; /* defined only when in states 1 and 2 */
  /* Context iterator that will be used if the next token is a '('.  */
  flag_context_list_iterator_ty next_context_iter =
    passthrough_context_list_iterator;
  /* Current context.  */
  flag_context_ty inner_context =
    inherited_context (outer_context,
                       flag_context_list_iterator_advance (&context_iter));

  /* Start state is 0 or 1.  */
  state = (in_i18n ? 1 : 0);

  for (;;)
    {
      token_ty token;

      if (in_i18n)
        phase8_get (&token);
      else
        phase5_get (&token);

      switch (token.type)
        {
        case token_type_i18n:
          if (extract_parenthesized (mlp, inner_context, next_context_iter,
                                     true))
            return true;
          next_context_iter = null_context_list_iterator;
          state = 0;
          continue;

        case token_type_string_literal:
          if (state == 1)
            {
              lex_pos_ty pos;
              pos.file_name = logical_file_name;
              pos.line_number = token.line_number;

              if (plural_state == 0)
                {
                  /* Seen an msgid.  */
                  plural_mp = remember_a_message (mlp, NULL, token.string,
                                                  inner_context, &pos,
                                                  NULL, token.comment);
                  plural_state = 1;
                  state = 2;
                }
              else
                {
                  /* Seen an msgid_plural.  */
                  if (plural_mp != NULL)
                    remember_a_message_plural (plural_mp, token.string,
                                               inner_context, &pos,
                                               token.comment);
                  state = 0;
                }
              drop_reference (token.comment);
            }
          else
            {
              free_token (&token);
              state = 0;
            }
          next_context_iter = null_context_list_iterator;
          continue;

        case token_type_symbol:
          next_context_iter =
            flag_context_list_iterator (
              flag_context_list_table_lookup (
                flag_context_list_table,
                token.string, strlen (token.string)));
          free_token (&token);
          state = 0;
          continue;

        case token_type_lparen:
          if (extract_parenthesized (mlp, inner_context, next_context_iter,
                                     false))
            return true;
          next_context_iter = null_context_list_iterator;
          state = 0;
          continue;

        case token_type_rparen:
          return false;

        case token_type_comma:
          if (state == 2)
            state = 1;
          else
            state = 0;
          inner_context =
            inherited_context (outer_context,
                               flag_context_list_iterator_advance (
                                 &context_iter));
          next_context_iter = passthrough_context_list_iterator;
          continue;

        case token_type_other:
          next_context_iter = null_context_list_iterator;
          state = 0;
          continue;

        case token_type_eof:
          return true;

        default:
          abort ();
        }
    }
}
示例#4
0
static void
x_lua_lex (token_ty *tok)
{
  phase5_get (tok);
}