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 <vector>
8 
9 #include <hilti/base/result.h>
10 
11 namespace hilti::util {
23 public:
24  using ID = std::string; //< type for identifiers
25  using Value = int; //< type associated with integers (may expand this to a variant in the future)
26 
28  enum class State {
29  Include, //< include line
30  Skip //< skip line
31  };
32 
38  SourceCodePreprocessor(std::map<ID, Value> constants) : _constants(constants) {}
39 
49  Result<State> processLine(std::string_view directive, std::string_view expression = "");
50 
52  State state() const { return _stack.back() == 1 ? State::Include : State::Skip; }
53 
58  bool expectingDirective() { return _stack.size() > 1; }
59 
60 private:
61  Result<bool> _parseIf(const std::string_view& expression);
62 
63  std::map<ID, Value> _constants;
64  std::vector<int> _stack = {1};
65 };
66 
67 } // namespace hilti::util
Definition: cache.h:11
Definition: preprocessor.h:22
bool expectingDirective()
Definition: preprocessor.h:58
State state() const
Definition: preprocessor.h:52
State
Definition: preprocessor.h:28
SourceCodePreprocessor(std::map< ID, Value > constants)
Definition: preprocessor.h:38
Definition: result.h:67
Result< State > processLine(std::string_view directive, std::string_view expression="")
Definition: preprocessor.cc:10