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

1041 {
1042  Unexpected = 0,
1043  Word = 1 << 1,
1044  Colon = 1 << 2,
1045  Equal = 1 << 3,
1046  Dollarpar = 1 << 4,
1047  Rightpar = 1 << 5,
1048  Comma = 1 << 6,
1049  Plusequal = 1 << 7,
1050  Pipe = 1 << 8,
1051 };

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

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

Read a (possibly quoted) word.

Definition at line 1105 of file remake.cpp.

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

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

Skip empty lines.

Definition at line 1019 of file remake.cpp.

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

1020 {
1021  char c;
1022  while (strchr("\r\n", (c = in.get()))) {}
1023  if (in.good()) in.putback(c);
1024 }
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 1030 of file remake.cpp.

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

1031 {
1032  char c = in.get();
1033  if (c == '\r') c = in.get();
1034  if (c != '\n' && in.good()) in.putback(c);
1035  if (c != '\n' && !in.eof()) return false;
1036  if (multi) skip_empty(in);
1037  return true;
1038 }
static void skip_empty(std::istream &in)
Definition: remake.cpp:1019
static void skip_spaces ( std::istream &  in)
static

Skip spaces.

Definition at line 1009 of file remake.cpp.

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

1010 {
1011  char c;
1012  while (strchr(" \t", (c = in.get()))) {}
1013  if (in.good()) in.putback(c);
1014 }