-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from BastianBlokland/feature/char-type
Character type
- Loading branch information
Showing
49 changed files
with
732 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ enum class TokenKind { | |
LitFloat, | ||
LitBool, | ||
LitString, | ||
LitChar, | ||
Keyword, | ||
Identifier, | ||
LineComment, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
#include "lex/token_payload.hpp" | ||
|
||
namespace lex { | ||
|
||
class LitCharTokenPayload final : public TokenPayload { | ||
public: | ||
LitCharTokenPayload() = delete; | ||
explicit LitCharTokenPayload(const uint8_t val) : m_val{val} {} | ||
|
||
auto operator==(const TokenPayload& rhs) const noexcept -> bool override { | ||
const auto castedRhs = dynamic_cast<const LitCharTokenPayload*>(&rhs); | ||
return castedRhs != nullptr && m_val == castedRhs->m_val; | ||
} | ||
|
||
auto operator!=(const TokenPayload& rhs) const noexcept -> bool override { | ||
return !LitCharTokenPayload::operator==(rhs); | ||
} | ||
|
||
[[nodiscard]] auto clone() -> std::unique_ptr<TokenPayload> override { | ||
return std::make_unique<LitCharTokenPayload>(*this); | ||
} | ||
|
||
[[nodiscard]] auto getValue() const noexcept { return m_val; } | ||
|
||
private: | ||
const uint8_t m_val; | ||
|
||
auto print(std::ostream& out) const -> std::ostream& override; | ||
}; | ||
|
||
} // namespace lex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
#include "prog/expr/node.hpp" | ||
#include "prog/program.hpp" | ||
|
||
namespace prog::expr { | ||
|
||
class LitCharNode final : public Node { | ||
friend auto litCharNode(const Program& program, uint8_t val) -> NodePtr; | ||
|
||
public: | ||
LitCharNode() = delete; | ||
|
||
auto operator==(const Node& rhs) const noexcept -> bool override; | ||
auto operator!=(const Node& rhs) const noexcept -> bool override; | ||
|
||
[[nodiscard]] auto operator[](unsigned int i) const -> const Node& override; | ||
[[nodiscard]] auto getChildCount() const -> unsigned int override; | ||
[[nodiscard]] auto getType() const noexcept -> sym::TypeId override; | ||
[[nodiscard]] auto toString() const -> std::string override; | ||
|
||
[[nodiscard]] auto getVal() const noexcept -> uint8_t; | ||
|
||
auto accept(NodeVisitor* visitor) const -> void override; | ||
|
||
private: | ||
sym::TypeId m_type; | ||
uint8_t m_val; | ||
|
||
LitCharNode(sym::TypeId type, uint8_t val); | ||
}; | ||
|
||
// Factories. | ||
auto litCharNode(const Program& program, uint8_t val) -> NodePtr; | ||
|
||
} // namespace prog::expr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ enum class TypeKind { | |
Float, | ||
Bool, | ||
String, | ||
Char, | ||
UserStruct, | ||
UserUnion, | ||
UserDelegate, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.