summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/formats/osdm/DynamicTokenizer.cpp (renamed from src/plugins/plain/DynamicTokenizer.cpp)0
-rw-r--r--src/formats/osdm/DynamicTokenizer.hpp (renamed from src/plugins/plain/DynamicTokenizer.hpp)0
-rw-r--r--src/formats/osdm/OsdmStreamParser.cpp (renamed from src/plugins/plain/PlainFormatStreamReader.cpp)43
-rw-r--r--src/formats/osdm/OsdmStreamParser.hpp (renamed from src/plugins/plain/PlainFormatStreamReader.hpp)56
-rw-r--r--src/formats/osdm/TokenTrie.cpp (renamed from src/plugins/plain/TokenTrie.cpp)0
-rw-r--r--src/formats/osdm/TokenTrie.hpp (renamed from src/plugins/plain/TokenTrie.hpp)0
6 files changed, 51 insertions, 48 deletions
diff --git a/src/plugins/plain/DynamicTokenizer.cpp b/src/formats/osdm/DynamicTokenizer.cpp
index f2cfcd1..f2cfcd1 100644
--- a/src/plugins/plain/DynamicTokenizer.cpp
+++ b/src/formats/osdm/DynamicTokenizer.cpp
diff --git a/src/plugins/plain/DynamicTokenizer.hpp b/src/formats/osdm/DynamicTokenizer.hpp
index 0cac2e8..0cac2e8 100644
--- a/src/plugins/plain/DynamicTokenizer.hpp
+++ b/src/formats/osdm/DynamicTokenizer.hpp
diff --git a/src/plugins/plain/PlainFormatStreamReader.cpp b/src/formats/osdm/OsdmStreamParser.cpp
index 05769f0..8cb8caf 100644
--- a/src/plugins/plain/PlainFormatStreamReader.cpp
+++ b/src/formats/osdm/OsdmStreamParser.cpp
@@ -21,7 +21,7 @@
#include <core/common/Utils.hpp>
#include <core/common/VariantReader.hpp>
-#include "PlainFormatStreamReader.hpp"
+#include "OsdmStreamParser.hpp"
namespace ousia {
@@ -160,15 +160,14 @@ public:
}
};
-PlainFormatStreamReader::PlainFormatStreamReader(CharReader &reader,
- Logger &logger)
+OsdmStreamParser::OsdmStreamParser(CharReader &reader, Logger &logger)
: reader(reader), logger(logger), tokenizer(Tokens)
{
// Place an intial command representing the complete file on the stack
commands.push(Command{"", Variant::mapType{}, true, true, true});
}
-Variant PlainFormatStreamReader::parseIdentifier(size_t start, bool allowNSSep)
+Variant OsdmStreamParser::parseIdentifier(size_t start, bool allowNSSep)
{
bool first = true;
bool hasCharSiceNSSep = false;
@@ -180,12 +179,14 @@ Variant PlainFormatStreamReader::parseIdentifier(size_t start, bool allowNSSep)
if ((first && Utils::isIdentifierStartCharacter(c)) ||
(!first && Utils::isIdentifierCharacter(c))) {
identifier.push_back(c);
- } else if (c == ':' && hasCharSiceNSSep && reader.fetchPeek(c2) && Utils::isIdentifierStartCharacter(c2)) {
+ } else if (c == ':' && hasCharSiceNSSep && reader.fetchPeek(c2) &&
+ Utils::isIdentifierStartCharacter(c2)) {
identifier.push_back(c);
} else {
if (c == ':' && allowNSSep) {
logger.error(
- "Expected character before and after namespace separator \":\"",
+ "Expected character before and after namespace separator "
+ "\":\"",
reader);
}
reader.resetPeek();
@@ -209,7 +210,7 @@ Variant PlainFormatStreamReader::parseIdentifier(size_t start, bool allowNSSep)
return res;
}
-PlainFormatStreamReader::State PlainFormatStreamReader::parseBeginCommand()
+OsdmStreamParser::State OsdmStreamParser::parseBeginCommand()
{
// Expect a '{' after the command
reader.consumeWhitespace();
@@ -250,7 +251,7 @@ PlainFormatStreamReader::State PlainFormatStreamReader::parseBeginCommand()
return State::COMMAND;
}
-static bool checkStillInField(const PlainFormatStreamReader::Command &cmd,
+static bool checkStillInField(const OsdmStreamParser::Command &cmd,
const Variant &endName, Logger &logger)
{
if (cmd.inField && !cmd.inRangeField) {
@@ -263,7 +264,7 @@ static bool checkStillInField(const PlainFormatStreamReader::Command &cmd,
return false;
}
-PlainFormatStreamReader::State PlainFormatStreamReader::parseEndCommand()
+OsdmStreamParser::State OsdmStreamParser::parseEndCommand()
{
// Expect a '{' after the command
if (!reader.expect('{')) {
@@ -326,7 +327,7 @@ PlainFormatStreamReader::State PlainFormatStreamReader::parseEndCommand()
return cmd.inRangeField ? State::FIELD_END : State::NONE;
}
-Variant PlainFormatStreamReader::parseCommandArguments(Variant commandArgName)
+Variant OsdmStreamParser::parseCommandArguments(Variant commandArgName)
{
// Parse the arguments using the universal VariantReader
Variant commandArguments;
@@ -352,9 +353,8 @@ Variant PlainFormatStreamReader::parseCommandArguments(Variant commandArgName)
return commandArguments;
}
-void PlainFormatStreamReader::pushCommand(Variant commandName,
- Variant commandArguments,
- bool hasRange)
+void OsdmStreamParser::pushCommand(Variant commandName,
+ Variant commandArguments, bool hasRange)
{
// Store the location on the stack
location = commandName.getLocation();
@@ -368,8 +368,7 @@ void PlainFormatStreamReader::pushCommand(Variant commandName,
hasRange, false, false});
}
-PlainFormatStreamReader::State PlainFormatStreamReader::parseCommand(
- size_t start)
+OsdmStreamParser::State OsdmStreamParser::parseCommand(size_t start)
{
// Parse the commandName as a first identifier
Variant commandName = parseIdentifier(start, true);
@@ -417,7 +416,7 @@ PlainFormatStreamReader::State PlainFormatStreamReader::parseCommand(
return State::COMMAND;
}
-void PlainFormatStreamReader::parseBlockComment()
+void OsdmStreamParser::parseBlockComment()
{
DynamicToken token;
size_t depth = 1;
@@ -437,7 +436,7 @@ void PlainFormatStreamReader::parseBlockComment()
logger.error("File ended while being in a block comment", reader);
}
-void PlainFormatStreamReader::parseLineComment()
+void OsdmStreamParser::parseLineComment()
{
char c;
while (reader.read(c)) {
@@ -447,7 +446,7 @@ void PlainFormatStreamReader::parseLineComment()
}
}
-bool PlainFormatStreamReader::checkIssueData(DataHandler &handler)
+bool OsdmStreamParser::checkIssueData(DataHandler &handler)
{
if (!handler.isEmpty()) {
data = handler.toVariant(reader.getSourceId());
@@ -458,7 +457,7 @@ bool PlainFormatStreamReader::checkIssueData(DataHandler &handler)
return false;
}
-bool PlainFormatStreamReader::checkIssueFieldStart()
+bool OsdmStreamParser::checkIssueFieldStart()
{
// Fetch the current command, and check whether we're currently inside a
// field of this command
@@ -483,7 +482,7 @@ bool PlainFormatStreamReader::checkIssueFieldStart()
return false;
}
-PlainFormatStreamReader::State PlainFormatStreamReader::parse()
+OsdmStreamParser::State OsdmStreamParser::parse()
{
// Handler for incomming data
DataHandler handler;
@@ -628,12 +627,12 @@ PlainFormatStreamReader::State PlainFormatStreamReader::parse()
return State::END;
}
-const Variant &PlainFormatStreamReader::getCommandName()
+const Variant &OsdmStreamParser::getCommandName()
{
return commands.top().name;
}
-const Variant &PlainFormatStreamReader::getCommandArguments()
+const Variant &OsdmStreamParser::getCommandArguments()
{
return commands.top().arguments;
}
diff --git a/src/plugins/plain/PlainFormatStreamReader.hpp b/src/formats/osdm/OsdmStreamParser.hpp
index 2ee261c..48d8fb7 100644
--- a/src/plugins/plain/PlainFormatStreamReader.hpp
+++ b/src/formats/osdm/OsdmStreamParser.hpp
@@ -17,17 +17,17 @@
*/
/**
- * @file PlainFormatStreamReader.hpp
+ * @file OsdmStreamParser.hpp
*
- * Provides classes for low-level classes for reading the plain TeX-esque
- * format. The class provided here do not build any model objects and does not
- * implement the Parser interfaces.
+ * Provides classes for low-level classes for reading the TeX-esque osdm
+ * format. The class provided here does not build any model objects and does not
+ * implement the Parser interface.
*
* @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de)
*/
-#ifndef _OUSIA_PLAIN_FORMAT_STREAM_READER_HPP_
-#define _OUSIA_PLAIN_FORMAT_STREAM_READER_HPP_
+#ifndef _OUSIA_OSDM_STREAM_PARSER_HPP_
+#define _OUSIA_OSDM_STREAM_PARSER_HPP_
#include <stack>
@@ -43,17 +43,20 @@ class Logger;
class DataHandler;
/**
- * The PlainFormatStreamReader class provides a low-level reader for the plain
- * TeX-esque format. The parser is constructed around a "parse" function, which
- * reads data from the underlying CharReader until a new state is reached and
- * indicates this state in a return value. The calling code then has to pull
- * corresponding data from the stream reader. The reader already handles some
- * invalid cases, but recovers from most errors and happily continues parsing.
+ * The OsdmStreamParser class provides a low-level reader for the TeX-esque osdm
+ * format. The parser is constructed around a "parse" function, which reads data
+ * from the underlying CharReader until a new state is reached and indicates
+ * this state in a return value. The calling code then has to pull corresponding
+ * data from the stream reader. The reader makes sure the incommind file is
+ * syntactically valid and tries to recorver from most errors. If an error is
+ * irrecoverable (this is the case for errors with wrong nesting of commands or
+ * fields, as this would lead to too many consecutive errors) a
+ * LoggableException is thrown.
*/
-class PlainFormatStreamReader {
+class OsdmStreamParser {
public:
/**
- * Enum used to indicate which state the PlainFormatStreamReader class is in
+ * Enum used to indicate which state the OsdmStreamParser class is in
* after calling the "parse" function.
*/
enum class State {
@@ -110,13 +113,13 @@ public:
END,
/**
- * Returned from internal functions if nothing should be done.
- */
+ * Returned from internal functions if nothing should be done.
+ */
NONE,
/**
- * Returned from internal function to indicate irrecoverable errors.
- */
+ * Returned from internal function to indicate irrecoverable errors.
+ */
ERROR
};
@@ -169,8 +172,8 @@ public:
* @param inRangeField is set to true if we currently inside the outer
* field of the command.
*/
- Command(Variant name, Variant arguments, bool hasRange,
- bool inField, bool inRangeField)
+ Command(Variant name, Variant arguments, bool hasRange, bool inField,
+ bool inRangeField)
: name(std::move(name)),
arguments(std::move(arguments)),
hasRange(hasRange),
@@ -242,7 +245,8 @@ private:
/**
* Pushes the parsed command onto the command stack.
*/
- void pushCommand(Variant commandName, Variant commandArguments, bool hasRange);
+ void pushCommand(Variant commandName, Variant commandArguments,
+ bool hasRange);
/**
* Parses the command arguments.
@@ -288,14 +292,14 @@ private:
public:
/**
- * Constructor of the PlainFormatStreamReader class. Attaches the new
- * PlainFormatStreamReader to the given CharReader and Logger instances.
+ * Constructor of the OsdmStreamParser class. Attaches the new
+ * OsdmStreamParser to the given CharReader and Logger instances.
*
* @param reader is the reader instance from which incomming characters
* should be read.
* @param logger is the logger instance to which errors should be written.
*/
- PlainFormatStreamReader(CharReader &reader, Logger &logger);
+ OsdmStreamParser(CharReader &reader, Logger &logger);
/**
* Continues parsing. Returns one of the states defined in the State enum.
@@ -339,9 +343,9 @@ public:
*
* @return the last internal token location.
*/
- SourceLocation &getLocation() {return location;}
+ SourceLocation &getLocation() { return location; }
};
}
-#endif /* _OUSIA_PLAIN_FORMAT_STREAM_READER_HPP_ */
+#endif /* _OUSIA_OSDM_STREAM_PARSER_HPP_ */
diff --git a/src/plugins/plain/TokenTrie.cpp b/src/formats/osdm/TokenTrie.cpp
index 4a0430b..4a0430b 100644
--- a/src/plugins/plain/TokenTrie.cpp
+++ b/src/formats/osdm/TokenTrie.cpp
diff --git a/src/plugins/plain/TokenTrie.hpp b/src/formats/osdm/TokenTrie.hpp
index 36c2ffa..36c2ffa 100644
--- a/src/plugins/plain/TokenTrie.hpp
+++ b/src/formats/osdm/TokenTrie.hpp