initial commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "sedpp/Command.h"
|
||||
#include "sedpp/Options.h"
|
||||
|
||||
namespace sedpp {
|
||||
|
||||
// Converts raw -e/-f script text into a flat Program. The compiler is deliberately
|
||||
// syntax-oriented; command range state and "last regex" behavior are resolved by
|
||||
// Runner because they depend on input cycles.
|
||||
class Compiler {
|
||||
public:
|
||||
explicit Compiler(const Options &options);
|
||||
|
||||
[[nodiscard]] Program compile(const std::vector<std::string> &scripts);
|
||||
[[nodiscard]] const std::unordered_map<std::string, std::size_t> &labels() const {
|
||||
return labels_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Script parsing is a small cursor parser because sed syntax is compact and
|
||||
// delimiter-driven; tokenizing first tends to lose useful byte positions.
|
||||
void compileOne(const std::string &script);
|
||||
[[nodiscard]] std::optional<Address> parseAddress(const std::string &script,
|
||||
std::size_t &pos,
|
||||
bool secondAddress);
|
||||
[[nodiscard]] std::string parseDelimited(const std::string &script,
|
||||
std::size_t &pos, char delimiter,
|
||||
bool regexMode = false,
|
||||
bool unescapeDelimiter = false);
|
||||
[[nodiscard]] std::string readUntilCommandEnd(const std::string &script,
|
||||
std::size_t &pos);
|
||||
static void skipBlanks(const std::string &script, std::size_t &pos);
|
||||
static void skipSeparators(const std::string &script, std::size_t &pos);
|
||||
|
||||
const Options &options_;
|
||||
Program program_;
|
||||
std::unordered_map<std::string, std::size_t> labels_;
|
||||
};
|
||||
|
||||
} // namespace sedpp
|
||||
Reference in New Issue
Block a user