summaryrefslogtreecommitdiff
path: root/src/producer.hpp
diff options
context:
space:
mode:
authorAleksey Veresov <aleksey@veresov.pro>2019-11-08 19:49:40 +0300
committerAleksey Veresov <aleksey@veresov.pro>2019-11-08 19:56:11 +0300
commit3047ed6100a56a529f26e43ada0a3fc3c3815c3e (patch)
tree9648d5a74bae9cbd90670a8bfa0af47189e4536f /src/producer.hpp
parentc6419eed96f2832b1de2b94d711552efaa9b172d (diff)
downloadtexo-3047ed6100a56a529f26e43ada0a3fc3c3815c3e.tar
texo-3047ed6100a56a529f26e43ada0a3fc3c3815c3e.tar.xz
texo-3047ed6100a56a529f26e43ada0a3fc3c3815c3e.zip
[texo] Full rewrite of inner representation.
Diffstat (limited to 'src/producer.hpp')
-rw-r--r--src/producer.hpp189
1 files changed, 172 insertions, 17 deletions
diff --git a/src/producer.hpp b/src/producer.hpp
index 62e098d..f55cb91 100644
--- a/src/producer.hpp
+++ b/src/producer.hpp
@@ -1,37 +1,192 @@
#ifndef TEXO_INCLUDED_PRODUCER
#define TEXO_INCLUDED_PRODUCER
-#include "texo.hpp"
#include "exporter.hpp"
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Texo Producer
+ * Texo interface for producing output based on inner representation.
+ */
class TexoProducer {
public:
- TexoProducer(TexoExporter &exporter);
+ TexoProducer(TexoExporter &exporter); // Setup exporter used for output.
- virtual void End();
- virtual void Put(char c);
- virtual void Put(const Texo &piece);
+ virtual bool End(); // Notify producer, what input is ended.
- virtual void Put(const TexoHeader &piece);
- virtual void Put(const TexoParagraph &piece) = 0;
- virtual void Put(const TexoCode &piece);
- virtual void Put(const TexoQuote &piece);
- virtual void Put(const TexoMono &piece);
- virtual void Put(const TexoBold &piece);
- virtual void Put(const TexoItalic &piece);
- virtual void Put(const TexoUnderline &piece);
- virtual void Put(const TexoStrike &piece);
+ virtual bool Put(char c); // Output c, possibly escaping it.
+
+
+ // Block Signal Handlers
+ // Only one can be opened at one moment.
+ virtual bool Code();
+ virtual bool Header(int level);
+ virtual bool Paragraph() = 0;
+ virtual bool Quote();
+
+
+ // Modificator Signal Handlers
+ // Independently switch one of text modificators.
+ virtual bool Bold();
+ virtual bool Italic();
+ virtual bool Mono();
+ virtual bool Strike();
+ virtual bool Underline();
+
+ // Switch link to given or switch it off, if no one is given.
+ virtual bool Link(
+ const ScriptVariable &link,
+ const ScriptVariable &title
+ );
+ virtual bool Link();
+
+
+ virtual bool PutImage(
+ const ScriptVariable &src,
+ const ScriptVariable &alt,
+ const ScriptVariable &title
+ );
+ virtual bool PutHorizontalRule();
- virtual void Put(const TexoImage &piece);
- virtual void Put(const TexoLink &piece);
- virtual void Put(const TexoHorizontalRule &piece);
protected:
TexoExporter &exporter;
};
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Texo Strict Producer
+ * Converts switch-signal interface of Texo Producer into
+ * sequence of start/close signals with disjoint modificator sections,
+ * as well as block sections, which are provided on top level.
+ */
+class TexoProducerStrict: public TexoProducer {
+public:
+ TexoProducerStrict(TexoExporter &exporter);
+
+
+ bool End();
+
+
+ bool Put(char c);
+
+
+ bool Code();
+ bool Header(int level);
+ bool Paragraph();
+ bool Quote();
+
+
+ bool Bold();
+ bool Italic();
+ bool Mono();
+ bool Strike();
+ bool Underline();
+
+ bool Link(const ScriptVariable &path, const ScriptVariable &title);
+ bool Link();
+
+ bool PutImage(
+ const ScriptVariable &src,
+ const ScriptVariable &alt,
+ const ScriptVariable &title
+ );
+ bool PutHorizontalRule();
+
+
+protected:
+ virtual bool TruePut(char c) = 0;
+
+ virtual bool StartCode() = 0;
+ virtual bool StartHeader(int level) = 0;
+ virtual bool StartParagraph() = 0;
+ virtual bool StartQuote() = 0;
+
+ virtual bool CloseCode() = 0;
+ virtual bool CloseHeader(int level) = 0;
+ virtual bool CloseParagraph() = 0;
+ virtual bool CloseQuote() = 0;
+
+
+ virtual bool StartBold() = 0;
+ virtual bool StartItalic() = 0;
+ virtual bool StartMono() = 0;
+ virtual bool StartStrike() = 0;
+ virtual bool StartUnderline() = 0;
+
+ virtual bool CloseBold() = 0;
+ virtual bool CloseItalic() = 0;
+ virtual bool CloseMono() = 0;
+ virtual bool CloseStrike() = 0;
+ virtual bool CloseUnderline() = 0;
+
+ virtual bool StartLink(
+ const ScriptVariable &link,
+ const ScriptVariable &title
+ ) = 0;
+ virtual bool CloseLink(
+ const ScriptVariable &link,
+ const ScriptVariable &title
+ ) = 0;
+
+
+ virtual bool TruePutImage(
+ const ScriptVariable &src,
+ const ScriptVariable &alt,
+ const ScriptVariable &title
+ ) = 0;
+ virtual bool TruePutHorizontalRule() = 0;
+
+
+private:
+ enum Block {
+ block_none = 0,
+ code,
+ header,
+ paragraph,
+ quote
+ } block;
+
+ int header_level;
+
+
+ enum Mod {
+ bold,
+ italic,
+ link,
+ mono,
+ strike,
+ underline
+ } mods[6];
+ int opened;
+
+ const ScriptVariable *link_link;
+ const ScriptVariable *link_title;
+
+
+ bool Start(); // Open paragraph if no block is opened.
+
+ bool CloseBlock();
+
+ bool SwitchMod(Mod mod);
+
+ bool OpenMod(Mod mod);
+
+ bool CloseMod(Mod mod);
+
+ // Close all opened mods sequentially, down to (including) last,
+ // returning count of closed mods, or negative number in case of error.
+ int CloseMods(Mod last);
+
+ // Close all opened mods.
+ bool CloseMods();
+
+ bool Reopen(int closed);
+
+ bool IsOpened(Mod mod) const;
+};
+
+
#endif