diff options
Diffstat (limited to '')
| -rwxr-xr-x | src/yuescript/yue_parser.cpp | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/src/yuescript/yue_parser.cpp b/src/yuescript/yue_parser.cpp index 66043d3..94ce550 100755 --- a/src/yuescript/yue_parser.cpp +++ b/src/yuescript/yue_parser.cpp | |||
| @@ -11,25 +11,24 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
| 11 | namespace pl = parserlib; | 11 | namespace pl = parserlib; |
| 12 | 12 | ||
| 13 | namespace yue { | 13 | namespace yue { |
| 14 | using namespace std::string_view_literals; | ||
| 15 | 14 | ||
| 16 | std::unordered_set<std::string> LuaKeywords = { | 15 | std::unordered_set<std::string> LuaKeywords = { |
| 17 | "and", "break", "do", "else", "elseif", | 16 | "and"s, "break"s, "do"s, "else"s, "elseif"s, |
| 18 | "end", "false", "for", "function", "goto", | 17 | "end"s, "false"s, "for"s, "function"s, "goto"s, |
| 19 | "if", "in", "local", "nil", "not", | 18 | "if"s, "in"s, "local"s, "nil"s, "not"s, |
| 20 | "or", "repeat", "return", "then", "true", | 19 | "or"s, "repeat"s, "return"s, "then"s, "true"s, |
| 21 | "until", "while" | 20 | "until"s, "while"s |
| 22 | }; | 21 | }; |
| 23 | 22 | ||
| 24 | std::unordered_set<std::string> Keywords = { | 23 | std::unordered_set<std::string> Keywords = { |
| 25 | "and", "break", "do", "else", "elseif", | 24 | "and"s, "break"s, "do"s, "else"s, "elseif"s, |
| 26 | "end", "false", "for", "function", "goto", | 25 | "end"s, "false"s, "for"s, "function"s, "goto"s, |
| 27 | "if", "in", "local", "nil", "not", | 26 | "if"s, "in"s, "local"s, "nil"s, "not"s, |
| 28 | "or", "repeat", "return", "then", "true", | 27 | "or"s, "repeat"s, "return"s, "then"s, "true"s, |
| 29 | "until", "while", // Lua keywords | 28 | "until"s, "while"s, // Lua keywords |
| 30 | "as", "class", "continue", "export", "extends", | 29 | "as"s, "class"s, "continue"s, "export"s, "extends"s, |
| 31 | "from", "global", "import", "macro", "switch", | 30 | "from"s, "global"s, "import"s, "macro"s, "switch"s, |
| 32 | "try", "unless", "using", "when", "with" // Yue keywords | 31 | "try"s, "unless"s, "using"s, "when"s, "with"s // Yue keywords |
| 33 | }; | 32 | }; |
| 34 | 33 | ||
| 35 | YueParser::YueParser() { | 34 | YueParser::YueParser() { |
| @@ -86,7 +85,7 @@ YueParser::YueParser() { | |||
| 86 | if (isValid) { | 85 | if (isValid) { |
| 87 | if (st->buffer == st->moduleName) { | 86 | if (st->buffer == st->moduleName) { |
| 88 | st->moduleFix++; | 87 | st->moduleFix++; |
| 89 | st->moduleName = std::string("_module_"sv) + std::to_string(st->moduleFix); | 88 | st->moduleName = "_module_"s + std::to_string(st->moduleFix); |
| 90 | } | 89 | } |
| 91 | } | 90 | } |
| 92 | st->buffer.clear(); | 91 | st->buffer.clear(); |
| @@ -179,10 +178,15 @@ YueParser::YueParser() { | |||
| 179 | 178 | ||
| 180 | local_flag = expr('*') | expr('^'); | 179 | local_flag = expr('*') | expr('^'); |
| 181 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); | 180 | local_values = NameList >> -(sym('=') >> (TableBlock | ExpListLow)); |
| 182 | Attrib = (expr("const") | expr("close")) >> not_(AlphaNum); | ||
| 183 | Local = key("local") >> (Space >> local_flag | local_values); | 181 | Local = key("local") >> (Space >> local_flag | local_values); |
| 184 | 182 | ||
| 185 | LocalAttrib = Attrib >> NameList >> Assign; | 183 | const_attrib = key("const"); |
| 184 | close_attrib = key("close"); | ||
| 185 | local_const_item = (Space >> Variable | simple_table | TableLit); | ||
| 186 | LocalAttrib = ( | ||
| 187 | const_attrib >> Seperator >> local_const_item >> *(sym(',') >> local_const_item) | | ||
| 188 | close_attrib >> Seperator >> Space >> Variable >> *(sym(',') >> Space >> Variable) | ||
| 189 | ) >> Assign; | ||
| 186 | 190 | ||
| 187 | colon_import_name = sym('\\') >> Space >> Variable; | 191 | colon_import_name = sym('\\') >> Space >> Variable; |
| 188 | ImportName = colon_import_name | Space >> Variable; | 192 | ImportName = colon_import_name | Space >> Variable; |
| @@ -754,6 +758,10 @@ std::string ParseInfo::errorMessage(std::string_view msg, const input_range* loc | |||
| 754 | ++it; | 758 | ++it; |
| 755 | } | 759 | } |
| 756 | auto line = Converter{}.to_bytes(std::wstring(begin, end)); | 760 | auto line = Converter{}.to_bytes(std::wstring(begin, end)); |
| 761 | while (col < static_cast<int>(line.size()) | ||
| 762 | && (line[col] == ' ' || line[col] == '\t')) { | ||
| 763 | col++; | ||
| 764 | } | ||
| 757 | Utils::replace(line, "\t"sv, " "sv); | 765 | Utils::replace(line, "\t"sv, " "sv); |
| 758 | std::ostringstream buf; | 766 | std::ostringstream buf; |
| 759 | buf << loc->m_begin.m_line << ": "sv << msg << | 767 | buf << loc->m_begin.m_line << ": "sv << msg << |
