-
Notifications
You must be signed in to change notification settings - Fork 1
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 #33 from EdwardPalmer99/EdwardPalmer99/feature/cle…
…anup-tokenizer Rewrites Token
- Loading branch information
Showing
5 changed files
with
99 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file Token.cpp | ||
* @author Edward Palmer | ||
* @date 2025-01-14 | ||
* | ||
* @copyright Copyright (c) 2025 | ||
* | ||
*/ | ||
|
||
#include "Token.hpp" | ||
#include "Exceptions.hpp" | ||
|
||
Token::Token(TokenType type_, std::string value_) | ||
: type{type_}, value{std::move(value_)} | ||
{ | ||
} | ||
|
||
|
||
std::string Token::print() const | ||
{ | ||
return typeName() + ": " + value; | ||
} | ||
|
||
|
||
std::string Token::typeName() const | ||
{ | ||
switch (type) | ||
{ | ||
case EndOfFile: | ||
return "end-of-file"; | ||
case Punctuation: | ||
return "punctuation"; | ||
case Keyword: | ||
return "keyword"; | ||
case Variable: | ||
return "variable"; | ||
case String: | ||
return "string"; | ||
case Operator: | ||
return "other"; | ||
case Int: | ||
return "int"; | ||
case Float: | ||
return "float"; | ||
default: | ||
ThrowException("unexpected token type: " + std::to_string(type)); | ||
} | ||
} |
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,38 @@ | ||
/** | ||
* @file Token.hpp | ||
* @author Edward Palmer | ||
* @date 2025-01-14 | ||
* | ||
* @copyright Copyright (c) 2025 | ||
* | ||
*/ | ||
|
||
#pragma once | ||
#include <string> | ||
|
||
class Token | ||
{ | ||
public: | ||
enum TokenType | ||
{ | ||
EndOfFile, | ||
Punctuation, | ||
Keyword, | ||
Variable, | ||
String, | ||
Operator, | ||
Int, | ||
Float | ||
}; | ||
|
||
Token() = delete; | ||
Token(TokenType type, std::string value); | ||
|
||
std::string print() const; | ||
|
||
const TokenType type; | ||
const std::string value; | ||
|
||
private: | ||
std::string typeName() const; | ||
}; |
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