Start of new ANTLR4 based parser.
Very simple tests pass.
This commit is contained in:
parent
03b4194193
commit
fbbe832a05
44 changed files with 860 additions and 8 deletions
83
pglablib/CaseChangingCharStream.h
Normal file
83
pglablib/CaseChangingCharStream.h
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#pragma once
|
||||
|
||||
#include "antlr4-runtime.h"
|
||||
#include <QChar>
|
||||
|
||||
/// Helper stream for antlr, the lexer does not need to base case sensitive
|
||||
/// this is achieved by changing the case of the chars in LA how ever
|
||||
/// when the text of a recognized token is captured the getText function
|
||||
/// is used which does no case conversion so the parse will receive the original
|
||||
/// case.
|
||||
class CaseChangingCharStream: public antlr4::CharStream
|
||||
{
|
||||
public:
|
||||
CaseChangingCharStream(antlr4::CharStream *stream, bool upper)
|
||||
: stream(stream)
|
||||
, upper(upper)
|
||||
{}
|
||||
|
||||
virtual ~CaseChangingCharStream()
|
||||
{}
|
||||
|
||||
virtual void consume() override
|
||||
{
|
||||
stream->consume();
|
||||
}
|
||||
|
||||
virtual size_t LA(ssize_t i) override
|
||||
{
|
||||
int c = stream->LA(i);
|
||||
if (c <= 0)
|
||||
return c;
|
||||
|
||||
if (upper)
|
||||
return QChar::toUpper(c);
|
||||
|
||||
return QChar::toLower(c);
|
||||
}
|
||||
|
||||
virtual std::string getText(const antlr4::misc::Interval &interval) override
|
||||
{
|
||||
return stream->getText(interval);
|
||||
}
|
||||
|
||||
virtual std::string toString() const override
|
||||
{
|
||||
return stream->toString();
|
||||
}
|
||||
|
||||
virtual ssize_t mark() override
|
||||
{
|
||||
return stream->mark();
|
||||
}
|
||||
|
||||
virtual void release(ssize_t marker) override
|
||||
{
|
||||
stream->release(marker);
|
||||
}
|
||||
|
||||
virtual size_t index() override
|
||||
{
|
||||
return stream->index();
|
||||
}
|
||||
|
||||
virtual void seek(size_t index) override
|
||||
{
|
||||
stream->seek(index);
|
||||
}
|
||||
|
||||
virtual size_t size() override
|
||||
{
|
||||
return stream->size();
|
||||
}
|
||||
|
||||
virtual std::string getSourceName() const override
|
||||
{
|
||||
return stream->getSourceName();
|
||||
}
|
||||
|
||||
private:
|
||||
antlr4::CharStream *stream;
|
||||
bool upper;
|
||||
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue