mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 20:11:50 +00:00
Fix syntax highlighting unicode support (#475)
* convert BasicParser to a template * fix syntax hightlighting with unicode characters
This commit is contained in:
parent
b61f594495
commit
8a8c1525fd
19 changed files with 644 additions and 509 deletions
|
|
@ -3,24 +3,8 @@
|
|||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
#include "data/dv.hpp"
|
||||
#include "typedefs.hpp"
|
||||
|
||||
inline int is_box(int c) {
|
||||
switch (c) {
|
||||
case 'B':
|
||||
case 'b':
|
||||
return 2;
|
||||
case 'O':
|
||||
case 'o':
|
||||
return 8;
|
||||
case 'X':
|
||||
case 'x':
|
||||
return 16;
|
||||
}
|
||||
return 10;
|
||||
}
|
||||
|
||||
inline bool is_digit(int c) {
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
|
@ -66,7 +50,7 @@ public:
|
|||
uint pos;
|
||||
uint line;
|
||||
uint linestart;
|
||||
|
||||
|
||||
parsing_error(
|
||||
const std::string& message,
|
||||
std::string_view filename,
|
||||
|
|
@ -75,47 +59,14 @@ public:
|
|||
uint line,
|
||||
uint linestart
|
||||
);
|
||||
|
||||
parsing_error(
|
||||
const std::string& message,
|
||||
std::string&& filename,
|
||||
std::string&& source,
|
||||
uint pos,
|
||||
uint line,
|
||||
uint linestart
|
||||
);
|
||||
std::string errorLog() const;
|
||||
};
|
||||
|
||||
class BasicParser {
|
||||
protected:
|
||||
std::string_view filename;
|
||||
std::string_view source;
|
||||
uint pos = 0;
|
||||
uint line = 1;
|
||||
uint linestart = 0;
|
||||
|
||||
virtual void skipWhitespace();
|
||||
void skip(size_t n);
|
||||
void skipLine();
|
||||
bool skipTo(const std::string& substring);
|
||||
void expect(char expected);
|
||||
void expect(const std::string& substring);
|
||||
bool isNext(const std::string& substring);
|
||||
void expectNewLine();
|
||||
void goBack(size_t count = 1);
|
||||
void reset();
|
||||
|
||||
int64_t parseSimpleInt(int base);
|
||||
dv::value parseNumber(int sign);
|
||||
dv::value parseNumber();
|
||||
std::string parseString(char chr, bool closeRequired = true);
|
||||
|
||||
parsing_error error(const std::string& message);
|
||||
public:
|
||||
std::string_view readUntil(char c);
|
||||
std::string_view readUntil(std::string_view s, bool nothrow);
|
||||
std::string_view readUntilWhitespace();
|
||||
std::string_view readUntilEOL();
|
||||
std::string parseName();
|
||||
std::string parseXmlName();
|
||||
bool hasNext();
|
||||
size_t remain() const;
|
||||
char peek();
|
||||
char peekInLine();
|
||||
char peekNoJump();
|
||||
char nextChar();
|
||||
|
||||
BasicParser(std::string_view file, std::string_view source);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue