Logo Search packages:      
Sourcecode: uncrustify version File versions

static bool parse_next ( chunk_t pc  )  [static]

Skips the next bit of whatever and returns the type of block.

pc->str is the input text. pc->len in the output length. pc->type is the output type pc->column is output column

Parameters:
pc The structure to update, str is an input.
Returns:
true/false - whether anything was parsed

Parse whitespace

Handle unknown/unhandled preprocessors

Detect backslash-newline

REVISIT: does this need to handle other line endings?

Parse comments

Parse strings and character constants

Definition at line 593 of file tokenize.cpp.

References chunk_t::column, d_parse_string(), chunk_t::len, chunk_t::nl_count, chunk_t::orig_col, chunk_t::orig_line, parse_bs_newline(), parse_comment(), parse_cs_string(), parse_number(), parse_string(), parse_whitespace(), parse_word(), chunk_t::str, and chunk_t::type.

Referenced by tokenize().

{
   const chunk_tag_t *punc;

   if ((pc == NULL) || (pc->str == NULL) || (*pc->str == 0))
   {
      //fprintf(stderr, "All done!\n");
      return(false);
   }

   /* Save off the current column */
   pc->orig_line = cpd.line_number;
   pc->column    = cpd.column;
   pc->orig_col  = cpd.column;
   pc->len       = 0;
   pc->type      = CT_NONE;
   pc->nl_count  = 0;


   /**
    *  Parse whitespace
    */
   if (parse_whitespace(pc))
   {
      return(true);
   }

   /**
    *  Handle unknown/unhandled preprocessors
    */
   if (cpd.in_preproc == CT_PP_OTHER)
   {
      /* Chunk to a newline or comment */
      pc->type = CT_PREPROC_BODY;
      char last = 0;
      while (pc->str[pc->len] != 0)
      {
         char ch = pc->str[pc->len];

         /* Bail on a non-escaped newline or on a C++ comment start */
         if ((((ch == '\n') || (ch == '\r')) && (last != '\\')) ||
             ((ch == '/') && (pc->str[pc->len + 1] == '/')))
         {
            break;
         }
         last = ch;
         pc->len++;
      }
      if (pc->len > 0)
      {
         return(true);
      }
   }

   /**
    *   Detect backslash-newline
    *
    * REVISIT: does this need to handle other line endings?
    */
   if ((pc->str[0] == '\\') && parse_bs_newline(pc))
   {
      cpd.column = 1;
      cpd.line_number++;
      return(true);
   }

   /**
    *  Parse comments
    */
   if (parse_comment(pc))
   {
      return(true);
   }

   /* Check for C# literal strings, ie @"hello" */
   if (((cpd.lang_flags & LANG_CS) != 0) && (*pc->str == '@'))
   {
      if (pc->str[1] == '"')
      {
         parse_cs_string(pc);
         return(true);
      }
      if (((get_char_table(pc->str[1]) & CT_KW1) != 0) &&
          parse_word(pc, true))
      {
         return(true);
      }
   }

   /* PAWN specific stuff */
   if ((cpd.lang_flags & LANG_PAWN) != 0)
   {
      /* Check for PAWN strings: \"hi" or !"hi" or !\"hi" or \!"hi" */
      if ((pc->str[0] == '\\') || (pc->str[0] == '!'))
      {
         if (pc->str[1] == '"')
         {
            parse_string(pc, 1, (*pc->str == '!'));
            return(true);
         }
         else if (((pc->str[1] == '\\') || (pc->str[1] == '!')) &&
                  (pc->str[2] == '"'))
         {
            parse_string(pc, 2, false);
            return(true);
         }
      }
   }

   /**
    *  Parse strings and character constants
    */

   if (parse_number(pc))
   {
      return(true);
   }

   if ((cpd.lang_flags & LANG_D) != 0)
   {
      /* D specific stuff */
      if (d_parse_string(pc))
      {
         return(true);
      }
   }
   else
   {
      /* Not D stuff */

      /* Check for L'a', L"abc", 'a', "abc", <abc> strings */
      if (((*pc->str == 'L') && ((pc->str[1] == '"') || (pc->str[1] == '\''))) ||
          (*pc->str == '"') ||
          (*pc->str == '\'') ||
          ((*pc->str == '<') && (cpd.in_preproc == CT_PP_INCLUDE)))
      {
         parse_string(pc, (*pc->str == 'L') ? 1 : 0, true);
         return(true);
      }
   }

   /* Check for pawn/ObjectiveC identifiers */
   if ((*pc->str == '@') &&
       ((get_char_table(pc->str[1]) & CT_KW2) != 0) &&
       parse_word(pc, false))
   {
      return(true);
   }

   if (((get_char_table(*pc->str) & CT_KW1) != 0) &&
       parse_word(pc, false))
   {
      return(true);
   }

   if ((punc = find_punctuator(pc->str, cpd.lang_flags)) != NULL)
   {
      pc->type    = punc->type;
      pc->len     = strlen(punc->tag);
      cpd.column += pc->len;
      return(true);
   }


   /* throw away this character */
   pc->type = CT_UNKNOWN;
   pc->len  = 1;

   LOG_FMT(LWARN, "%s:%d Garbage in col %d: %x\n",
           cpd.filename, pc->orig_line, cpd.column, *pc->str);
   cpd.error_count++;
   return(true);
}


Generated by  Doxygen 1.6.0   Back to index