nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
libnixf
tools
nixf-tidy.cpp
Go to the documentation of this file.
1
/// \file
2
/// \brief nixf-tidy, provide linting based on libnixf.
3
4
#include "
nixf/Basic/JSONDiagnostic.h
"
5
#include "
nixf/Basic/Nodes/Basic.h
"
6
#include "
nixf/Parse/Parser.h
"
7
#include "
nixf/Sema/VariableLookup.h
"
8
9
#include <iostream>
10
#include <sstream>
11
12
using namespace
nixf
;
13
14
namespace
{
15
16
/// Pretty print the output.
17
bool
PrettyPrint =
false
;
18
19
/// Enable variable lookup warnings.
20
bool
VLA;
21
22
void
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
33
int
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) {
43
VariableLookupAnalysis
V(Diags);
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
}
Basic.h
JSONDiagnostic.h
Provide jsonified diagnostic, for other languages/structured output.
VariableLookup.h
Lookup variable names, from it's parent scope.
nixf::VariableLookupAnalysis
Definition
VariableLookup.h:116
nixf::VariableLookupAnalysis::runOnAST
void runOnAST(const Node &Root, bool IsFlake=false)
Perform variable lookup analysis (def-use) on AST.
Definition
VariableLookup.cpp:562
Parser.h
Parser interface.
nixf
Definition
Diagnostic.h:19
nixf::to_json
void to_json(nlohmann::json &R, const LexerCursor &LC)
nixf::parse
std::shared_ptr< Node > parse(std::string_view Src, std::vector< Diagnostic > &Diags)
Parse a string.
Definition
ParseSupport.cpp:37
main
int main(int Argc, const char *Argv[])
Definition
nixf-tidy.cpp:33
Generated by
1.17.0