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.

65 lines
1.3 KiB

2 years ago
/*
* Copyright (C) 2023 Riyyi
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <cstddef> // size_t
#include <vector>
#include "ast.h"
#include "lexer.h"
namespace blaze {
// Parsing -> creates AST
class Reader {
public:
Reader(std::vector<Token>&& tokens) noexcept;
virtual ~Reader();
void read();
void dump();
ASTNode* node() { return m_node; }
private:
bool isEOF() const;
Token peek() const;
Token consume();
bool consumeSpecific(Token token);
2 years ago
void ignore();
void retreat();
2 years ago
ASTNode* readImpl();
ASTNode* readSpliceUnquote(); // ~@
ASTNode* readList(); // ()
ASTNode* readVector(); // []
ASTNode* readHashMap(); // {}
ASTNode* readQuote(); // '
ASTNode* readQuasiQuote(); // `
ASTNode* readUnquote(); // ~
ASTNode* readWithMeta(); // ^
ASTNode* readDeref(); // @
ASTNode* readString(); // "foobar"
ASTNode* readKeyword(); // :keyword
ASTNode* readValue(); // number, "true", "false", "nil", symbol
2 years ago
void dumpImpl(ASTNode* node);
size_t m_index { 0 };
size_t m_indentation { 0 };
std::vector<Token> m_tokens;
char m_error_character { 0 };
bool m_invalid_syntax { false };
bool m_is_unbalanced { false };
2 years ago
ASTNode* m_node { nullptr };
};
} // namespace blaze