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 915 of file remake.cpp.

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

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 933 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().

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

Read a (possibly quoted) word.

Definition at line 978 of file remake.cpp.

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

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

Skip empty lines.

Definition at line 894 of file remake.cpp.

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

895 {
896  char c;
897  while (strchr("\r\n", (c = in.get()))) {}
898  if (in.good()) in.putback(c);
899 }
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 905 of file remake.cpp.

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

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

Skip spaces.

Definition at line 884 of file remake.cpp.

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

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