#pragma once #include #include #include #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 &scripts); [[nodiscard]] const std::unordered_map &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
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 labels_; }; } // namespace sedpp