Remake
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Enumerations | Functions
Lexer

Enumerations

enum  {
  Unexpected = 0, Word = 1 << 1, Colon = 1 << 2, Equal = 1 << 3,
  Dollarpar = 1 << 4, Rightpar = 1 << 5, Comma = 1 << 6, Plusequal = 1 << 7
}
 

Functions

static void skip_spaces (std::istream &in)
 
static void skip_empty (std::istream &in)
 
static bool skip_eol (std::istream &in, bool multi=false)
 
static int expect_token (std::istream &in, int mask)
 
static std::string read_word (std::istream &in)
 

Detailed Description

Enumeration Type Documentation

anonymous enum
Enumerator
Unexpected 
Word 
Colon 
Equal 
Dollarpar 
Rightpar 
Comma 
Plusequal 

Definition at line 914 of file remake.cpp.

915 {
916  Unexpected = 0,
917  Word = 1 << 1,
918  Colon = 1 << 2,
919  Equal = 1 << 3,
920  Dollarpar = 1 << 4,
921  Rightpar = 1 << 5,
922  Comma = 1 << 6,
923  Plusequal = 1 << 7,
924 };

Function Documentation

static int expect_token ( std::istream &  in,
int  mask 
)
static

Skip spaces and peek at the next token. If it is one of mask, skip it (if it is not Word) and return it.

Note
For composite tokens allowed by mask, input characters might have been eaten even for an Unexpected result.

Definition at line 932 of file remake.cpp.

Referenced by addprefix_generator::addprefix_generator(), addsuffix_generator::addsuffix_generator(), load_rule(), load_rules(), input_generator::next(), addprefix_generator::next(), and addsuffix_generator::next().

933 {
934  while (true)
935  {
936  skip_spaces(in);
937  char c = in.peek();
938  if (!in.good()) return Unexpected;
939  int tok;
940  switch (c)
941  {
942  case '\r':
943  case '\n': return Unexpected;
944  case ':': tok = Colon; break;
945  case ',': tok = Comma; break;
946  case '=': tok = Equal; break;
947  case ')': tok = Rightpar; break;
948  case '$':
949  if (!(mask & Dollarpar)) return Unexpected;
950  in.ignore(1);
951  tok = Dollarpar;
952  if (in.peek() != '(') return Unexpected;
953  break;
954  case '+':
955  if (!(mask & Plusequal)) return Unexpected;
956  in.ignore(1);
957  tok = Plusequal;
958  if (in.peek() != '=') return Unexpected;
959  break;
960  case '\\':
961  in.ignore(1);
962  if (skip_eol(in)) continue;
963  in.putback('\\');
964  return mask & Word ? Word : Unexpected;
965  default:
966  return mask & Word ? Word : Unexpected;
967  }
968  if (!(tok & mask)) return Unexpected;
969  in.ignore(1);
970  return tok;
971  }
972 }
static std::string read_word ( std::istream &  in)
static

Read a (possibly quoted) word.

Definition at line 977 of file remake.cpp.

Referenced by load_rule(), load_rules(), and input_generator::next().

978 {
979  int c = in.get();
980  std::string res;
981  if (!in.good()) return res;
982  char const *separators = " \t\r\n:$(),=+\"";
983  bool quoted = c == '"';
984  if (!quoted)
985  {
986  if (strchr(separators, c))
987  {
988  in.putback(c);
989  return res;
990  }
991  res += c;
992  }
993  while (true)
994  {
995  c = in.get();
996  if (!in.good()) return res;
997  if (quoted)
998  {
999  if (c == '\\')
1000  res += in.get();
1001  else if (c == '"')
1002  return res;
1003  else
1004  res += c;
1005  }
1006  else
1007  {
1008  if (strchr(separators, c))
1009  {
1010  in.putback(c);
1011  return res;
1012  }
1013  res += c;
1014  }
1015  }
1016 }
static void skip_empty ( std::istream &  in)
static

Skip empty lines.

Definition at line 893 of file remake.cpp.

Referenced by load_dependencies(), load_rules(), and skip_eol().

894 {
895  char c;
896  while (strchr("\r\n", (c = in.get()))) {}
897  if (in.good()) in.putback(c);
898 }
static bool skip_eol ( std::istream &  in,
bool  multi = false 
)
static

Skip end of line. If multi is true, skip the following empty lines too.

Returns
true if there was a line to end.

Definition at line 904 of file remake.cpp.

Referenced by expect_token(), load_rule(), and load_rules().

905 {
906  char c = in.get();
907  if (c == '\r') c = in.get();
908  if (c != '\n' && in.good()) in.putback(c);
909  if (c != '\n' && !in.eof()) return false;
910  if (multi) skip_empty(in);
911  return true;
912 }
static void skip_spaces ( std::istream &  in)
static

Skip spaces.

Definition at line 883 of file remake.cpp.

Referenced by expect_token(), get_function(), and load_rule().

884 {
885  char c;
886  while (strchr(" \t", (c = in.get()))) {}
887  if (in.good()) in.putback(c);
888 }