Browse Source

prepend operator

feature/dependency-graph
Martin Dørum 3 years ago
parent
commit
c7b7e30900
4 changed files with 24 additions and 4 deletions
  1. 1
    1
      Makefile
  2. 2
    1
      sample.bbb
  3. 19
    1
      src/BBBParser.cc
  4. 2
    1
      src/BBBParser.h

+ 1
- 1
Makefile View File

@@ -2,7 +2,7 @@ SRCS = src/BBBParser.cc src/SourceFile.cc src/main.cc
HDRS = src/BBBParser.h src/SourceFile.h
BUILD = build
OBJS = $(patsubst %,$(BUILD)/%.o,$(SRCS))
CFLAGS = -g
CFLAGS = -g -Wall -Wextra -Wno-unused-parameter

$(BUILD)/%.cc.o: %.cc $(HDRS)
@mkdir -p $(@D)

+ 2
- 1
sample.bbb View File

@@ -10,4 +10,5 @@ files:=
$other_files

cflags :=-g -O3 -DTITLE="Hello World"
cflags += HELLO nope
cflags += these values will be appended
cflags =+ these values will be prepended

+ 19
- 1
src/BBBParser.cc View File

@@ -27,6 +27,10 @@ BBBParser::Operator BBBParser::readOperator() {
skip(); // '+'
skip(); // '='
return Operator::PLUS_EQUALS;
} else if (peek() == '=' && ch2 == '+') {
skip(); // '='
skip(); // '+'
return Operator::EQUALS_PLUS;
}

return Operator::NONE;
@@ -41,7 +45,7 @@ void BBBParser::skip(char expected) {
}
}

void BBBParser::error(std::string msg) {
[[noreturn]] void BBBParser::error(std::string msg) {
throw BBBParseError(std::to_string(line_) + ":" + std::to_string(ch_) + ": " + msg);
}

@@ -277,6 +281,7 @@ void BBBParser::parse(Variables &vars) {
vars[key] = std::move(values);
values.clear();
break;

case Operator::PLUS_EQUALS:
{
auto &vec = vars[key];
@@ -287,6 +292,19 @@ void BBBParser::parse(Variables &vars) {
}
values.clear();
break;

case Operator::EQUALS_PLUS:
{
auto &vec = vars[key];
vec.reserve(vec.size() + values.size());
for (size_t i = 0; i < vec.size(); ++i) {
values.push_back(std::move(vec[i]));
}
vec = std::move(values);
}
values.clear();
break;

case Operator::NONE:
break;
}

+ 2
- 1
src/BBBParser.h View File

@@ -36,6 +36,7 @@ private:
enum class Operator {
COLON_EQUALS,
PLUS_EQUALS,
EQUALS_PLUS,
NONE,
};

@@ -45,7 +46,7 @@ private:
Operator readOperator();
void skip(char);
void skip() { get(); }
void error(std::string);
[[noreturn]] void error(std::string);

void skipWhitespaceLine();
void skipWhitespace();

Loading…
Cancel
Save