Files
BlitzLLVM/code_compiler/source/lexer.hpp
T
2025-01-25 19:26:49 +01:00

78 lines
1.8 KiB
C++

/// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2017-2025 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
// AUTOGENERATED COPYRIGHT HEADER END
#pragma once
#include <cinttypes>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <istream>
#include <memory>
#include <string>
#include <utility>
#include "error.hpp"
// ToDo:
// - Figure out a way to let the lexer output line and character information?
namespace blitz {
struct token {
std::pair<uint64_t, uint64_t> location;
std::string text;
enum class variant : uint64_t {
NONE, // There is no token here.
UNKNOWN, // We have absolutely no fucking clue.
ENDOFFILE, // End of the file.
NEWLINE, // New Line.
SEPARATOR, // Command Separator.
CONTROL, // All kinds of control signals
SYMBOL, // All kinds of symbols.
COMMENT, // ; Whatever
TEXT, // HelloWorld
STRING, // "HelloWorld"
INTEGER, // 1, 1% (without the %)
REAL, // 1.0, 1# (without the #)
} type;
std::string to_string();
bool operator==(blitz::token::variant rhs);
bool operator==(std::string const& rhs);
};
class lexer {
std::filesystem::path _file;
std::ifstream _stream;
// Current location in the file.
std::pair<uint64_t, uint64_t> _location;
blitz::token _current;
blitz::token _next;
public:
~lexer();
lexer(std::filesystem::path file);
/** Retrieve the current token information.
*/
blitz::token current();
/** Retrieve the next token in the given stream.
*
* This will replace the current token.
*/
blitz::token next();
/** Peek at the next token in the given stream.
*
* The current token will remain in-tact.
*/
blitz::token peek();
public:
std::filesystem::path file();
};
} // namespace blitz