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

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

Definition at line 1057 of file remake.cpp.

1058 {
1059  Unexpected = 0,
1060  Word = 1 << 1,
1061  Colon = 1 << 2,
1062  Equal = 1 << 3,
1063  Dollarpar = 1 << 4,
1064  Rightpar = 1 << 5,
1065  Comma = 1 << 6,
1066  Plusequal = 1 << 7,
1067  Pipe = 1 << 8,
1068 };
@ Plusequal
Definition: remake.cpp:1066
@ Word
Definition: remake.cpp:1060
@ Equal
Definition: remake.cpp:1062
@ Unexpected
Definition: remake.cpp:1059
@ Colon
Definition: remake.cpp:1061
@ Dollarpar
Definition: remake.cpp:1063
@ Pipe
Definition: remake.cpp:1067
@ Comma
Definition: remake.cpp:1065
@ Rightpar
Definition: remake.cpp:1064

Function Documentation

◆ expect_token()

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

1077 {
1078  while (true)
1079  {
1080  skip_spaces(in);
1081  char c = in.peek();
1082  if (!in.good()) return Unexpected;
1083  int tok;
1084  switch (c)
1085  {
1086  case '\r':
1087  case '\n': return Unexpected;
1088  case ':': tok = Colon; break;
1089  case ',': tok = Comma; break;
1090  case '=': tok = Equal; break;
1091  case ')': tok = Rightpar; break;
1092  case '|': tok = Pipe; break;
1093  case '$':
1094  if (!(mask & Dollarpar)) return Unexpected;
1095  in.ignore(1);
1096  tok = Dollarpar;
1097  if (in.peek() != '(') return Unexpected;
1098  break;
1099  case '+':
1100  if (!(mask & Plusequal)) return Unexpected;
1101  in.ignore(1);
1102  tok = Plusequal;
1103  if (in.peek() != '=') return Unexpected;
1104  break;
1105  case '\\':
1106  in.ignore(1);
1107  if (skip_eol(in)) continue;
1108  in.putback('\\');
1109  return mask & Word ? Word : Unexpected;
1110  default:
1111  return mask & Word ? Word : Unexpected;
1112  }
1113  if (!(tok & mask)) return Unexpected;
1114  in.ignore(1);
1115  return tok;
1116  }
1117 }
static bool skip_eol(std::istream &in, bool multi=false)
Definition: remake.cpp:1047
static void skip_spaces(std::istream &in)
Definition: remake.cpp:1026

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

◆ read_word()

static std::string read_word ( std::istream &  in,
bool  detect_equal = true 
)
static

Read a (possibly quoted) word.

Definition at line 1122 of file remake.cpp.

1123 {
1124  int c = in.peek();
1125  std::string res;
1126  if (!in.good()) return res;
1127  char const *separators = " \t\r\n$(),:";
1128  bool quoted = c == '"';
1129  if (quoted) in.ignore(1);
1130  bool plus = false;
1131  while (true)
1132  {
1133  c = in.peek();
1134  if (!in.good()) return res;
1135  if (quoted)
1136  {
1137  in.ignore(1);
1138  if (c == '\\')
1139  res += in.get();
1140  else if (c == '"')
1141  quoted = false;
1142  else
1143  res += c;
1144  continue;
1145  }
1146  if (detect_equal && c == '=')
1147  {
1148  if (plus) in.putback('+');
1149  return res;
1150  }
1151  if (plus)
1152  {
1153  res += '+';
1154  plus = false;
1155  }
1156  if (strchr(separators, c)) return res;
1157  in.ignore(1);
1158  if (detect_equal && c == '+') plus = true;
1159  else res += c;
1160  }
1161 }

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

◆ skip_empty()

static void skip_empty ( std::istream &  in)
static

Skip empty lines.

Definition at line 1036 of file remake.cpp.

1037 {
1038  char c;
1039  while (strchr("\r\n", (c = in.get()))) {}
1040  if (in.good()) in.putback(c);
1041 }

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

◆ skip_eol()

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

1048 {
1049  char c = in.get();
1050  if (c == '\r') c = in.get();
1051  if (c != '\n' && in.good()) in.putback(c);
1052  if (c != '\n' && !in.eof()) return false;
1053  if (multi) skip_empty(in);
1054  return true;
1055 }
static void skip_empty(std::istream &in)
Definition: remake.cpp:1036

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

◆ skip_spaces()

static void skip_spaces ( std::istream &  in)
static

Skip spaces.

Definition at line 1026 of file remake.cpp.

1027 {
1028  char c;
1029  while (strchr(" \t", (c = in.get()))) {}
1030  if (in.good()) in.putback(c);
1031 }

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