fix: Minor fixes
Fixed some minor mistakes (wrong messages/errors) due to copy/pasting code. Fixed that digits weren't allowed in identifiers before. Also minor improvements in some functions/code parts.
This commit is contained in:
parent
85dd8bc10f
commit
f9051e1c21
@ -27,7 +27,7 @@ namespace arti::lang {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline constexpr bool isIdentChar(char c) {
|
static inline constexpr bool isIdentChar(char c) {
|
||||||
return isLetter(c) || c == '_';
|
return isLetter(c) || c == '_' || isDigit(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline constexpr bool isHexChar(char c) {
|
static inline constexpr bool isHexChar(char c) {
|
||||||
|
|||||||
@ -8,189 +8,76 @@ namespace arti::lang {
|
|||||||
std::string toString(const Token &value) {
|
std::string toString(const Token &value) {
|
||||||
using enum TokenV;
|
using enum TokenV;
|
||||||
|
|
||||||
|
std::string_view tokenStr;
|
||||||
|
|
||||||
switch (value.value) {
|
switch (value.value) {
|
||||||
case tkEOF:
|
case tkEOF: return "Token{{ tkEOF }}";
|
||||||
return std::format("Token{{ {} }}", "tkEOF", value.strValue);
|
case tkString: tokenStr = "tkString"; break;
|
||||||
case tkString:
|
case tkDecimal: tokenStr = "tkDecimal"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "tkString", value.strValue);
|
case tkInteger: tokenStr = "tkInteger"; break;
|
||||||
case tkDecimal:
|
case tkCharacter: tokenStr = "tkCharacter"; break;
|
||||||
return std::format(
|
case tkIdentifier: tokenStr = "tkIdentifier"; break;
|
||||||
"Token{{ {}, {} }}",
|
case opDot: tokenStr = "opDot"; break;
|
||||||
"tkDecimal",
|
case opMod: tokenStr = "opMod"; break;
|
||||||
value.strValue
|
case opPlus: tokenStr = "opPlus"; break;
|
||||||
);
|
case opHyphen: tokenStr = "opHyphen"; break;
|
||||||
case tkInteger:
|
case opSlash: tokenStr = "opSlash"; break;
|
||||||
return std::format(
|
case opBang: tokenStr = "opBang"; break;
|
||||||
"Token{{ {}, {} }}",
|
case opStar: tokenStr = "opStar"; break;
|
||||||
"tkInteger",
|
case opColon: tokenStr = "opColon"; break;
|
||||||
value.strValue
|
case opComma: tokenStr = "opComma"; break;
|
||||||
);
|
case opAssign: tokenStr = "opAssign"; break;
|
||||||
case tkCharacter:
|
case opAccess: tokenStr = "opAccess"; break;
|
||||||
return std::format(
|
case opSemicolon: tokenStr = "opSemicolon"; break;
|
||||||
"Token{{ {}, {} }}",
|
case opCaret: tokenStr = "opCaret"; break;
|
||||||
"tkCharacter",
|
case opTilde: tokenStr = "opTilde"; break;
|
||||||
value.strValue
|
case opEq: tokenStr = "opEq"; break;
|
||||||
);
|
case opNeq: tokenStr = "opNeq"; break;
|
||||||
case tkIdentifier:
|
case opLt: tokenStr = "opLt"; break;
|
||||||
return std::format(
|
case opGt: tokenStr = "opGt"; break;
|
||||||
"Token{{ {}, {} }}",
|
case opLtEq: tokenStr = "opLtEq"; break;
|
||||||
"tkIdentifier",
|
case opGtEq: tokenStr = "opGtEq"; break;
|
||||||
value.strValue
|
case opLShift: tokenStr = "opLShift"; break;
|
||||||
);
|
case opRShift: tokenStr = "opRShift"; break;
|
||||||
case opDot:
|
case opBoolAnd: tokenStr = "opBoolAnd"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opDot", value.strValue);
|
case opBoolOr: tokenStr = "opBoolOr"; break;
|
||||||
case opMod:
|
case opAnd: tokenStr = "opAnd"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opMod", value.strValue);
|
case opOr: tokenStr = "opOr"; break;
|
||||||
case opPlus:
|
case opLParen: tokenStr = "opLParen"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opPlus", value.strValue);
|
case opRParen: tokenStr = "opRParen"; break;
|
||||||
case opHyphen:
|
case opLBracket: tokenStr = "opLBracket"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opHyphen", value.strValue);
|
case opRBracket: tokenStr = "opRBracket"; break;
|
||||||
case opSlash:
|
case opLSquirly: tokenStr = "opLSquirly"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opSlash", value.strValue);
|
case opRSquirly: tokenStr = "opRSquirly"; break;
|
||||||
case opBang:
|
case opArrow: tokenStr = "opArrow"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opBang", value.strValue);
|
case kwOr: tokenStr = "kwOr"; break;
|
||||||
case opStar:
|
case kwNot: tokenStr = "kwNot"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opStar", value.strValue);
|
case kwAnd: tokenStr = "kwAnd"; break;
|
||||||
case opColon:
|
case kwIf: tokenStr = "kwIf"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opColon", value.strValue);
|
case kwElse: tokenStr = "kwElse"; break;
|
||||||
case opComma:
|
case kwFn: tokenStr = "kwFn"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opComma", value.strValue);
|
case kwEnum: tokenStr = "kwEnum"; break;
|
||||||
case opAssign:
|
case kwStruct: tokenStr = "kwStruct"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opAssign", value.strValue);
|
case kwVariant: tokenStr = "kwVariant"; break;
|
||||||
case opAccess:
|
case kwDef: tokenStr = "kwDef"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opAccess", value.strValue);
|
case kwLet: tokenStr = "kwLet"; break;
|
||||||
case opSemicolon:
|
case kwMut: tokenStr = "kwMut"; break;
|
||||||
return std::format(
|
case kwFor: tokenStr = "kwFor"; break;
|
||||||
"Token{{ {}, {} }}",
|
case kwWhile: tokenStr = "kwWhile"; break;
|
||||||
"opSemicolon",
|
case kwReturn: tokenStr = "kwReturn"; break;
|
||||||
value.strValue
|
case kwUnreachable: tokenStr = "kwUnreachable"; break;
|
||||||
);
|
case kwDefer: tokenStr = "kwDefer"; break;
|
||||||
case opCaret:
|
case kwErrDefer: tokenStr = "kwErrDefer"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opCaret", value.strValue);
|
case kwTrue: tokenStr = "kwTrue"; break;
|
||||||
case opTilde:
|
case kwFalse: tokenStr = "kwFalse"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opTilde", value.strValue);
|
case kwNull: tokenStr = "kwNull"; break;
|
||||||
case opEq:
|
case kwImport: tokenStr = "kwImport"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opEq", value.strValue);
|
case kwExport: tokenStr = "kwExport"; break;
|
||||||
case opNeq:
|
case kwModule: tokenStr = "kwModule"; break;
|
||||||
return std::format("Token{{ {}, {} }}", "opNeq", value.strValue);
|
default: tokenStr = "<Undefined>"; break;
|
||||||
case opLt:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opLt", value.strValue);
|
|
||||||
case opGt:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opGt", value.strValue);
|
|
||||||
case opLtEq:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opLtEq", value.strValue);
|
|
||||||
case opGtEq:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opGtEq", value.strValue);
|
|
||||||
case opLShift:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opLShift", value.strValue);
|
|
||||||
case opRShift:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opRShift", value.strValue);
|
|
||||||
case opBoolAnd:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"opBoolAnd",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case opBoolOr:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opBoolOr", value.strValue);
|
|
||||||
case opAnd:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opAnd", value.strValue);
|
|
||||||
case opOr:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opOr", value.strValue);
|
|
||||||
case opLParen:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opLParen", value.strValue);
|
|
||||||
case opRParen:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opRParen", value.strValue);
|
|
||||||
case opLBracket:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"opLBracket",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case opRBracket:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"opRBracket",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case opLSquirly:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"opLSquirly",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case opRSquirly:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"opRSquirly",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case opArrow:
|
|
||||||
return std::format("Token{{ {}, {} }}", "opArrow", value.strValue);
|
|
||||||
case kwOr:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwOr", value.strValue);
|
|
||||||
case kwNot:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwNot", value.strValue);
|
|
||||||
case kwAnd:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwAnd", value.strValue);
|
|
||||||
case kwIf:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwIf", value.strValue);
|
|
||||||
case kwElse:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwElse", value.strValue);
|
|
||||||
case kwFn:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwFn", value.strValue);
|
|
||||||
case kwEnum:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwEnum", value.strValue);
|
|
||||||
case kwStruct:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwStruct", value.strValue);
|
|
||||||
case kwVariant:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"kwVariant",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case kwDef:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwDef", value.strValue);
|
|
||||||
case kwLet:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwLet", value.strValue);
|
|
||||||
case kwMut:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwMut", value.strValue);
|
|
||||||
case kwFor:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwFor", value.strValue);
|
|
||||||
case kwWhile:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwWhile", value.strValue);
|
|
||||||
case kwReturn:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwReturn", value.strValue);
|
|
||||||
case kwUnreachable:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"kwUnreachable",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case kwDefer:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwDefer", value.strValue);
|
|
||||||
case kwErrDefer:
|
|
||||||
return std::format(
|
|
||||||
"Token{{ {}, {} }}",
|
|
||||||
"kwErrDefer",
|
|
||||||
value.strValue
|
|
||||||
);
|
|
||||||
case kwTrue:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwTrue", value.strValue);
|
|
||||||
case kwFalse:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwFalse", value.strValue);
|
|
||||||
case kwNull:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwNull", value.strValue);
|
|
||||||
case kwImport:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwImport", value.strValue);
|
|
||||||
case kwExport:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwExport", value.strValue);
|
|
||||||
case kwModule:
|
|
||||||
return std::format("Token{{ {}, {} }}", "kwModule", value.strValue);
|
|
||||||
default:
|
|
||||||
return "<Undefined>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unreachable();
|
return std::format("Token{{ {}, {} }}", tokenStr, value.strValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace arti::lang
|
} // namespace arti::lang
|
||||||
|
|||||||
@ -430,7 +430,7 @@ namespace arti::lang {
|
|||||||
return langException<ExceptCode::ecInvalidLiteral>(
|
return langException<ExceptCode::ecInvalidLiteral>(
|
||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
"end of string (\")",
|
"end of char literal (')",
|
||||||
"EOF"
|
"EOF"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -439,7 +439,7 @@ namespace arti::lang {
|
|||||||
return langException<ExceptCode::ecInvalidLiteral>(
|
return langException<ExceptCode::ecInvalidLiteral>(
|
||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
"end of string (\")",
|
"end char literal (')",
|
||||||
*iter
|
*iter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -478,78 +478,76 @@ namespace arti::lang {
|
|||||||
{ stIter, iter }
|
{ stIter, iter }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string_view strToken{ stIter, iter };
|
if (tok.strValue.compare("or") == 0) {
|
||||||
|
|
||||||
if (strToken.compare("or") == 0) {
|
|
||||||
tok.value = TokenV::kwOr;
|
tok.value = TokenV::kwOr;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("not") == 0) {
|
else if (tok.strValue.compare("not") == 0) {
|
||||||
tok.value = TokenV::kwNot;
|
tok.value = TokenV::kwNot;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("and") == 0) {
|
else if (tok.strValue.compare("and") == 0) {
|
||||||
tok.value = TokenV::kwAnd;
|
tok.value = TokenV::kwAnd;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("if") == 0) {
|
else if (tok.strValue.compare("if") == 0) {
|
||||||
tok.value = TokenV::kwIf;
|
tok.value = TokenV::kwIf;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("else") == 0) {
|
else if (tok.strValue.compare("else") == 0) {
|
||||||
tok.value = TokenV::kwElse;
|
tok.value = TokenV::kwElse;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("fn") == 0) {
|
else if (tok.strValue.compare("fn") == 0) {
|
||||||
tok.value = TokenV::kwFn;
|
tok.value = TokenV::kwFn;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("enum") == 0) {
|
else if (tok.strValue.compare("enum") == 0) {
|
||||||
tok.value = TokenV::kwEnum;
|
tok.value = TokenV::kwEnum;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("struct") == 0) {
|
else if (tok.strValue.compare("struct") == 0) {
|
||||||
tok.value = TokenV::kwStruct;
|
tok.value = TokenV::kwStruct;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("variant") == 0) {
|
else if (tok.strValue.compare("variant") == 0) {
|
||||||
tok.value = TokenV::kwVariant;
|
tok.value = TokenV::kwVariant;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("def") == 0) {
|
else if (tok.strValue.compare("def") == 0) {
|
||||||
tok.value = TokenV::kwDef;
|
tok.value = TokenV::kwDef;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("let") == 0) {
|
else if (tok.strValue.compare("let") == 0) {
|
||||||
tok.value = TokenV::kwLet;
|
tok.value = TokenV::kwLet;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("mut") == 0) {
|
else if (tok.strValue.compare("mut") == 0) {
|
||||||
tok.value = TokenV::kwMut;
|
tok.value = TokenV::kwMut;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("for") == 0) {
|
else if (tok.strValue.compare("for") == 0) {
|
||||||
tok.value = TokenV::kwFor;
|
tok.value = TokenV::kwFor;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("while") == 0) {
|
else if (tok.strValue.compare("while") == 0) {
|
||||||
tok.value = TokenV::kwWhile;
|
tok.value = TokenV::kwWhile;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("return") == 0) {
|
else if (tok.strValue.compare("return") == 0) {
|
||||||
tok.value = TokenV::kwReturn;
|
tok.value = TokenV::kwReturn;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("unreachable") == 0) {
|
else if (tok.strValue.compare("unreachable") == 0) {
|
||||||
tok.value = TokenV::kwUnreachable;
|
tok.value = TokenV::kwUnreachable;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("defer") == 0) {
|
else if (tok.strValue.compare("defer") == 0) {
|
||||||
tok.value = TokenV::kwDefer;
|
tok.value = TokenV::kwDefer;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("errdefer") == 0) {
|
else if (tok.strValue.compare("errdefer") == 0) {
|
||||||
tok.value = TokenV::kwErrDefer;
|
tok.value = TokenV::kwErrDefer;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("true") == 0) {
|
else if (tok.strValue.compare("true") == 0) {
|
||||||
tok.value = TokenV::kwTrue;
|
tok.value = TokenV::kwTrue;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("false") == 0) {
|
else if (tok.strValue.compare("false") == 0) {
|
||||||
tok.value = TokenV::kwFalse;
|
tok.value = TokenV::kwFalse;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("null") == 0) {
|
else if (tok.strValue.compare("null") == 0) {
|
||||||
tok.value = TokenV::kwNull;
|
tok.value = TokenV::kwNull;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("import") == 0) {
|
else if (tok.strValue.compare("import") == 0) {
|
||||||
tok.value = TokenV::kwImport;
|
tok.value = TokenV::kwImport;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("export") == 0) {
|
else if (tok.strValue.compare("export") == 0) {
|
||||||
tok.value = TokenV::kwExport;
|
tok.value = TokenV::kwExport;
|
||||||
}
|
}
|
||||||
else if (strToken.compare("module") == 0) {
|
else if (tok.strValue.compare("module") == 0) {
|
||||||
tok.value = TokenV::kwModule;
|
tok.value = TokenV::kwModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,7 +608,7 @@ namespace arti::lang {
|
|||||||
tok.strValue = std::string_view{ stIter, iter };
|
tok.strValue = std::string_view{ stIter, iter };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return langException<ExceptCode::ecInvalidCharacter>(
|
return langException<ExceptCode::ecInvalidToken>(
|
||||||
line,
|
line,
|
||||||
column,
|
column,
|
||||||
tok.strValue
|
tok.strValue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user