Large chunk of work in parser for getting expressions to work.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <memory>
|
||||
#include "../../CoreData/Identifier.hpp"
|
||||
#include "../../TextSpan.hpp"
|
||||
#include "../ParserDefines.hpp"
|
||||
#include "LexTokenKind.hpp"
|
||||
|
||||
namespace MalachScript::Parser {
|
||||
@@ -28,30 +29,30 @@ namespace MalachScript::Parser {
|
||||
};
|
||||
|
||||
class IntegerLiteral : public LexTokenImpl<LexTokenKind::IntegerLiteral> {
|
||||
uint64_t _value;
|
||||
ParseInt _value;
|
||||
|
||||
public:
|
||||
IntegerLiteral(const TextSpan& span, uint64_t value)
|
||||
IntegerLiteral(const TextSpan& span, ParseInt value)
|
||||
: LexTokenImpl<LexTokenKind::IntegerLiteral>(span), _value(value) {}
|
||||
[[nodiscard]] inline uint64_t GetValue() const noexcept { return _value; }
|
||||
[[nodiscard]] inline ParseInt GetValue() const noexcept { return _value; }
|
||||
};
|
||||
|
||||
class FloatLiteral : public LexTokenImpl<LexTokenKind::FloatLiteral> {
|
||||
double _value;
|
||||
ParseFloat _value;
|
||||
|
||||
public:
|
||||
FloatLiteral(const TextSpan& span, double value)
|
||||
FloatLiteral(const TextSpan& span, ParseFloat value)
|
||||
: LexTokenImpl<LexTokenKind::FloatLiteral>(span), _value(value) {}
|
||||
[[nodiscard]] inline double GetValue() const noexcept { return _value; }
|
||||
[[nodiscard]] inline long double GetValue() const noexcept { return _value; }
|
||||
};
|
||||
|
||||
class StringLiteral : public LexTokenImpl<LexTokenKind::StringLiteral> {
|
||||
std::u8string _value;
|
||||
ParseString _value;
|
||||
|
||||
public:
|
||||
StringLiteral(const TextSpan& span, std::u8string value)
|
||||
StringLiteral(const TextSpan& span, ParseString value)
|
||||
: LexTokenImpl<LexTokenKind::StringLiteral>(span), _value(std::move(value)) {}
|
||||
[[nodiscard]] inline const std::u8string& GetValue() const noexcept { return _value; }
|
||||
[[nodiscard]] inline const ParseString& GetValue() const noexcept { return _value; }
|
||||
};
|
||||
|
||||
class IdentifierToken : public LexTokenImpl<LexTokenKind::Identifier> {
|
||||
|
||||
@@ -338,16 +338,16 @@ namespace MalachScript::Parser {
|
||||
return pow10[n];
|
||||
}
|
||||
|
||||
LexToken* Lexer::LexDecimal(uint64_t initial) {
|
||||
LexToken* Lexer::LexDecimal(ParseInt initial) {
|
||||
auto start = _position;
|
||||
uint64_t value = initial;
|
||||
uint64_t decimalValue = 0;
|
||||
uint64_t exponentValue = 0;
|
||||
ParseInt value = initial;
|
||||
ParseInt decimalValue = 0;
|
||||
ParseInt exponentValue = 0;
|
||||
uint8_t decimalLength = 0;
|
||||
bool isDecimal = false;
|
||||
bool isExponent = false;
|
||||
while (true) {
|
||||
auto v = (uint64_t)LexDecimalValue(Peek());
|
||||
auto v = (ParseInt)LexDecimalValue(Peek());
|
||||
if (v == 255) {
|
||||
if (!isDecimal && Peek() == u8'.') {
|
||||
isDecimal = true;
|
||||
@@ -376,7 +376,7 @@ namespace MalachScript::Parser {
|
||||
}
|
||||
}
|
||||
if (isDecimal || isExponent) {
|
||||
auto val = value + ((double)decimalValue / quick_pow10(decimalLength));
|
||||
auto val = value + ((ParseFloat)decimalValue / quick_pow10(decimalLength));
|
||||
if (isExponent) {
|
||||
val *= pow(10, exponentValue);
|
||||
}
|
||||
@@ -387,7 +387,7 @@ namespace MalachScript::Parser {
|
||||
|
||||
IntegerLiteral* Lexer::LexHexadecimal() {
|
||||
auto start = _position;
|
||||
uint64_t value = 0;
|
||||
ParseInt value = 0;
|
||||
while (true) {
|
||||
auto v = LexHexadecimalValue(Peek());
|
||||
if (v == 255) {
|
||||
@@ -401,7 +401,7 @@ namespace MalachScript::Parser {
|
||||
}
|
||||
IntegerLiteral* Lexer::LexOctal() {
|
||||
auto start = _position;
|
||||
uint64_t value = 0;
|
||||
ParseInt value = 0;
|
||||
while (true) {
|
||||
auto v = LexOctalValue(Peek());
|
||||
if (v == 255) {
|
||||
@@ -415,7 +415,7 @@ namespace MalachScript::Parser {
|
||||
}
|
||||
IntegerLiteral* Lexer::LexBinary() {
|
||||
auto start = _position;
|
||||
uint64_t value = 0;
|
||||
ParseInt value = 0;
|
||||
while (true) {
|
||||
auto v = LexBinaryValue(Peek());
|
||||
if (v == 255) {
|
||||
@@ -457,7 +457,7 @@ namespace MalachScript::Parser {
|
||||
if (heredoc) {
|
||||
Progress(2);
|
||||
}
|
||||
return Create<StringLiteral>(TextSpan(start, start + _position), std::u8string(_script.substr(start, offset)));
|
||||
return Create<StringLiteral>(TextSpan(start, start + _position), ParseString(_script.substr(start, offset)));
|
||||
}
|
||||
|
||||
LexToken* Lexer::LexKeywordOrIdentifier() {
|
||||
|
||||
Reference in New Issue
Block a user