3#include <initializer_list>
6#include <unordered_map>
31 [[nodiscard]]
const std::vector<std::string_view>&
getTokens()
const;
33 [[nodiscard]] uint64_t
size()
const;
35 [[nodiscard]] uint64_t
tell()
const;
37 void seek(uint64_t head_);
39 [[nodiscard]] std::string_view
next();
42 requires std::same_as<T, bool> || std::integral<T> || std::floating_point<T>
44 if constexpr (std::same_as<T, bool>) {
46 }
else if constexpr (std::integral<T>) {
48 }
else if constexpr (std::floating_point<T>) {
55 [[nodiscard]] std::string_view
peek()
const;
58 requires std::same_as<T, bool> || std::integral<T> || std::floating_point<T>
60 if constexpr (std::same_as<T, bool>) {
62 }
else if constexpr (std::integral<T>) {
64 }
else if constexpr (std::floating_point<T>) {
76 std::vector<std::string_view>
tokens;
92 [[nodiscard]]
Result parse(std::string_view
text, std::string& backingString)
const;
168[[nodiscard]]
bool tryToEatChar(BufferStream& stream,
char c);
std::vector< std::string_view > tokens
const std::vector< std::string_view > & getTokens() const
void seek(uint64_t head_)
std::string_view peek() const
Tokenizer & setEscapeSequences(const EscapeSequenceMap &escapeSequences_)
Tokenizer & setMultiLineCommentStart(std::string_view multiLineCommentStart_)
std::string_view singleLineCommentStart
Result parse(std::string_view text, std::string &backingString) const
EscapeSequenceMap escapeSequences
Tokenizer & setSingleLineCommentStart(std::string_view singleLineCommentStart_)
Tokenizer & setMultiLineCommentEnd(std::string_view multiLineCommentEnd_)
std::string_view multiLineCommentStart
std::string_view multiLineCommentEnd
std::string convertSpecialCharsToEscapes(std::string_view str, const EscapeSequenceMap &escapeSequences)
Convert special characters like \n to escaped special characters like \\n.
std::string convertEscapesToSpecialChars(std::string_view str, const EscapeSequenceMap &escapeSequences)
Convert escaped special characters like \\n to special characters like \n.
constexpr std::string_view DEFAULT_MULTI_LINE_COMMENT_END
void eatMultiLineComment(BufferStream &stream, std::string_view multiLineCommentEnd=DEFAULT_MULTI_LINE_COMMENT_END)
If a multi line comment is detected, eat its contents.
std::string readString(BufferStream &stream, std::initializer_list< std::pair< char, char > > quotes={DEFAULT_QUOTES}, const EscapeSequenceMap &escapeSequences=getDefaultEscapeSequences())
Read a string starting at the current stream position.
std::unordered_map< char, char > EscapeSequenceMap
void eatSingleLineComment(BufferStream &stream)
If a single line comment is detected, eat its contents.
void eatWhitespaceAndSingleLineComments(BufferStream &stream, std::string_view singleLineCommentStart=DEFAULT_SINGLE_LINE_COMMENT_START)
Eat all whitespace and single line comments after the current stream position.
void eatWhitespace(BufferStream &stream)
Eat all whitespace after the current stream position.
constexpr std::string_view DEFAULT_SINGLE_LINE_COMMENT_START
bool tryToEatChar(BufferStream &stream, char c)
If the given char exists at the current position, skip over it.
constexpr std::string_view DEFAULT_MULTI_LINE_COMMENT_START
constexpr std::pair DEFAULT_QUOTES
const EscapeSequenceMap & getDefaultEscapeSequencesOrNone(bool useEscapes)
std::string_view readUnquotedStringToBuffer(BufferStream &stream, BufferStream &backing, const EscapeSequenceMap &escapeSequences=getDefaultEscapeSequences())
Read a string starting at the current stream position.
std::string readUnquotedString(BufferStream &stream, const EscapeSequenceMap &escapeSequences=getDefaultEscapeSequences())
Read a string starting at the current stream position.
void eatWhitespaceAndComments(BufferStream &stream, std::string_view singleLineCommentStart=DEFAULT_SINGLE_LINE_COMMENT_START, std::string_view multiLineCommentStart=DEFAULT_MULTI_LINE_COMMENT_START)
Eat all whitespace and comments after the current stream position.
std::string_view readStringToBuffer(BufferStream &stream, BufferStream &backing, std::initializer_list< std::pair< char, char > > quotes={DEFAULT_QUOTES}, const EscapeSequenceMap &escapeSequences=getDefaultEscapeSequences())
Read a string starting at the current stream position.
const EscapeSequenceMap & getDefaultEscapeSequences()
void eatWhitespaceAndMultiLineComments(BufferStream &stream, std::string_view multiLineCommentStart=DEFAULT_MULTI_LINE_COMMENT_START)
Eat all whitespace and multi line comments after the current stream position.
bool toBool(std::string_view number, bool &out, int base=10)
bool toFloat(std::string_view number, std::floating_point auto &out)
bool toInt(std::string_view number, std::integral auto &out, int base=10)