diff options
author | Li Jin <dragon-fly@qq.com> | 2020-10-08 13:01:18 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2020-10-08 13:01:18 +0800 |
commit | 97bbe98289fb74c7cf2d9793b80a1a27b4146045 (patch) | |
tree | 4bee0dded55bad28f6822b6e2dd3ea5251c66ae2 /src | |
parent | 5b656d2913e4f9f0017698ec835ce4ddda1dc81f (diff) | |
download | yuescript-97bbe98289fb74c7cf2d9793b80a1a27b4146045.tar.gz yuescript-97bbe98289fb74c7cf2d9793b80a1a27b4146045.tar.bz2 yuescript-97bbe98289fb74c7cf2d9793b80a1a27b4146045.zip |
change file extension moonp.
Diffstat (limited to 'src')
-rw-r--r-- | src/MoonP/moon_compiler.cpp | 7 | ||||
-rw-r--r-- | src/MoonP/moon_compiler.h | 3 | ||||
-rw-r--r-- | src/MoonP/moonplus.cpp | 6 | ||||
-rw-r--r-- | src/MoonP/moonplus.h | 11 | ||||
-rw-r--r-- | src/MoonP/stacktraceplus.h | 2 | ||||
-rw-r--r-- | src/moonp.cpp | 8 |
6 files changed, 21 insertions, 16 deletions
diff --git a/src/MoonP/moon_compiler.cpp b/src/MoonP/moon_compiler.cpp index 8c0746f..6e7db2c 100644 --- a/src/MoonP/moon_compiler.cpp +++ b/src/MoonP/moon_compiler.cpp | |||
@@ -53,9 +53,8 @@ inline std::string s(std::string_view sv) { | |||
53 | return std::string(sv); | 53 | return std::string(sv); |
54 | } | 54 | } |
55 | 55 | ||
56 | const std::string_view version() { | 56 | const std::string_view version = "0.4.16"sv; |
57 | return "0.4.15"sv; | 57 | const std::string_view extension = "mp"sv; |
58 | } | ||
59 | 58 | ||
60 | class MoonCompilerImpl { | 59 | class MoonCompilerImpl { |
61 | public: | 60 | public: |
@@ -4926,7 +4925,7 @@ private: | |||
4926 | } | 4925 | } |
4927 | case id<macro_name_pair_t>(): { | 4926 | case id<macro_name_pair_t>(): { |
4928 | auto pair = static_cast<macro_name_pair_t*>(item); | 4927 | auto pair = static_cast<macro_name_pair_t*>(item); |
4929 | macroPairs.emplace_back(_parser.toString(pair->value->name), _parser.toString(pair->key->name)); | 4928 | macroPairs.emplace_back(_parser.toString(pair->value->name), _parser.toString(pair->key->name)); |
4930 | break; | 4929 | break; |
4931 | } | 4930 | } |
4932 | default: | 4931 | default: |
diff --git a/src/MoonP/moon_compiler.h b/src/MoonP/moon_compiler.h index 37a79bf..cb57d57 100644 --- a/src/MoonP/moon_compiler.h +++ b/src/MoonP/moon_compiler.h | |||
@@ -17,7 +17,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI | |||
17 | 17 | ||
18 | namespace MoonP { | 18 | namespace MoonP { |
19 | 19 | ||
20 | const std::string_view version(); | 20 | extern const std::string_view version; |
21 | extern const std::string_view extension; | ||
21 | 22 | ||
22 | struct MoonConfig { | 23 | struct MoonConfig { |
23 | bool lintGlobalVariable = false; | 24 | bool lintGlobalVariable = false; |
diff --git a/src/MoonP/moonplus.cpp b/src/MoonP/moonplus.cpp index cb6d3ec..c775d75 100644 --- a/src/MoonP/moonplus.cpp +++ b/src/MoonP/moonplus.cpp | |||
@@ -122,7 +122,11 @@ int luaopen_moonp(lua_State* L) { | |||
122 | lua_getfield(L, -1, "loaded"); // package loaded | 122 | lua_getfield(L, -1, "loaded"); // package loaded |
123 | lua_createtable(L, 0, 0); // package loaded moonp | 123 | lua_createtable(L, 0, 0); // package loaded moonp |
124 | lua_pushcfunction(L, moontolua); // package loaded moonp func | 124 | lua_pushcfunction(L, moontolua); // package loaded moonp func |
125 | lua_setfield(L, -2, "to_lua"); // moonp["to_lua"] = func, package loaded tb | 125 | lua_setfield(L, -2, "to_lua"); // moonp["to_lua"] = func, package loaded moonp |
126 | lua_pushlstring(L, &MoonP::version.front(), MoonP::version.size()); // package loaded moonp version | ||
127 | lua_setfield(L, -2, "version"); // loaded["version"] = version, package loaded moonp | ||
128 | lua_pushlstring(L, &MoonP::extension.front(), MoonP::extension.size()); // package loaded moonp ext | ||
129 | lua_setfield(L, -2, "extension"); // loaded["extension"] = ext, package loaded moonp | ||
126 | lua_pushcfunction(L, init_stacktraceplus); // package loaded moonp func1 | 130 | lua_pushcfunction(L, init_stacktraceplus); // package loaded moonp func1 |
127 | lua_setfield(L, -2, "load_stacktraceplus"); // moonp["load_stacktraceplus"] = func1, package loaded moonp | 131 | lua_setfield(L, -2, "load_stacktraceplus"); // moonp["load_stacktraceplus"] = func1, package loaded moonp |
128 | lua_setfield(L, -2, "moonp"); // loaded["moonp"] = moonp, package loaded | 132 | lua_setfield(L, -2, "moonp"); // loaded["moonp"] = moonp, package loaded |
diff --git a/src/MoonP/moonplus.h b/src/MoonP/moonplus.h index 83d4c75..b18ab64 100644 --- a/src/MoonP/moonplus.h +++ b/src/MoonP/moonplus.h | |||
@@ -1,4 +1,4 @@ | |||
1 | R"moonscript_codes( | 1 | R"moonplus_codes( |
2 | --[[ | 2 | --[[ |
3 | Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin | 3 | Copyright (C) 2020 by Leaf Corcoran, modified by Li Jin |
4 | 4 | ||
@@ -73,6 +73,7 @@ get_options = function(...) | |||
73 | end | 73 | end |
74 | end | 74 | end |
75 | create_moonpath = function(package_path) | 75 | create_moonpath = function(package_path) |
76 | local extension = moonp.extension | ||
76 | local moonpaths | 77 | local moonpaths |
77 | do | 78 | do |
78 | local _accum_0 = { } | 79 | local _accum_0 = { } |
@@ -87,7 +88,7 @@ create_moonpath = function(package_path) | |||
87 | _continue_0 = true | 88 | _continue_0 = true |
88 | break | 89 | break |
89 | end | 90 | end |
90 | _accum_0[_len_0] = prefix .. ".moon" | 91 | _accum_0[_len_0] = prefix .. "." .. extension |
91 | _len_0 = _len_0 + 1 | 92 | _len_0 = _len_0 + 1 |
92 | _continue_0 = true | 93 | _continue_0 = true |
93 | until true | 94 | until true |
@@ -134,7 +135,7 @@ moon_loader = function(name) | |||
134 | end | 135 | end |
135 | return res | 136 | return res |
136 | end | 137 | end |
137 | return nil, "Could not find moon file" | 138 | return nil, "Could not find moonp file" |
138 | end | 139 | end |
139 | moon_call = function(f, ...) | 140 | moon_call = function(f, ...) |
140 | local args = { | 141 | local args = { |
@@ -148,7 +149,7 @@ moon_call = function(f, ...) | |||
148 | end | 149 | end |
149 | loadstring = function(...) | 150 | loadstring = function(...) |
150 | local options, str, chunk_name, mode, env = get_options(...) | 151 | local options, str, chunk_name, mode, env = get_options(...) |
151 | chunk_name = chunk_name or "=(moonscript.loadstring)" | 152 | chunk_name = chunk_name or "=(moonplus.loadstring)" |
152 | local code, err = moonp.to_lua(str, options) | 153 | local code, err = moonp.to_lua(str, options) |
153 | if not code then | 154 | if not code then |
154 | return nil, err | 155 | return nil, err |
@@ -247,4 +248,4 @@ for k, v in pairs({ | |||
247 | }) do | 248 | }) do |
248 | moonp[k] = v | 249 | moonp[k] = v |
249 | end | 250 | end |
250 | )moonscript_codes"; | 251 | )moonplus_codes"; |
diff --git a/src/MoonP/stacktraceplus.h b/src/MoonP/stacktraceplus.h index d658c5c..e884a2c 100644 --- a/src/MoonP/stacktraceplus.h +++ b/src/MoonP/stacktraceplus.h | |||
@@ -335,7 +335,7 @@ local function getMoonLineNumber(fname, line) | |||
335 | end | 335 | end |
336 | if file_exist then | 336 | if file_exist then |
337 | local codes = moonp.read_file(file_path) | 337 | local codes = moonp.read_file(file_path) |
338 | local moonFile = codes:match("^%s*--%s*%[moon%]:%s*([^\n]*)") | 338 | local moonFile = codes:match("^%s*--%s*%[moonp%]:%s*([^\n]*)") |
339 | if moonFile then | 339 | if moonFile then |
340 | fname = moonFile:gsub("^%s*(.-)%s*$", "%1") | 340 | fname = moonFile:gsub("^%s*(.-)%s*$", "%1") |
341 | source = codes | 341 | source = codes |
diff --git a/src/moonp.cpp b/src/moonp.cpp index 68f7b10..25be015 100644 --- a/src/moonp.cpp +++ b/src/moonp.cpp | |||
@@ -174,7 +174,7 @@ int main(int narg, const char** args) { | |||
174 | break; | 174 | break; |
175 | } | 175 | } |
176 | }); | 176 | }); |
177 | std::cout << "Moonscript+ "sv << MoonP::version() << '\n'; | 177 | std::cout << "Moonscript+ "sv << MoonP::version << '\n'; |
178 | while (true) { | 178 | while (true) { |
179 | count++; | 179 | count++; |
180 | std::string codes; | 180 | std::string codes; |
@@ -366,7 +366,7 @@ int main(int narg, const char** args) { | |||
366 | std::cout << help; | 366 | std::cout << help; |
367 | return 0; | 367 | return 0; |
368 | } else if (arg == "-v"sv) { | 368 | } else if (arg == "-v"sv) { |
369 | std::cout << "Moonscript+ version: "sv << MoonP::version() << '\n'; | 369 | std::cout << "Moonscript+ version: "sv << MoonP::version << '\n'; |
370 | return 0; | 370 | return 0; |
371 | } else if (arg == "-o"sv) { | 371 | } else if (arg == "-o"sv) { |
372 | ++i; | 372 | ++i; |
@@ -382,7 +382,7 @@ int main(int narg, const char** args) { | |||
382 | if (!item.is_directory()) { | 382 | if (!item.is_directory()) { |
383 | auto ext = item.path().extension().string(); | 383 | auto ext = item.path().extension().string(); |
384 | for (char& ch : ext) ch = std::tolower(ch); | 384 | for (char& ch : ext) ch = std::tolower(ch); |
385 | if (ext == ".moon"sv) { | 385 | if (!ext.empty() && ext.substr(1) == MoonP::extension) { |
386 | files.emplace_back(item.path().string(), item.path().lexically_relative(arg).string()); | 386 | files.emplace_back(item.path().string(), item.path().lexically_relative(arg).string()); |
387 | } | 387 | } |
388 | } | 388 | } |
@@ -453,7 +453,7 @@ int main(int narg, const char** args) { | |||
453 | if (output) { | 453 | if (output) { |
454 | const auto& codes = std::get<0>(result); | 454 | const auto& codes = std::get<0>(result); |
455 | if (config.reserveLineNumber) { | 455 | if (config.reserveLineNumber) { |
456 | auto head = std::string("-- [moon]: "sv) + file.first + '\n'; | 456 | auto head = std::string("-- [moonp]: "sv) + file.first + '\n'; |
457 | output.write(head.c_str(), head.size()); | 457 | output.write(head.c_str(), head.size()); |
458 | } | 458 | } |
459 | output.write(codes.c_str(), codes.size()); | 459 | output.write(codes.c_str(), codes.size()); |