Spicy
preprocessor.h
1 // Copyright (c) 2020-2021 by the Zeek Project. See LICENSE for details.
2 
3 #pragma once
4 
5 #include <map>
6 #include <string>
7 #include <utility>
8 #include <vector>
9 
10 #include <hilti/base/result.h>
11 
12 namespace hilti::util {
24 public:
25  using ID = std::string; //< type for identifiers
26  using Value = int; //< type associated with integers (may expand this to a variant in the future)
27 
29  enum class State {
30  Include, //< include line
31  Skip //< skip line
32  };
33 
39  SourceCodePreprocessor(std::map<ID, Value> constants) : _constants(std::move(std::move(constants))) {}
40 
50  Result<State> processLine(std::string_view directive, std::string_view expression = "");
51 
53  State state() const { return _stack.back() == 1 ? State::Include : State::Skip; }
54 
59  bool expectingDirective() { return _stack.size() > 1; }
60 
61 private:
62  Result<bool> _parseIf(const std::string_view& expression);
63 
64  std::map<ID, Value> _constants;
65  std::vector<int> _stack = {1};
66 };
67 
68 } // namespace hilti::util
Definition: cache.h:11
Definition: optional.h:79
Definition: preprocessor.h:23
bool expectingDirective()
Definition: preprocessor.h:59
State state() const
Definition: preprocessor.h:53
State
Definition: preprocessor.h:29
SourceCodePreprocessor(std::map< ID, Value > constants)
Definition: preprocessor.h:39
Definition: result.h:67
Result< State > processLine(std::string_view directive, std::string_view expression="")
Definition: preprocessor.cc:10