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,
  Pipe = 1 << 8
}
 

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, bool detect_equal=true)
 

Detailed Description

Enumeration Type Documentation

anonymous enum
Enumerator
Unexpected 
Word 
Colon 
Equal 
Dollarpar 
Rightpar 
Comma 
Plusequal 
Pipe 

Definition at line 1033 of file remake.cpp.

1034 {
1035  Unexpected = 0,
1036  Word = 1 << 1,
1037  Colon = 1 << 2,
1038  Equal = 1 << 3,
1039  Dollarpar = 1 << 4,
1040  Rightpar = 1 << 5,
1041  Comma = 1 << 6,
1042  Plusequal = 1 << 7,
1043  Pipe = 1 << 8,
1044 };

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

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

1053 {
1054  while (true)
1055  {
1056  skip_spaces(in);
1057  char c = in.peek();
1058  if (!in.good()) return Unexpected;
1059  int tok;
1060  switch (c)
1061  {
1062  case '\r':
1063  case '\n': return Unexpected;
1064  case ':': tok = Colon; break;
1065  case ',': tok = Comma; break;
1066  case '=': tok = Equal; break;
1067  case ')': tok = Rightpar; break;
1068  case '|': tok = Pipe; break;
1069  case '$':
1070  if (!(mask & Dollarpar)) return Unexpected;
1071  in.ignore(1);
1072  tok = Dollarpar;
1073  if (in.peek() != '(') return Unexpected;
1074  break;
1075  case '+':
1076  if (!(mask & Plusequal)) return Unexpected;
1077  in.ignore(1);
1078  tok = Plusequal;
1079  if (in.peek() != '=') return Unexpected;
1080  break;
1081  case '\\':
1082  in.ignore(1);
1083  if (skip_eol(in)) continue;
1084  in.putback('\\');
1085  return mask & Word ? Word : Unexpected;
1086  default:
1087  return mask & Word ? Word : Unexpected;
1088  }
1089  if (!(tok & mask)) return Unexpected;
1090  in.ignore(1);
1091  return tok;
1092  }
1093 }
static std::string read_word ( std::istream &  in,
bool  detect_equal = true 
)
static

Read a (possibly quoted) word.

Definition at line 1098 of file remake.cpp.

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

1099 {
1100  int c = in.peek();
1101  std::string res;
1102  if (!in.good()) return res;
1103  char const *separators = " \t\r\n$(),:";
1104  bool quoted = c == '"';
1105  if (quoted) in.ignore(1);
1106  bool plus = false;
1107  while (true)
1108  {
1109  c = in.peek();
1110  if (!in.good()) return res;
1111  if (quoted)
1112  {
1113  in.ignore(1);
1114  if (c == '\\')
1115  res += in.get();
1116  else if (c == '"')
1117  quoted = false;
1118  else
1119  res += c;
1120  continue;
1121  }
1122  if (detect_equal && c == '=')
1123  {
1124  if (plus) in.putback('+');
1125  return res;
1126  }
1127  if (plus)
1128  {
1129  res += '+';
1130  plus = false;
1131  }
1132  if (strchr(separators, c)) return res;
1133  in.ignore(1);
1134  if (detect_equal && c == '+') plus = true;
1135  else res += c;
1136  }
1137 }
static void skip_empty ( std::istream &  in)
static

Skip empty lines.

Definition at line 1012 of file remake.cpp.

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

1013 {
1014  char c;
1015  while (strchr("\r\n", (c = in.get()))) {}
1016  if (in.good()) in.putback(c);
1017 }
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 1023 of file remake.cpp.

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

1024 {
1025  char c = in.get();
1026  if (c == '\r') c = in.get();
1027  if (c != '\n' && in.good()) in.putback(c);
1028  if (c != '\n' && !in.eof()) return false;
1029  if (multi) skip_empty(in);
1030  return true;
1031 }
static void skip_spaces ( std::istream &  in)
static

Skip spaces.

Definition at line 1002 of file remake.cpp.

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

1003 {
1004  char c;
1005  while (strchr(" \t", (c = in.get()))) {}
1006  if (in.good()) in.putback(c);
1007 }