Add mechanism for specifying names for source strings.

Expose a new method setStringsWithLengthsAndNames() in the interface
which allows the caller to set descriptive names for source strings.
These names can be used in error messages.
This commit is contained in:
Lei Zhang 2015-07-21 10:23:43 -04:00
parent b9e5424792
commit 1719fb207a
3 changed files with 61 additions and 17 deletions

View file

@ -51,7 +51,7 @@ const int EndOfInput = -1;
//
class TInputScanner {
public:
TInputScanner(int n, const char* const s[], size_t L[], int b = 0, int f = 0) :
TInputScanner(int n, const char* const s[], size_t L[], const char* const* names = nullptr, int b = 0, int f = 0) :
numSources(n),
sources(reinterpret_cast<const unsigned char* const *>(s)), // up to this point, common usage is "char*", but now we need positive 8-bit characters
lengths(L), currentSource(0), currentChar(0), stringBias(b), finale(f)
@ -60,6 +60,10 @@ public:
for (int i = 0; i < numSources; ++i) {
loc[i].init();
}
if (names != nullptr) {
for (int i = 0; i < numSources; ++i)
loc[i].name = names[i];
}
loc[currentSource].string = -stringBias;
loc[currentSource].line = 1;
loc[currentSource].column = 0;