Improve AST nodes
Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#define FURC_FRONT_PARSER_HPP
|
||||
|
||||
#include "furc/ast/declaration.hpp"
|
||||
#include "furc/ast/expression.hpp"
|
||||
#include "furc/ast/literal.hpp"
|
||||
#include "furc/ast/node.hpp"
|
||||
#include "furc/ast/program.hpp"
|
||||
#include "furc/front/lexer.hpp"
|
||||
@@ -28,6 +30,8 @@ public:
|
||||
private:
|
||||
ast::node_handle<ast::declaration_node> parse_declaration();
|
||||
ast::node_handle<ast::statement_node> parse_statement();
|
||||
ast::node_handle<ast::expression_node> parse_expression();
|
||||
ast::node_handle<ast::literal_node> parse_literal();
|
||||
|
||||
ast::function_body_handle parse_body();
|
||||
private:
|
||||
|
||||
@@ -14,6 +14,7 @@ enum class token_t {
|
||||
None,
|
||||
Identifier,
|
||||
Keyword,
|
||||
String,
|
||||
Integer,
|
||||
Lparen,
|
||||
Rparen,
|
||||
@@ -32,6 +33,7 @@ static inline std::ostream& operator<<(std::ostream& os, token_t type) {
|
||||
case token_t::None: return os << "none";
|
||||
case token_t::Identifier: return os << "identifier";
|
||||
case token_t::Keyword: return os << "keyword";
|
||||
case token_t::String: return os << "string";
|
||||
case token_t::Integer: return os << "integer";
|
||||
case token_t::Lparen: return os << "'('";
|
||||
case token_t::Rparen: return os << "')'";
|
||||
@@ -51,6 +53,7 @@ static inline std::string operator+(const std::string& str, token_t type) {
|
||||
case token_t::None: return str + "none";
|
||||
case token_t::Identifier: return str + "identifier";
|
||||
case token_t::Keyword: return str + "keyword";
|
||||
case token_t::String: return str + "string";
|
||||
case token_t::Integer: return str + "integer";
|
||||
case token_t::Lparen: return str + "'('";
|
||||
case token_t::Rparen: return str + "')'";
|
||||
@@ -103,9 +106,10 @@ struct token {
|
||||
bool operator==(const token& rhs) const {
|
||||
if (type != rhs.type) return false;
|
||||
switch (type) {
|
||||
case token_t::Identifier: return value == rhs.value;
|
||||
case token_t::Keyword: return keyword == rhs.keyword;
|
||||
case token_t::Identifier:
|
||||
case token_t::String:
|
||||
case token_t::Integer: return value == rhs.value;
|
||||
case token_t::Keyword: return keyword == rhs.keyword;
|
||||
case token_t::None:
|
||||
case token_t::Lparen:
|
||||
case token_t::Rparen:
|
||||
@@ -124,6 +128,7 @@ struct token {
|
||||
static inline std::ostream& operator<<(std::ostream& os, const token& token) {
|
||||
switch (token.type) {
|
||||
case token_t::Identifier:
|
||||
case token_t::String:
|
||||
case token_t::Integer: return os << token.value;
|
||||
case token_t::Keyword: return os << token.keyword;
|
||||
default: return os << token.type;
|
||||
|
||||
Reference in New Issue
Block a user