VoxelEngine/src/coders/BasicParser.hpp
MihailRis 8a8c1525fd
Fix syntax highlighting unicode support (#475)
* convert BasicParser to a template

* fix syntax hightlighting with unicode characters
2025-02-22 01:01:20 +03:00

54 lines
1.3 KiB
C++

#pragma once
#include "commons.hpp"
#include "data/dv.hpp"
template <typename CharT>
class BasicParser {
using StringT = std::basic_string<CharT>;
using StringViewT = std::basic_string_view<CharT>;
protected:
std::string_view filename;
StringViewT source;
uint pos = 0;
uint line = 1;
uint linestart = 0;
virtual void skipWhitespace();
void skip(size_t n);
void skipLine();
bool skipTo(const StringT& substring);
void expect(CharT expected);
void expect(const StringT& substring);
bool isNext(const StringT& substring);
void expectNewLine();
void goBack(size_t count = 1);
void reset();
int64_t parseSimpleInt(int base);
dv::value parseNumber(int sign);
dv::value parseNumber();
StringT parseString(CharT chr, bool closeRequired = true);
parsing_error error(const std::string& message);
public:
StringViewT readUntil(CharT c);
StringViewT readUntil(StringViewT s, bool nothrow);
StringViewT readUntilWhitespace();
StringViewT readUntilEOL();
StringT parseName();
StringT parseXmlName();
bool hasNext();
size_t remain() const;
CharT peek();
CharT peekInLine();
CharT peekNoJump();
CharT nextChar();
BasicParser(std::string_view file, StringViewT source)
: filename(file), source(source) {
}
};
#include "BasicParser.inl"