Add integers to lexer
Signed-off-by: CHatingPython <chatingpython@gmail.com>
This commit is contained in:
@@ -42,7 +42,9 @@ public:
|
||||
|
||||
front::token name() const { return m_name; }
|
||||
public:
|
||||
std::ostream& print(std::ostream& os) const override { return os << "function " << m_name.value << " declaration"; }
|
||||
std::ostream& print(std::ostream& os) const override {
|
||||
return os << "function " << m_name->string << " declaration";
|
||||
}
|
||||
protected:
|
||||
front::token m_name;
|
||||
};
|
||||
@@ -73,13 +75,14 @@ public:
|
||||
const function_body_handle& body() const { return m_body; }
|
||||
public:
|
||||
std::ostream& print(std::ostream& os) const override {
|
||||
os << "function " << m_name.value << " definition:";
|
||||
function_declarartion_node::print(os);
|
||||
os << ':';
|
||||
if (m_body.present()) {
|
||||
for (const auto& entry : m_body->statements)
|
||||
os << '\n' << entry;
|
||||
return os << '\n' << m_body->end << ": " << m_name.value << " end";
|
||||
return os << '\n' << m_body->end << ": " << m_name->string << " end";
|
||||
}
|
||||
return os << (std::string)m_body; // error
|
||||
return os << m_body.error(); // error
|
||||
}
|
||||
private:
|
||||
function_body_handle m_body;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "furc/ast/expression.hpp"
|
||||
#include "furc/ast/node.hpp"
|
||||
#include "furc/front/token.hpp"
|
||||
|
||||
#include <ostream>
|
||||
|
||||
@@ -14,13 +15,6 @@ enum class literal_node_t {
|
||||
Integer
|
||||
};
|
||||
|
||||
static inline std::ostream& operator<<(std::ostream& os, literal_node_t type) {
|
||||
switch (type) {
|
||||
case literal_node_t::String: return os << "string";
|
||||
case literal_node_t::Integer: return os << "integer";
|
||||
}
|
||||
}
|
||||
|
||||
class literal_node : public expression_node {
|
||||
public:
|
||||
node_t category() const override { return node_t::Literal; }
|
||||
@@ -40,8 +34,8 @@ public:
|
||||
const handle<std::string_view>& value() const { return m_value; }
|
||||
public:
|
||||
std::ostream& print(std::ostream& os) const override {
|
||||
if (m_value.error()) return os << (std::string)m_value;
|
||||
return os << '"' << *m_value << '"';
|
||||
if (m_value.has_error()) return os << (std::string)m_value;
|
||||
return os << "string literal (" << *m_value << ")";
|
||||
}
|
||||
private:
|
||||
handle<std::string_view> m_value;
|
||||
@@ -49,14 +43,19 @@ private:
|
||||
|
||||
class integer_literal_node : public literal_node {
|
||||
public:
|
||||
integer_literal_node(handle<std::uint64_t>&& value)
|
||||
integer_literal_node(handle<front::integer_token>&& value)
|
||||
: m_value(std::move(value)) {}
|
||||
public:
|
||||
literal_node_t literal_type() const override { return literal_node_t::Integer; }
|
||||
|
||||
const handle<std::uint64_t>& value() const { return m_value; }
|
||||
const handle<front::integer_token>& value() const { return m_value; }
|
||||
public:
|
||||
std::ostream& print(std::ostream& os) const override {
|
||||
if (m_value.has_error()) return os << m_value.error();
|
||||
return os << "integer literal (" << *m_value << ")";
|
||||
}
|
||||
private:
|
||||
handle<std::uint64_t> m_value;
|
||||
handle<front::integer_token> m_value;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
|
||||
Reference in New Issue
Block a user