nixd
Loading...
Searching...
No Matches
nixf-tidy.cpp
Go to the documentation of this file.
1/// \file
2/// \brief nixf-tidy, provide linting based on libnixf.
3
6#include "nixf/Parse/Parser.h"
8
9#include <iostream>
10#include <sstream>
11
12using namespace nixf;
13
14namespace {
15
16/// Pretty print the output.
17bool PrettyPrint = false;
18
19/// Enable variable lookup warnings.
20bool VLA;
21
22void parseArgs(int Argc, const char *Argv[]) {
23 for (int I = 0; I < Argc; I++) {
24 if (std::string_view(Argv[I]) == "--pretty-print")
25 PrettyPrint = true;
26 else if (std::string_view(Argv[I]) == "--variable-lookup")
27 VLA = true;
28 }
29}
30
31} // namespace
32
33int main(int Argc, const char *Argv[]) {
34 parseArgs(Argc, Argv);
35 std::ostringstream Inputs;
36 Inputs << std::cin.rdbuf();
37 std::string Src = Inputs.str();
38
39 std::vector<nixf::Diagnostic> Diags;
40 std::shared_ptr<nixf::Node> AST = nixf::parse(Src, Diags);
41
42 if (VLA) {
44 if (AST)
45 V.runOnAST(*AST);
46 }
47
48 nlohmann::json V;
49 to_json(V, Diags);
50
51 if (PrettyPrint)
52 std::cout << std::setw(4);
53 std::cout << V << "\n";
54 return 0;
55}
Provide jsonified diagnostic, for other languages/structured output.
Lookup variable names, from it's parent scope.
void runOnAST(const Node &Root)
Perform variable lookup analysis (def-use) on AST.
Parser interface.
void to_json(nlohmann::json &R, const LexerCursor &LC)
std::shared_ptr< Node > parse(std::string_view Src, std::vector< Diagnostic > &Diags)
Parse a string.
int main(int Argc, const char *Argv[])
Definition nixf-tidy.cpp:33