diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-28 15:48:38 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-28 15:48:38 +0100 |
commit | fa2a5bdf0152002de520fcc72e48686b9e2657b1 (patch) | |
tree | 9b3c49103194c4ca1401b1a305b7bf129405503e /src | |
parent | b54760fbd5470032dc716dc870dc08b32dfba5ac (diff) |
Adapted all unit tests, renamed COMMAND_END event to RANGE_END event to match ranged annotations
Diffstat (limited to 'src')
-rw-r--r-- | src/formats/osml/OsmlStreamParser.cpp | 28 | ||||
-rw-r--r-- | src/formats/osml/OsmlStreamParser.hpp | 11 |
2 files changed, 23 insertions, 16 deletions
diff --git a/src/formats/osml/OsmlStreamParser.cpp b/src/formats/osml/OsmlStreamParser.cpp index 7e01a3c..e467dc5 100644 --- a/src/formats/osml/OsmlStreamParser.cpp +++ b/src/formats/osml/OsmlStreamParser.cpp @@ -127,7 +127,7 @@ private: /** * Set to true if this is a command with clear begin and end. */ - bool hasRange; + bool hasRange: 1; public: /** @@ -259,7 +259,7 @@ public: */ enum class State : uint8_t { COMMAND_START = 0, - COMMAND_END = 1, + RANGE_END = 1, FIELD_START = 2, FIELD_END = 3, ANNOTATION_START = 4, @@ -328,7 +328,7 @@ private: * * @return an internal State specifying whether an error occured (return * values State::REOVERABLE_ERROR or State::IRRECOVERABLE_ERROR) or a - * command was actually ended (return value State::COMMAND_END). + * command was actually ended (return value State::RANGE_END). */ State parseEndCommand(); @@ -569,7 +569,7 @@ OsmlStreamParserImpl::State OsmlStreamParserImpl::parseEndCommand() // End the current command location = name.getLocation(); commands.pop(); - return State::COMMAND_END; + return State::RANGE_END; } Variant OsmlStreamParserImpl::parseCommandArguments(Variant commandArgName) @@ -808,14 +808,15 @@ OsmlStreamParserImpl::State OsmlStreamParserImpl::parse() // If this was an annotation start token, add the parsed < to the // output + SourceOffset charStart = token.location.getStart(); + SourceOffset charEnd = reader.getPeekOffset(); if (type == OsmlTokens.AnnotationStart) { - data.append('<', token.location.getStart(), - token.location.getStart() + 1); + data.append('<', charStart, charStart + 1); + charStart = charStart + 1; } // Append the character to the output data, mark it as protected - data.append(c, token.location.getStart(), reader.getPeekOffset(), - true); + data.append(c, charStart, charEnd, true); reader.consumePeek(); continue; } else if (type == Tokens::Data) { @@ -880,11 +881,12 @@ OsmlStreamParserImpl::State OsmlStreamParserImpl::parse() // Make sure all open commands and fields have been ended at the end of the // stream - while (commands.size() > 1) { + while (true) { + bool topLevelCommand = commands.size() == 1U; if (cmd().inField()) { // If the stream ended with an open range field, issue information // about the range field - if (cmd().inRangeField()) { + if (cmd().inRangeField() && !topLevelCommand) { // Inform about the still open command itself logger.error("Reached end of stream, but command \"" + getCommandName().asString() + @@ -901,7 +903,11 @@ OsmlStreamParserImpl::State OsmlStreamParserImpl::parse() } } } - commands.pop(); + if (!topLevelCommand) { + commands.pop(); + } else { + break; + } } location = SourceLocation{reader.getSourceId(), reader.getOffset()}; diff --git a/src/formats/osml/OsmlStreamParser.hpp b/src/formats/osml/OsmlStreamParser.hpp index 1fee90b..10d5296 100644 --- a/src/formats/osml/OsmlStreamParser.hpp +++ b/src/formats/osml/OsmlStreamParser.hpp @@ -69,11 +69,11 @@ public: COMMAND_START = 0, /** - * State returned if a range command has just ended. This state is not - * returned for non-range commands (as the actual end of a command is - * context dependant). + * State returned if a range command or range annotation has just ended. + * This state is not returned for non-range commands (as the actual end + * of a command is context dependent). */ - COMMAND_END = 1, + RANGE_END = 1, /** * State returned if a new field started. The reader assures that the @@ -185,7 +185,8 @@ public: /** * Returns true if the currently started command is a range command, only - * valid if State::COMMAND_START was returned by the "parse" function. + * valid if State::COMMAND_START or State::ANNOTATION_START was returned by + * the "parse" function. * * @return true if the command is started is a range command, false * otherwise. |