diff --git a/include/gp/dynamic/compiler/lexer.hpp b/include/gp/dynamic/compiler/lexer.hpp index 10aa74d..5a44337 100644 --- a/include/gp/dynamic/compiler/lexer.hpp +++ b/include/gp/dynamic/compiler/lexer.hpp @@ -352,606 +352,606 @@ inline void gr_lexer::scan_script() { }while (advance()); } - inline void gr_lexer::scan_number(){ - gr_lexeme lex = gr_lexeme(*this); - lex.is_literal = true; +inline void gr_lexer::scan_number(){ + gr_lexeme lex = gr_lexeme(*this); + lex.is_literal = true; - bool isFloat; - string buffer(_allocator); - for (;;) { - char symbol = get(); + bool isFloat; + string buffer(_allocator); + for (;;) { + char symbol = get(); - if (symbol >= '0' && symbol <= '9') - buffer.push_back(symbol); - else if (symbol == '_') { - // Do nothing, only cosmetic (e.g. 1_000_000). - } - else if (symbol == '.') { - if (isFloat) - break; - isFloat = true; - buffer.push_back(symbol); - } - else if (symbol == 'f') { - isFloat = true; - break; - } - else { - if (_current) - _current--; + if (symbol >= '0' && symbol <= '9') + buffer.push_back(symbol); + else if (symbol == '_') { + // Do nothing, only cosmetic (e.g. 1_000_000). + } + else if (symbol == '.') { + if (isFloat) break; - } + isFloat = true; + buffer.push_back(symbol); + } + else if (symbol == 'f') { + isFloat = true; + break; + } + else { + if (_current) + _current--; + break; + } - _current++; + _current++; - if (_current >= _text.size()) - break; - } + if (_current >= _text.size()) + break; } +} - inline void gr_lexer::scan_string(){ - gr_lexeme lex = gr_lexeme(*this); - lex.type = gr_lexeme_type::string_; - lex.is_literal = true; +inline void gr_lexer::scan_string(){ + gr_lexeme lex = gr_lexeme(*this); + lex.type = gr_lexeme_type::string_; + lex.is_literal = true; - gp_config::assertion(get() != '\"',"Expected \'\"\' at the beginning of the string."); - _current++; + gp_config::assertion(get() != '\"',"Expected \'\"\' at the beginning of the string."); + _current++; - string buffer(_allocator); - bool escape = false; - bool wasEscape = false; - for (;;) { - gp_config::assertion(_current >= _text.size(),"Missing \'\"\' character."); - char symbol = get(); + string buffer(_allocator); + bool escape = false; + bool wasEscape = false; + for (;;) { + gp_config::assertion(_current >= _text.size(),"Missing \'\"\' character."); + char symbol = get(); - if (symbol == '\n') { - _position_of_line = _current; - _line++; - } - else if (symbol == '\"' && (!wasEscape)) - break; - else if (symbol == '\\' && (!wasEscape)) { - escape = true; - } + if (symbol == '\n') { + _position_of_line = _current; + _line++; + } + else if (symbol == '\"' && (!wasEscape)) + break; + else if (symbol == '\\' && (!wasEscape)) { + escape = true; + } - if (!escape) { - if (!wasEscape) { - buffer.push_back(symbol); - } - else { - if (symbol == 'n') - buffer.push_back('\n'); - else - buffer.push_back(symbol); - } + if (!escape) { + if (!wasEscape) { + buffer.push_back(symbol); + } + else { + if (symbol == 'n') + buffer.push_back('\n'); + else + buffer.push_back(symbol); } - wasEscape = escape; - escape = false; - - _current++; } + wasEscape = escape; + escape = false; - lex._text_length = size_t(buffer.size() + 2u); - lex.svalue = buffer; - _lexemes.push_back(lex); + _current++; } - inline void gr_lexer::scan_operator(){ - gr_lexeme lex = gr_lexeme(*this); - lex.is_operator = true; + lex._text_length = size_t(buffer.size() + 2u); + lex.svalue = buffer; + _lexemes.push_back(lex); +} - switch (get()) { - case '{': - lex.type = gr_lexeme_type::leftCurlyBrace; - break; - case '}': - lex.type = gr_lexeme_type::rightCurlyBrace; - break; - case '(': - lex.type = gr_lexeme_type::leftParenthesis; - break; - case ')': - lex.type = gr_lexeme_type::rightParenthesis; - break; - case '[': - lex.type = gr_lexeme_type::leftBracket; - break; - case ']': - lex.type = gr_lexeme_type::rightBracket; - break; - case '.': - lex.type = gr_lexeme_type::period; +inline void gr_lexer::scan_operator(){ + gr_lexeme lex = gr_lexeme(*this); + lex.is_operator = true; + + switch (get()) { + case '{': + lex.type = gr_lexeme_type::leftCurlyBrace; + break; + case '}': + lex.type = gr_lexeme_type::rightCurlyBrace; + break; + case '(': + lex.type = gr_lexeme_type::leftParenthesis; + break; + case ')': + lex.type = gr_lexeme_type::rightParenthesis; + break; + case '[': + lex.type = gr_lexeme_type::leftBracket; + break; + case ']': + lex.type = gr_lexeme_type::rightBracket; + break; + case '.': + lex.type = gr_lexeme_type::period; + break; + case ';': + lex.type = gr_lexeme_type::semicolon; + break; + case ':': + lex.type = gr_lexeme_type::colon; + if (_current + 1 >= _text.size()) break; - case ';': - lex.type = gr_lexeme_type::semicolon; + if (get(1) == ':') { + lex.type = gr_lexeme_type::doubleColon; + lex._text_length = 2; + _current++; + } + break; + case ',': + lex.type = gr_lexeme_type::comma; + break; + case '^': + lex.type = gr_lexeme_type::power; + if (_current + 1 >= _text.size()) break; - case ':': - lex.type = gr_lexeme_type::colon; - if (_current + 1 >= _text.size()) - break; - if (get(1) == ':') { - lex.type = gr_lexeme_type::doubleColon; - lex._text_length = 2; - _current++; - } + if (get(1) == '=') { + lex.type = gr_lexeme_type::powerAssign; + lex._text_length = 2; + _current++; + } + break; + case '@': + lex.type = gr_lexeme_type::at; + break; + case '&': + lex.type = gr_lexeme_type::pointer; + break; + case '~': + lex.type = gr_lexeme_type::concatenate; + if (_current + 1 >= _text.size()) break; - case ',': - lex.type = gr_lexeme_type::comma; + if (get(1) == '=') { + lex.type = gr_lexeme_type::concatenateAssign; + lex._text_length = 2; + _current++; + } + break; + case '+': + lex.type = gr_lexeme_type::add; + if (_current + 1 >= _text.size()) break; - case '^': - lex.type = gr_lexeme_type::power; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::powerAssign; - lex._text_length = 2; - _current++; - } + switch (get(1)) { + case '=': + lex.type = gr_lexeme_type::addAssign; + lex._text_length = 2; + _current++; break; - case '@': - lex.type = gr_lexeme_type::at; + case '+': + lex.type = gr_lexeme_type::increment; + lex._text_length = 2; + _current++; break; - case '&': - lex.type = gr_lexeme_type::pointer; + default: break; - case '~': - lex.type = gr_lexeme_type::concatenate; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::concatenateAssign; - lex._text_length = 2; - _current++; - } + } + break; + case '-': + lex.type = gr_lexeme_type::substract; + if (_current + 1 >= _text.size()) break; - case '+': - lex.type = gr_lexeme_type::add; - if (_current + 1 >= _text.size()) - break; - switch (get(1)) { - case '=': - lex.type = gr_lexeme_type::addAssign; - lex._text_length = 2; - _current++; - break; - case '+': - lex.type = gr_lexeme_type::increment; - lex._text_length = 2; - _current++; - break; - default: - break; - } + switch (get(1)) { + case '=': + lex.type = gr_lexeme_type::substractAssign; + lex._text_length = 2; + _current++; break; case '-': - lex.type = gr_lexeme_type::substract; - if (_current + 1 >= _text.size()) - break; - switch (get(1)) { - case '=': - lex.type = gr_lexeme_type::substractAssign; - lex._text_length = 2; - _current++; - break; - case '-': - lex.type = gr_lexeme_type::decrement; - lex._text_length = 2; - _current++; - break; - default: - break; - } + lex.type = gr_lexeme_type::decrement; + lex._text_length = 2; + _current++; break; - case '*': - lex.type = gr_lexeme_type::multiply; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::multiplyAssign; - lex._text_length = 2; - _current++; - } + default: break; - case '/': - lex.type = gr_lexeme_type::divide; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::divideAssign; - lex._text_length = 2; - _current++; - } + } + break; + case '*': + lex.type = gr_lexeme_type::multiply; + if (_current + 1 >= _text.size()) break; - case '%': - lex.type = gr_lexeme_type::remainder; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::remainderAssign; - lex._text_length = 2; - _current++; - } + if (get(1) == '=') { + lex.type = gr_lexeme_type::multiplyAssign; + lex._text_length = 2; + _current++; + } + break; + case '/': + lex.type = gr_lexeme_type::divide; + if (_current + 1 >= _text.size()) break; - case '=': - lex.type = gr_lexeme_type::assign; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::equal; - lex._text_length = 2; - _current++; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::doubleEqual; - lex._text_length = 3; - _current++; - } - } + if (get(1) == '=') { + lex.type = gr_lexeme_type::divideAssign; + lex._text_length = 2; + _current++; + } + break; + case '%': + lex.type = gr_lexeme_type::remainder; + if (_current + 1 >= _text.size()) break; - case '<': - lex.type = gr_lexeme_type::lesser; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::lesserOrEqual; - lex._text_length = 2; - _current++; - if (_current + 1 >= _text.size()) - break; - if (get(1) == '>') { - lex.type = gr_lexeme_type::threeWayComparison; - lex._text_length = 3; - _current++; - } - } - else if (get(1) == '-') { - lex.type = gr_lexeme_type::send; - lex._text_length = 2; - _current++; - } - else if (get(1) == '<') { - lex.type = gr_lexeme_type::leftShift; - lex._text_length = 2; - _current++; - } + if (get(1) == '=') { + lex.type = gr_lexeme_type::remainderAssign; + lex._text_length = 2; + _current++; + } + break; + case '=': + lex.type = gr_lexeme_type::assign; + if (_current + 1 >= _text.size()) break; - case '>': - lex.type = gr_lexeme_type::greater; + if (get(1) == '=') { + lex.type = gr_lexeme_type::equal; + lex._text_length = 2; + _current++; if (_current + 1 >= _text.size()) break; if (get(1) == '=') { - lex.type = gr_lexeme_type::greaterOrEqual; - lex._text_length = 2; - _current++; - } - else if (get(1) == '>') { - lex.type = gr_lexeme_type::rightShift; - lex._text_length = 2; + lex.type = gr_lexeme_type::doubleEqual; + lex._text_length = 3; _current++; } + } + break; + case '<': + lex.type = gr_lexeme_type::lesser; + if (_current + 1 >= _text.size()) break; - case '!': - lex.type = gr_lexeme_type::not_; + if (get(1) == '=') { + lex.type = gr_lexeme_type::lesserOrEqual; + lex._text_length = 2; + _current++; if (_current + 1 >= _text.size()) break; - if (get(1) == '=') { - lex.type = gr_lexeme_type::notEqual; - lex._text_length = 2; + if (get(1) == '>') { + lex.type = gr_lexeme_type::threeWayComparison; + lex._text_length = 3; _current++; } + } + else if (get(1) == '-') { + lex.type = gr_lexeme_type::send; + lex._text_length = 2; + _current++; + } + else if (get(1) == '<') { + lex.type = gr_lexeme_type::leftShift; + lex._text_length = 2; + _current++; + } + break; + case '>': + lex.type = gr_lexeme_type::greater; + if (_current + 1 >= _text.size()) break; - default: - gp_config::assertion(false, "GrLexer: invalid operator"); + if (get(1) == '=') { + lex.type = gr_lexeme_type::greaterOrEqual; + lex._text_length = 2; + _current++; } - - _lexemes.push_back(lex); + else if (get(1) == '>') { + lex.type = gr_lexeme_type::rightShift; + lex._text_length = 2; + _current++; + } + break; + case '!': + lex.type = gr_lexeme_type::not_; + if (_current + 1 >= _text.size()) + break; + if (get(1) == '=') { + lex.type = gr_lexeme_type::notEqual; + lex._text_length = 2; + _current++; + } + break; + default: + gp_config::assertion(false, "GrLexer: invalid operator"); } - namespace _hidden { - bool operator==(const gp::vector& lhs, const char* rhs) { - for(size_t index = 0; index < lhs.size() && rhs[index] != 0; index++){ - if(lhs[index] != rhs[index]) return false; - } - return true; + _lexemes.push_back(lex); +} + +namespace _hidden { + bool operator==(const gp::vector& lhs, const char* rhs) { + for(size_t index = 0; index < lhs.size() && rhs[index] != 0; index++){ + if(lhs[index] != rhs[index]) return false; } + return true; } +} - inline void gr_lexer::scan_word(){ - gr_lexeme lex = gr_lexeme(*this); - lex.is_keyword = true; - - string symbol_buffer(_allocator); - for (;;) { - if (_current >= _text.size()) - break; +inline void gr_lexer::scan_word(){ + gr_lexeme lex = gr_lexeme(*this); + lex.is_keyword = true; - char symbol = get(); - if (symbol == '!' || symbol == '?') { - symbol_buffer.push_back(symbol); - _current++; - break; - } - if (symbol <= '&' || (symbol >= '(' && symbol <= '/') || (symbol >= ':' - && symbol <= '@') || (symbol >= '[' && symbol <= '^') - || (symbol >= '{' && symbol <= 0x7F)) - break; + string symbol_buffer(_allocator); + for (;;) { + if (_current >= _text.size()) + break; + char symbol = get(); + if (symbol == '!' || symbol == '?') { symbol_buffer.push_back(symbol); _current++; + break; } - _current--; + if (symbol <= '&' || (symbol >= '(' && symbol <= '/') || (symbol >= ':' + && symbol <= '@') || (symbol >= '[' && symbol <= '^') + || (symbol >= '{' && symbol <= 0x7F)) + break; - lex._text_length = symbol_buffer.size(); + symbol_buffer.push_back(symbol); + _current++; + } + _current--; - using namespace _hidden; + lex._text_length = symbol_buffer.size(); - if(symbol_buffer == "use"){ - scan_use(); - return; - } - else if(symbol_buffer == "pub"){ - lex.type = gr_lexeme_type::public_; - } - else if(symbol_buffer == "main"){ - lex.type = gr_lexeme_type::main_; - } - else if(symbol_buffer == "type"){ - lex.type = gr_lexeme_type::type_; - } - else if(symbol_buffer == "event"){ - lex.type = gr_lexeme_type::event_; - } - else if(symbol_buffer == "class"){ - lex.type = gr_lexeme_type::class_; - } - else if(symbol_buffer == "enum"){ - lex.type = gr_lexeme_type::enum_; - } - else if(symbol_buffer == "template"){ - lex.type = gr_lexeme_type::template_; - } - else if(symbol_buffer == "if"){ - lex.type = gr_lexeme_type::if_; - } - else if(symbol_buffer == "unless"){ - lex.type = gr_lexeme_type::unless; - } - else if(symbol_buffer == "else"){ - lex.type = gr_lexeme_type::else_; - } - else if(symbol_buffer == "switch"){ - lex.type = gr_lexeme_type::switch_; - } - else if(symbol_buffer == "select"){ - lex.type = gr_lexeme_type::select; - } - else if(symbol_buffer == "case"){ - lex.type = gr_lexeme_type::case_; - } - else if(symbol_buffer == "while"){ - lex.type = gr_lexeme_type::while_; - } - else if(symbol_buffer == "do"){ - lex.type = gr_lexeme_type::do_; - } - else if(symbol_buffer == "until"){ - lex.type = gr_lexeme_type::until; - } - else if(symbol_buffer == "for"){ - lex.type = gr_lexeme_type::for_; - } - else if(symbol_buffer == "loop"){ - lex.type = gr_lexeme_type::loop; - } - else if(symbol_buffer == "return"){ - lex.type = gr_lexeme_type::return_; - } - else if(symbol_buffer == "self"){ - lex.type = gr_lexeme_type::self; - } - else if(symbol_buffer == "kill"){ - lex.type = gr_lexeme_type::kill; - } - else if(symbol_buffer == "killall"){ - lex.type = gr_lexeme_type::killAll; - } - else if(symbol_buffer == "yield"){ - lex.type = gr_lexeme_type::yield; - } - else if(symbol_buffer == "break"){ - lex.type = gr_lexeme_type::break_; - } - else if(symbol_buffer == "continue"){ - lex.type = gr_lexeme_type::continue_; - } - else if(symbol_buffer == "as"){ - lex.type = gr_lexeme_type::as; - } - else if(symbol_buffer == "try"){ - lex.type = gr_lexeme_type::try_; - } - else if(symbol_buffer == "catch"){ - lex.type = gr_lexeme_type::catch_; - } - else if(symbol_buffer == "raise"){ - lex.type = gr_lexeme_type::raise_; - } - else if(symbol_buffer == "defer"){ - lex.type = gr_lexeme_type::defer; - } - else if(symbol_buffer == "task"){ - lex.type = gr_lexeme_type::taskType; - lex.is_type = true; - } - else if(symbol_buffer == "func"){ - lex.type = gr_lexeme_type::functionType; - lex.is_type = true; - } - else if(symbol_buffer == "int"){ - lex.type = gr_lexeme_type::intType; - lex.is_type = true; - } - else if(symbol_buffer == "float"){ - lex.type = gr_lexeme_type::floatType; - lex.is_type = true; - } - else if(symbol_buffer == "bool"){ - lex.type = gr_lexeme_type::boolType; - lex.is_type = true; - } - else if(symbol_buffer == "string"){ - lex.type = gr_lexeme_type::stringType; - lex.is_type = true; - } - else if(symbol_buffer == "array"){ - lex.type = gr_lexeme_type::arrayType; - lex.is_type = true; - } - else if(symbol_buffer == "chan"){ - lex.type = gr_lexeme_type::chanType; - lex.is_type = true; - } - else if(symbol_buffer == "new"){ - lex.type = gr_lexeme_type::new_; - lex.is_type = false; - } - else if(symbol_buffer == "let"){ - lex.type = gr_lexeme_type::autoType; - lex.is_type = false; - } - else if(symbol_buffer == "true"){ - lex.type = gr_lexeme_type::boolean; - lex.is_keyword = false; - lex.is_literal = true; - lex.bvalue = true; - } - else if(symbol_buffer == "false"){ - lex.type = gr_lexeme_type::boolean; - lex.is_keyword = false; - lex.is_literal = true; - lex.bvalue = false; - } - else if(symbol_buffer == "null"){ - lex.type = gr_lexeme_type::null_; - lex.is_keyword = false; - lex.is_literal = true; - } - else if(symbol_buffer == "not"){ - lex.type = gr_lexeme_type::not_; - lex.is_keyword = false; - lex.is_operator = true; - } - else if(symbol_buffer == "and"){ - lex.type = gr_lexeme_type::and_; - lex.is_keyword = false; - lex.is_operator = true; - } - else if(symbol_buffer == "or"){ - lex.type = gr_lexeme_type::or_; - lex.is_keyword = false; - lex.is_operator = true; - } - else if(symbol_buffer == "xor"){ - lex.type = gr_lexeme_type::xor_; - lex.is_keyword = false; - lex.is_operator = true; - } else { - lex.is_keyword = false; - lex.type = gr_lexeme_type::identifier; - lex.svalue = symbol_buffer; - } + using namespace _hidden; - _lexemes.push_back(lex); + if(symbol_buffer == "use"){ + scan_use(); + return; } - - inline string gr_lexer::convert_path_to_import(string& path) { - return path; - } - - inline void gr_lexer::scan_file(gp::vector& file_name){ - _files_to_import.push_back(file_name); - - while (_files_to_import.size()) { - _file = _files_to_import[_files_to_import.size()-1]; - _files_imported.push_back(_file); - _text = file_loader(file_name); - _files_to_import.pop_back(); - - _line = 0u; - _current = 0u; - _lines = gp::vector(_allocator); - - gp::vector tmp(_allocator); - for(char c : _text) { - if(c == '\n') { - _lines.push_back(tmp); - tmp = gp::vector(_allocator); - } else { - tmp.push_back(c); - } - } + else if(symbol_buffer == "pub"){ + lex.type = gr_lexeme_type::public_; + } + else if(symbol_buffer == "main"){ + lex.type = gr_lexeme_type::main_; + } + else if(symbol_buffer == "type"){ + lex.type = gr_lexeme_type::type_; + } + else if(symbol_buffer == "event"){ + lex.type = gr_lexeme_type::event_; + } + else if(symbol_buffer == "class"){ + lex.type = gr_lexeme_type::class_; + } + else if(symbol_buffer == "enum"){ + lex.type = gr_lexeme_type::enum_; + } + else if(symbol_buffer == "template"){ + lex.type = gr_lexeme_type::template_; + } + else if(symbol_buffer == "if"){ + lex.type = gr_lexeme_type::if_; + } + else if(symbol_buffer == "unless"){ + lex.type = gr_lexeme_type::unless; + } + else if(symbol_buffer == "else"){ + lex.type = gr_lexeme_type::else_; + } + else if(symbol_buffer == "switch"){ + lex.type = gr_lexeme_type::switch_; + } + else if(symbol_buffer == "select"){ + lex.type = gr_lexeme_type::select; + } + else if(symbol_buffer == "case"){ + lex.type = gr_lexeme_type::case_; + } + else if(symbol_buffer == "while"){ + lex.type = gr_lexeme_type::while_; + } + else if(symbol_buffer == "do"){ + lex.type = gr_lexeme_type::do_; + } + else if(symbol_buffer == "until"){ + lex.type = gr_lexeme_type::until; + } + else if(symbol_buffer == "for"){ + lex.type = gr_lexeme_type::for_; + } + else if(symbol_buffer == "loop"){ + lex.type = gr_lexeme_type::loop; + } + else if(symbol_buffer == "return"){ + lex.type = gr_lexeme_type::return_; + } + else if(symbol_buffer == "self"){ + lex.type = gr_lexeme_type::self; + } + else if(symbol_buffer == "kill"){ + lex.type = gr_lexeme_type::kill; + } + else if(symbol_buffer == "killall"){ + lex.type = gr_lexeme_type::killAll; + } + else if(symbol_buffer == "yield"){ + lex.type = gr_lexeme_type::yield; + } + else if(symbol_buffer == "break"){ + lex.type = gr_lexeme_type::break_; + } + else if(symbol_buffer == "continue"){ + lex.type = gr_lexeme_type::continue_; + } + else if(symbol_buffer == "as"){ + lex.type = gr_lexeme_type::as; + } + else if(symbol_buffer == "try"){ + lex.type = gr_lexeme_type::try_; + } + else if(symbol_buffer == "catch"){ + lex.type = gr_lexeme_type::catch_; + } + else if(symbol_buffer == "raise"){ + lex.type = gr_lexeme_type::raise_; + } + else if(symbol_buffer == "defer"){ + lex.type = gr_lexeme_type::defer; + } + else if(symbol_buffer == "task"){ + lex.type = gr_lexeme_type::taskType; + lex.is_type = true; + } + else if(symbol_buffer == "func"){ + lex.type = gr_lexeme_type::functionType; + lex.is_type = true; + } + else if(symbol_buffer == "int"){ + lex.type = gr_lexeme_type::intType; + lex.is_type = true; + } + else if(symbol_buffer == "float"){ + lex.type = gr_lexeme_type::floatType; + lex.is_type = true; + } + else if(symbol_buffer == "bool"){ + lex.type = gr_lexeme_type::boolType; + lex.is_type = true; + } + else if(symbol_buffer == "string"){ + lex.type = gr_lexeme_type::stringType; + lex.is_type = true; + } + else if(symbol_buffer == "array"){ + lex.type = gr_lexeme_type::arrayType; + lex.is_type = true; + } + else if(symbol_buffer == "chan"){ + lex.type = gr_lexeme_type::chanType; + lex.is_type = true; + } + else if(symbol_buffer == "new"){ + lex.type = gr_lexeme_type::new_; + lex.is_type = false; + } + else if(symbol_buffer == "let"){ + lex.type = gr_lexeme_type::autoType; + lex.is_type = false; + } + else if(symbol_buffer == "true"){ + lex.type = gr_lexeme_type::boolean; + lex.is_keyword = false; + lex.is_literal = true; + lex.bvalue = true; + } + else if(symbol_buffer == "false"){ + lex.type = gr_lexeme_type::boolean; + lex.is_keyword = false; + lex.is_literal = true; + lex.bvalue = false; + } + else if(symbol_buffer == "null"){ + lex.type = gr_lexeme_type::null_; + lex.is_keyword = false; + lex.is_literal = true; + } + else if(symbol_buffer == "not"){ + lex.type = gr_lexeme_type::not_; + lex.is_keyword = false; + lex.is_operator = true; + } + else if(symbol_buffer == "and"){ + lex.type = gr_lexeme_type::and_; + lex.is_keyword = false; + lex.is_operator = true; + } + else if(symbol_buffer == "or"){ + lex.type = gr_lexeme_type::or_; + lex.is_keyword = false; + lex.is_operator = true; + } + else if(symbol_buffer == "xor"){ + lex.type = gr_lexeme_type::xor_; + lex.is_keyword = false; + lex.is_operator = true; + } else { + lex.is_keyword = false; + lex.type = gr_lexeme_type::identifier; + lex.svalue = symbol_buffer; + } + + _lexemes.push_back(lex); +} - scan_script(); +inline string gr_lexer::convert_path_to_import(string& path) { + return path; +} - _file_id++; +inline void gr_lexer::scan_file(gp::vector& file_name){ + _files_to_import.push_back(file_name); + + while (_files_to_import.size()) { + _file = _files_to_import[_files_to_import.size()-1]; + _files_imported.push_back(_file); + _text = file_loader(file_name); + _files_to_import.pop_back(); + + _line = 0u; + _current = 0u; + _lines = gp::vector(_allocator); + + gp::vector tmp(_allocator); + for(char c : _text) { + if(c == '\n') { + _lines.push_back(tmp); + tmp = gp::vector(_allocator); + } else { + tmp.push_back(c); + } } - } - inline void gr_lexer::scan_file_path(){ - gp_config::assertion(get() != '\"', "Expected \'\"\' at the beginning of the import."); - _current++; + scan_script(); - string buffer(_allocator); - for (;;) { - gp_config::assertion(_current >= _text.size(), "Missing \'\"\' character."); - char symbol = get(); - if (symbol == '\n') { - _position_of_line = _current; - _line++; - } - else if (symbol == '\"') - break; + _file_id++; + } +} - buffer.push_back(symbol); - _current++; - } - buffer = convert_path_to_import(buffer); +inline void gr_lexer::scan_file_path(){ + gp_config::assertion(get() != '\"', "Expected \'\"\' at the beginning of the import."); + _current++; - for(auto& file : _files_imported) { - if(file == buffer) return; - } - for(auto& file : _files_to_import) { - if(file == buffer) return; + string buffer(_allocator); + for (;;) { + gp_config::assertion(_current >= _text.size(), "Missing \'\"\' character."); + char symbol = get(); + if (symbol == '\n') { + _position_of_line = _current; + _line++; } + else if (symbol == '\"') + break; - _files_to_import.push_back(buffer); + buffer.push_back(symbol); + _current++; } + buffer = convert_path_to_import(buffer); - inline void gr_lexer::scan_use(){ - advance(); + for(auto& file : _files_imported) { + if(file == buffer) return; + } + for(auto& file : _files_to_import) { + if(file == buffer) return; + } - // Multiple files import. - if (get() == '{') { - advance(); - bool isFirst = true; - for (;;) { - if (isFirst) - isFirst = false; - else if (get() == '\"') - advance(); - else - gp_config::assertion(false, "Missing \'}\' after import list."); - // EOF - gp_config::assertion(_current >= _text.size(), "Missing \'}\' after import list."); - // End of the import list. - if (get() == '}') - break; - // Scan - scan_file_path(); - } - } - else { + _files_to_import.push_back(buffer); +} + +inline void gr_lexer::scan_use(){ + advance(); + + // Multiple files import. + if (get() == '{') { + advance(); + bool isFirst = true; + for (;;) { + if (isFirst) + isFirst = false; + else if (get() == '\"') + advance(); + else + gp_config::assertion(false, "Missing \'}\' after import list."); + // EOF + gp_config::assertion(_current >= _text.size(), "Missing \'}\' after import list."); + // End of the import list. + if (get() == '}') + break; + // Scan scan_file_path(); } } + else { + scan_file_path(); + } +}