diff --git a/include/.utils.hpp.kate-swp b/include/.utils.hpp.kate-swp deleted file mode 100644 index 832c508..0000000 Binary files a/include/.utils.hpp.kate-swp and /dev/null differ diff --git a/include/tokens.hpp b/include/tokens.hpp new file mode 100644 index 0000000..d01758f --- /dev/null +++ b/include/tokens.hpp @@ -0,0 +1,271 @@ +#pragma once + +#include + +namespace tokens { + +enum class Type { + + // --- sources + + SOURCE_FILE, + IMPORT, + CONSTRAINT, + + // --- definitions + + TYPE_DEFINITION, + FUNCTION_DEFINITION, + TYPECLASS_DEFINITION, + + // --- flow control + + CASE, + MATCH, + CONDITION, + LOOP, + + // --- operators + + COMMA_EXPRESSION, + OPERATOR_EXPRESSION, + + // --- continers + + BLOCK, + ARRAY, + + // --- modifiers + + RETURN, + NAME_DEFINITION, + ARRAY_ACCESS, + TUPLE_ACCESS, + LOOP_CONTROL, + REFERENCE, + SUFFIX_EXPRESSION, + + // --- other + + NAME_EXPRESSION, + CONSTRUCTOR, + LAMBDA, + + // --- type + + VARIANT_TYPE, + TUPLE_TYPE, + TYPE, + + // --- comments + + DEFINITION_INFO, + ANNOTATION_INFO, + + // --- tokens + + PLACEHOLDER, + SIMPLE_NAME_IDENTIFIER, + SIMPLE_TYPE_IDENTIFIER, + TYPECLASS_IDENTIFIER, + ARGUMENT_NAME_IDENTIFIER, + ARGUMENT_TYPE_IDENTIFIER, + ANNOTATION_IDENTIFIER, + + OPERATOR, + OPERATOR_TAIL1, + OPERATOR_TAIL2, + OPERATOR_TAIL3, + + FLOAT_NUMBER_LITERAL, + NUMBER_LITERAL, + STRING_LITERAL, + CHAR_LITERAL, + BOOL_LITERAL, + UNIT_LITERAL, + NULL_LITERAL, + + // --- + + UNDEFINED, +}; + +// --- sources + +const static std::string SOURCE_FILE = "source_file"; +const static std::string IMPORT = "import"; +const static std::string CONSTRAINT = "constraint"; + +// --- definitions + +const static std::string TYPE_DEFINITION = "type_definition"; +const static std::string FUNCTION_DEFINITION = "function_definition"; +const static std::string TYPECLASS_DEFINITION = "typeclass_definition"; + +// --- flow control + +const static std::string CASE = "case"; +const static std::string MATCH = "match"; +const static std::string CONDITION = "condition"; +const static std::string LOOP = "loop"; + +// --- operators + +const static std::string COMMA_EXPRESSION = "comma_expression"; +const static std::string OPERATOR_EXPRESSION = "operator_expression"; + +// --- continers + +const static std::string BLOCK = "block"; +const static std::string ARRAY = "array"; + +// --- modifiers + +const static std::string RETURN = "return"; +const static std::string NAME_DEFINITION = "name_definition"; +const static std::string ARRAY_ACCESS = "array_access"; +const static std::string TUPLE_ACCESS = "tuple_access"; +const static std::string LOOP_CONTROL = "loop_control"; +const static std::string REFERENCE = "reference"; +const static std::string SUFFIX_EXPRESSION = "suffix_expression"; + +// --- other + +const static std::string NAME_EXPRESSION = "name_expression"; +const static std::string CONSTRUCTOR = "constructor"; +const static std::string LAMBDA = "lambda"; + +// --- type + +const static std::string VARIANT_TYPE = "variant_type"; +const static std::string TUPLE_TYPE = "tuple_type"; +const static std::string TYPE = "type"; + +// --- comments + +const static std::string DEFINITION_INFO = "definition_info"; +const static std::string ANNOTATION_INFO = "annotation_info"; + +// --- tokens + +const static std::string PLACEHOLDER = "placeholder"; +const static std::string SIMPLE_NAME_IDENTIFIER = "simple_name_identifier"; +const static std::string SIMPLE_TYPE_IDENTIFIER = "simple_type_identifier"; +const static std::string TYPECLASS_IDENTIFIER = "typeclass_identifier"; +const static std::string ARGUMENT_NAME_IDENTIFIER = "argument_name_identifier"; +const static std::string ARGUMENT_TYPE_IDENTIFIER = "argument_type_identifier"; +const static std::string ANNOTATION_IDENTIFIER = "annotation_identifier"; + +const static std::string OPERATOR = "operator"; +const static std::string OPERATOR_TAIL1 = "operator_tail1"; +const static std::string OPERATOR_TAIL2 = "operator_tail2"; +const static std::string OPERATOR_TAIL3 = "operator_tail3"; + +const static std::string FLOAT_NUMBER_LITERAL = "float_number_literal"; +const static std::string NUMBER_LITERAL = "number_literal"; +const static std::string STRING_LITERAL = "string_literal"; +const static std::string CHAR_LITERAL = "char_literal"; +const static std::string BOOL_LITERAL = "bool_literal"; +const static std::string UNIT_LITERAL = "unit_literal"; +const static std::string NULL_LITERAL = "null_literal"; + +inline Type string_to_type(const std::string &str) { + if (str == SOURCE_FILE) { + return Type::SOURCE_FILE; + } else if (str == IMPORT) { + return Type::IMPORT; + } else if (str == CONSTRAINT) { + return Type::CONSTRAINT; + } else if (str == TYPE_DEFINITION) { + return Type::TYPE_DEFINITION; + } else if (str == FUNCTION_DEFINITION) { + return Type::FUNCTION_DEFINITION; + } else if (str == TYPECLASS_DEFINITION) { + return Type::TYPECLASS_DEFINITION; + } else if (str == CASE) { + return Type::CASE; + } else if (str == MATCH) { + return Type::MATCH; + } else if (str == CONDITION) { + return Type::CONDITION; + } else if (str == LOOP) { + return Type::LOOP; + } else if (str == COMMA_EXPRESSION) { + return Type::COMMA_EXPRESSION; + } else if (str == OPERATOR_EXPRESSION) { + return Type::OPERATOR_EXPRESSION; + } else if (str == BLOCK) { + return Type::BLOCK; + } else if (str == ARRAY) { + return Type::ARRAY; + } else if (str == RETURN) { + return Type::RETURN; + } else if (str == NAME_DEFINITION) { + return Type::NAME_DEFINITION; + } else if (str == ARRAY_ACCESS) { + return Type::ARRAY_ACCESS; + } else if (str == TUPLE_ACCESS) { + return Type::TUPLE_ACCESS; + } else if (str == LOOP_CONTROL) { + return Type::LOOP_CONTROL; + } else if (str == REFERENCE) { + return Type::REFERENCE; + } else if (str == SUFFIX_EXPRESSION) { + return Type::SUFFIX_EXPRESSION; + } else if (str == NAME_EXPRESSION) { + return Type::NAME_EXPRESSION; + } else if (str == CONSTRUCTOR) { + return Type::CONSTRUCTOR; + } else if (str == LAMBDA) { + return Type::LAMBDA; + } else if (str == VARIANT_TYPE) { + return Type::VARIANT_TYPE; + } else if (str == TUPLE_TYPE) { + return Type::TUPLE_TYPE; + } else if (str == TYPE) { + return Type::TYPE; + } else if (str == DEFINITION_INFO) { + return Type::DEFINITION_INFO; + } else if (str == ANNOTATION_INFO) { + return Type::ANNOTATION_INFO; + } else if (str == PLACEHOLDER) { + return Type::PLACEHOLDER; + } else if (str == SIMPLE_NAME_IDENTIFIER) { + return Type::SIMPLE_NAME_IDENTIFIER; + } else if (str == SIMPLE_TYPE_IDENTIFIER) { + return Type::SIMPLE_TYPE_IDENTIFIER; + } else if (str == TYPECLASS_IDENTIFIER) { + return Type::TYPECLASS_IDENTIFIER; + } else if (str == ARGUMENT_NAME_IDENTIFIER) { + return Type::ARGUMENT_NAME_IDENTIFIER; + } else if (str == ARGUMENT_TYPE_IDENTIFIER) { + return Type::ARGUMENT_TYPE_IDENTIFIER; + } else if (str == ANNOTATION_IDENTIFIER) { + return Type::ANNOTATION_IDENTIFIER; + } else if (str == OPERATOR) { + return Type::OPERATOR; + } else if (str == OPERATOR_TAIL1) { + return Type::OPERATOR_TAIL1; + } else if (str == OPERATOR_TAIL2) { + return Type::OPERATOR_TAIL2; + } else if (str == OPERATOR_TAIL3) { + return Type::OPERATOR_TAIL3; + } else if (str == FLOAT_NUMBER_LITERAL) { + return Type::FLOAT_NUMBER_LITERAL; + } else if (str == NUMBER_LITERAL) { + return Type::NUMBER_LITERAL; + } else if (str == STRING_LITERAL) { + return Type::STRING_LITERAL; + } else if (str == CHAR_LITERAL) { + return Type::CHAR_LITERAL; + } else if (str == BOOL_LITERAL) { + return Type::BOOL_LITERAL; + } else if (str == UNIT_LITERAL) { + return Type::UNIT_LITERAL; + } else if (str == NULL_LITERAL) { + return Type::NULL_LITERAL; + } + return Type::UNDEFINED; +} + +} // namespace tokens diff --git a/include/utils.hpp b/include/utils.hpp index 80f599f..6f70f09 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -1,5 +1 @@ #pragma once - -namespace utils { - optional -} // namespace utils