Remake
Loading...
Searching...
No Matches
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 1055 of file remake.cpp.

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

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

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

Referenced by addprefix_generator::addprefix_generator(), addsuffix_generator::addsuffix_generator(), load_rule(), load_rules(), main(), addprefix_generator::next(), addsuffix_generator::next(), and input_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 1120 of file remake.cpp.

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

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

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

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

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

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

◆ skip_spaces()

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

Skip spaces.

Definition at line 1024 of file remake.cpp.

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

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