summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/common/CharReader.cpp33
-rw-r--r--src/core/common/CharReader.hpp35
2 files changed, 52 insertions, 16 deletions
diff --git a/src/core/common/CharReader.cpp b/src/core/common/CharReader.cpp
index b0bbade..6fd3d45 100644
--- a/src/core/common/CharReader.cpp
+++ b/src/core/common/CharReader.cpp
@@ -405,10 +405,10 @@ CharReader::~CharReader()
buffer->deleteCursor(peekCursor);
}
-bool CharReader::readAtCursor(Cursor &cursor, char &c)
+bool CharReader::readAtCursor(Buffer::CursorId &cursor, char &c)
{
// Return false if we're at the end of the stream
- if (!buffer->read(cursor.cursor, c)) {
+ if (!buffer->read(cursor, c)) {
return false;
}
@@ -420,9 +420,9 @@ bool CharReader::readAtCursor(Cursor &cursor, char &c)
// Check whether the next character is a continuation of the
// current character
char c2;
- if (buffer->read(cursor.cursor, c2)) {
+ if (buffer->read(cursor, c2)) {
if ((c2 != '\n' && c2 != '\r') || c2 == c) {
- buffer->moveCursor(cursor.cursor, -1);
+ buffer->moveCursor(cursor, -1);
}
}
}
@@ -486,8 +486,8 @@ bool CharReader::consumeWhitespace()
CharReaderFork CharReader::fork()
{
- return CharReaderFork(buffer, readCursor, peekCursor, sourceId, offs,
- coherent);
+ return CharReaderFork{buffer, readCursor, peekCursor,
+ sourceId, offs, coherent};
}
size_t CharReader::readRaw(char *buf, size_t size)
@@ -502,11 +502,16 @@ size_t CharReader::readRaw(char *buf, size_t size)
return res;
}
-bool CharReader::atEnd() const { return buffer->atEnd(readCursor.cursor); }
+bool CharReader::atEnd() const { return buffer->atEnd(readCursor); }
-size_t CharReader::getOffset() const
+SourceOffset CharReader::getOffset() const
{
- return buffer->offset(readCursor.cursor) + offs;
+ return buffer->offset(readCursor) + offs;
+}
+
+SourcePosition CharReader::getPosition() const
+{
+ return getOffset();
}
SourceLocation CharReader::getLocation() const
@@ -514,13 +519,19 @@ SourceLocation CharReader::getLocation() const
return SourceLocation{sourceId, getOffset()};
}
+SourceLocation CharReader::getLocation(SourcePosition start) const
+{
+ return SourceLocation{sourceId, start, getOffset()};
+}
+
+SourceId CharReader::getSourceId() const { return sourceId; }
+
/* Class CharReaderFork */
CharReaderFork::CharReaderFork(std::shared_ptr<Buffer> buffer,
Buffer::CursorId parentReadCursor,
Buffer::CursorId parentPeekCursor,
- SourceContextCallback sourceId, size_t offs,
- bool coherent)
+ SourceId sourceId, size_t offs, bool coherent)
: CharReader(buffer, sourceId, offs),
parentReadCursor(parentReadCursor),
parentPeekCursor(parentPeekCursor)
diff --git a/src/core/common/CharReader.hpp b/src/core/common/CharReader.hpp
index 0957e97..5a4d906 100644
--- a/src/core/common/CharReader.hpp
+++ b/src/core/common/CharReader.hpp
@@ -367,7 +367,7 @@ private:
* @param c a reference to the character that should be written.
* @return true if another character needs to be read.
*/
- bool substituteLinebreaks(Cursor &cursor, char &c);
+ bool substituteLinebreaks(Buffer::CursorId &cursor, char &c);
/**
* Reads a single character from the given cursor.
@@ -534,7 +534,14 @@ public:
*
* @return the offset of the read cursor in bytes.
*/
- size_t getOffset() const;
+ SourceOffset getOffset() const;
+
+ /**
+ * Returns the offset of the read cursor in bytes.
+ *
+ * @return the offset of the read cursor in bytes.
+ */
+ SourcePosition getPosition() const;
/**
* Returns a SourceLocation object describing the exact position (including
@@ -544,6 +551,24 @@ public:
* cursor.
*/
SourceLocation getLocation() const;
+
+ /**
+ * Returns a SourceLocation object starting at the given start position and
+ * ending at the exact position (including the source file) of the read
+ * cursor.
+ *
+ * @return a SourceLocation object at the position of the current read
+ * cursor.
+ */
+ SourceLocation getLocation(SourcePosition start) const;
+
+ /**
+ * Returns the current SourceId which describes the Resource on which the
+ * CharReader is currently working.
+ *
+ * @return the current SourceId.
+ */
+ SourceId getSourceId() const;
};
/**
@@ -577,9 +602,9 @@ private:
* coherently.
*/
CharReaderFork(std::shared_ptr<Buffer> buffer,
- Buffer::CursorId &parentReadCursor,
- Buffer::CursorId &parentPeekCursor,
- SourceContextCallback sourceId, size_t offs, bool coherent);
+ Buffer::CursorId parentReadCursor,
+ Buffer::CursorId parentPeekCursor, SourceId sourceId,
+ size_t offs, bool coherent);
public:
/**