diff options
Diffstat (limited to '')
| -rw-r--r-- | src/yue.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/yue.cpp b/src/yue.cpp index 7b2ad0b..3e30c70 100644 --- a/src/yue.cpp +++ b/src/yue.cpp | |||
| @@ -113,6 +113,7 @@ int main(int narg, const char** args) { | |||
| 113 | " -s Use spaces in generated codes instead of tabs\n" | 113 | " -s Use spaces in generated codes instead of tabs\n" |
| 114 | " -p Write output to standard out\n" | 114 | " -p Write output to standard out\n" |
| 115 | " -b Dump compile time (doesn't write output)\n" | 115 | " -b Dump compile time (doesn't write output)\n" |
| 116 | " -g Dump global variables used in NAME LINE COLUMN\n" | ||
| 116 | " -l Write line numbers from source codes\n" | 117 | " -l Write line numbers from source codes\n" |
| 117 | " -v Print version\n" | 118 | " -v Print version\n" |
| 118 | #ifndef YUE_COMPILER_ONLY | 119 | #ifndef YUE_COMPILER_ONLY |
| @@ -270,6 +271,7 @@ int main(int narg, const char** args) { | |||
| 270 | config.useSpaceOverTab = false; | 271 | config.useSpaceOverTab = false; |
| 271 | bool writeToFile = true; | 272 | bool writeToFile = true; |
| 272 | bool dumpCompileTime = false; | 273 | bool dumpCompileTime = false; |
| 274 | bool lintGlobal = false; | ||
| 273 | std::string targetPath; | 275 | std::string targetPath; |
| 274 | std::string resultFile; | 276 | std::string resultFile; |
| 275 | std::string workPath; | 277 | std::string workPath; |
| @@ -380,6 +382,9 @@ int main(int narg, const char** args) { | |||
| 380 | config.reserveLineNumber = true; | 382 | config.reserveLineNumber = true; |
| 381 | } else if (arg == "-p"sv) { | 383 | } else if (arg == "-p"sv) { |
| 382 | writeToFile = false; | 384 | writeToFile = false; |
| 385 | } else if (arg == "-g"sv) { | ||
| 386 | writeToFile = false; | ||
| 387 | lintGlobal = true; | ||
| 383 | } else if (arg == "-t"sv) { | 388 | } else if (arg == "-t"sv) { |
| 384 | ++i; | 389 | ++i; |
| 385 | if (i < narg) { | 390 | if (i < narg) { |
| @@ -478,10 +483,19 @@ int main(int narg, const char** args) { | |||
| 478 | return std::tuple{1, file.first, buf.str()}; | 483 | return std::tuple{1, file.first, buf.str()}; |
| 479 | } | 484 | } |
| 480 | } | 485 | } |
| 486 | conf.lintGlobalVariable = lintGlobal; | ||
| 481 | auto result = yue::YueCompiler{YUE_ARGS}.compile(s, conf); | 487 | auto result = yue::YueCompiler{YUE_ARGS}.compile(s, conf); |
| 482 | if (result.error.empty()) { | 488 | if (result.error.empty()) { |
| 483 | if (!writeToFile) { | 489 | if (!writeToFile) { |
| 484 | return std::tuple{0, file.first, result.codes + '\n'}; | 490 | if (lintGlobal) { |
| 491 | std::ostringstream buf; | ||
| 492 | for (const auto& global : *result.globals) { | ||
| 493 | buf << global.name << ' ' << global.line << ' ' << global.col << '\n'; | ||
| 494 | } | ||
| 495 | return std::tuple{0, file.first, buf.str() + '\n'}; | ||
| 496 | } else { | ||
| 497 | return std::tuple{0, file.first, result.codes + '\n'}; | ||
| 498 | } | ||
| 485 | } else { | 499 | } else { |
| 486 | std::string targetExtension("lua"sv); | 500 | std::string targetExtension("lua"sv); |
| 487 | if (result.options) { | 501 | if (result.options) { |
