Kaynağa Gözat

prepend operator

feature/dependency-graph
Martin Dørum 5 yıl önce
ebeveyn
işleme
c7b7e30900
4 değiştirilmiş dosya ile 24 ekleme ve 4 silme
  1. 1
    1
      Makefile
  2. 2
    1
      sample.bbb
  3. 19
    1
      src/BBBParser.cc
  4. 2
    1
      src/BBBParser.h

+ 1
- 1
Makefile Dosyayı Görüntüle

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


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

+ 2
- 1
sample.bbb Dosyayı Görüntüle

$other_files $other_files


cflags :=-g -O3 -DTITLE="Hello World" 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 Dosyayı Görüntüle

skip(); // '+' skip(); // '+'
skip(); // '=' skip(); // '='
return Operator::PLUS_EQUALS; return Operator::PLUS_EQUALS;
} else if (peek() == '=' && ch2 == '+') {
skip(); // '='
skip(); // '+'
return Operator::EQUALS_PLUS;
} }


return Operator::NONE; return Operator::NONE;
} }
} }


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


vars[key] = std::move(values); vars[key] = std::move(values);
values.clear(); values.clear();
break; break;

case Operator::PLUS_EQUALS: case Operator::PLUS_EQUALS:
{ {
auto &vec = vars[key]; auto &vec = vars[key];
} }
values.clear(); values.clear();
break; 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: case Operator::NONE:
break; break;
} }

+ 2
- 1
src/BBBParser.h Dosyayı Görüntüle

enum class Operator { enum class Operator {
COLON_EQUALS, COLON_EQUALS,
PLUS_EQUALS, PLUS_EQUALS,
EQUALS_PLUS,
NONE, NONE,
}; };


Operator readOperator(); Operator readOperator();
void skip(char); void skip(char);
void skip() { get(); } void skip() { get(); }
void error(std::string);
[[noreturn]] void error(std::string);


void skipWhitespaceLine(); void skipWhitespaceLine();
void skipWhitespace(); void skipWhitespace();

Loading…
İptal
Kaydet