Files
BlitzLLVM/code_compiler/source/lexer.hpp
T
Michael Fabian 'Xaymar' Dirks dfe3e88dbd Lexer done for now, moving on to ast
2024-06-26 00:31:45 +02:00

65 lines
1.5 KiB
C++

/// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2017-2024 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 {
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();
};
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 _override;
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();
};
} // namespace blitz