Make a Lisp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.3 KiB

2 years ago
/*
* Copyright (C) 2023 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <cstddef> // size_t
#include <cstdint> // uint8_t
#include <string>
#include <vector>
#include "ruc/format/print.h"
#include "ruc/genericlexer.h"
namespace blaze {
struct Token {
enum class Type : uint8_t {
None,
Special, // ~@
BracketOpen, // [
BracketClose, // ]
BraceOpen, // {
BraceClose, // }
ParenOpen, // (
ParenClose, // )
Quote, // '
Backtick, // `
Tilde, // ~
Caret, // ^
At, // @
String, // "foobar"
Keyword, // :keyword
Value, // numbers, "true", "false", and "nil", symbols
2 years ago
Comment, // ;
Error,
2 years ago
};
Type type { Type::None };
size_t column { 0 };
size_t line { 0 };
std::string symbol;
};
// Lexical analyzer -> tokenizes
class Lexer final : public ruc::GenericLexer {
public:
Lexer(std::string_view input);
virtual ~Lexer();
void tokenize();
void dump() const;
std::vector<Token>& tokens() { return m_tokens; }
private:
bool consumeSpliceUnquoteOrUnquote(); // ~@ or ~
bool consumeString();
bool consumeKeyword();
2 years ago
bool consumeValue();
bool consumeComment();
2 years ago
size_t m_column { 0 };
size_t m_line { 0 };
std::vector<Token> m_tokens;
};
} // namespace blaze