xaizek / zograscope (License: AGPLv3 only) (since 2018-12-07)
Mainly a syntax-aware diff that also provides a number of additional tools.
Commit 2dbb98ef1a406f883b4c901f4ac777546ac17102

Add list of bad nodes to TSTransformer
These are the nodes which should be ignored.
Author: xaizek
Author date (UTC): 2022-08-01 20:54
Committer name: xaizek
Committer date (UTC): 2022-08-01 21:13
Parent(s): bf4962c08191476ce34ca0d6dfe5b50bfd9097ad
Signing key: 99DC5E4DB05F6BE2
Tree: 53f9d3a00c7a079ae57b2225c20c76af3bb36f4a
File Lines added Lines deleted
src/ts/TSTransformer.cpp 6 1
src/ts/TSTransformer.hpp 2 0
src/ts/bash/TSBashLanguage.cpp 2 1
src/ts/bash/TSBashLanguage.hpp 2 0
src/ts/lua/TSLuaLanguage.cpp 2 1
src/ts/lua/TSLuaLanguage.hpp 2 0
File src/ts/TSTransformer.cpp changed (mode: 100644) (index 6ace846..cedce55)
... ... TSTransformer::TSTransformer(const std::string &contents,
35 35 TreeBuilder &tb, TreeBuilder &tb,
36 36 const std::unordered_map<std::string, SType> &stypes, const std::unordered_map<std::string, SType> &stypes,
37 37 const std::unordered_map<std::string, Type> &types, const std::unordered_map<std::string, Type> &types,
38 const std::unordered_set<std::string> &badNodes,
38 39 int tabWidth, int tabWidth,
39 40 bool debug) bool debug)
40 41 : contents(contents), tsLanguage(tsLanguage), tb(tb), stypes(stypes), : contents(contents), tsLanguage(tsLanguage), tb(tb), stypes(stypes),
41 types(types), tabWidth(tabWidth), debug(debug)
42 types(types), badNodes(badNodes), tabWidth(tabWidth), debug(debug)
42 43 { } { }
43 44
44 45 void void
 
... ... TSTransformer::visit(const TSNode &node)
112 113 void void
113 114 TSTransformer::visitLeaf(SType stype, PNode *pnode, const TSNode &leaf) TSTransformer::visitLeaf(SType stype, PNode *pnode, const TSNode &leaf)
114 115 { {
116 if (badNodes.find(ts_node_type(leaf)) != badNodes.end()) {
117 return;
118 }
119
115 120 uint32_t from = ts_node_start_byte(leaf); uint32_t from = ts_node_start_byte(leaf);
116 121 uint32_t to = ts_node_end_byte(leaf); uint32_t to = ts_node_end_byte(leaf);
117 122
File src/ts/TSTransformer.hpp changed (mode: 100644) (index 4e843ad..c78985c)
... ... public:
40 40 TreeBuilder &tb, TreeBuilder &tb,
41 41 const std::unordered_map<std::string, SType> &stypes, const std::unordered_map<std::string, SType> &stypes,
42 42 const std::unordered_map<std::string, Type> &types, const std::unordered_map<std::string, Type> &types,
43 const std::unordered_set<std::string> &badNodes,
43 44 int tabWidth, int tabWidth,
44 45 bool debug); bool debug);
45 46
 
... ... private:
61 62 TreeBuilder &tb; // Result builder. TreeBuilder &tb; // Result builder.
62 63 const std::unordered_map<std::string, SType> &stypes; // Node type -> SType. const std::unordered_map<std::string, SType> &stypes; // Node type -> SType.
63 64 const std::unordered_map<std::string, Type> &types; // Node type -> Type. const std::unordered_map<std::string, Type> &types; // Node type -> Type.
65 const std::unordered_set<std::string> &badNodes; // Nodes to ignore.
64 66 std::unordered_set<std::string> badSTypes; // Missing stypes. std::unordered_set<std::string> badSTypes; // Missing stypes.
65 67 std::unordered_set<std::string> badTypes; // Missing types. std::unordered_set<std::string> badTypes; // Missing types.
66 68 int line; // Current line. int line; // Current line.
File src/ts/bash/TSBashLanguage.cpp changed (mode: 100644) (index 98ff740..e63dea4)
... ... TsBashLanguage::parse(const std::string &contents,
52 52 cpp17::pmr::monolithic &mr) const cpp17::pmr::monolithic &mr) const
53 53 { {
54 54 TreeBuilder tb(mr); TreeBuilder tb(mr);
55 TSTransformer t(contents, tsLanguage, tb, stypes, types, tabWidth, debug);
55 TSTransformer t(contents, tsLanguage, tb, stypes, types, badNodes, tabWidth,
56 debug);
56 57 t.transform(); t.transform();
57 58
58 59 return tb; return tb;
File src/ts/bash/TSBashLanguage.hpp changed (mode: 100644) (index 4d635d8..892adee)
18 18 #define ZOGRASCOPE__TS__BASH__TSBASHLANGUAGE_HPP__ #define ZOGRASCOPE__TS__BASH__TSBASHLANGUAGE_HPP__
19 19
20 20 #include <unordered_map> #include <unordered_map>
21 #include <unordered_set>
21 22
22 23 #include "Language.hpp" #include "Language.hpp"
23 24
 
... ... private:
89 90 const TSLanguage &tsLanguage; // Language description. const TSLanguage &tsLanguage; // Language description.
90 91 std::unordered_map<std::string, SType> stypes; // Maps nodes to STypes. std::unordered_map<std::string, SType> stypes; // Maps nodes to STypes.
91 92 std::unordered_map<std::string, Type> types; // Maps nodes to Types. std::unordered_map<std::string, Type> types; // Maps nodes to Types.
93 std::unordered_set<std::string> badNodes; // Lists nodes to ignore.
92 94 }; };
93 95
94 96 #endif // ZOGRASCOPE__TS__BASH__TSBASHLANGUAGE_HPP__ #endif // ZOGRASCOPE__TS__BASH__TSBASHLANGUAGE_HPP__
File src/ts/lua/TSLuaLanguage.cpp changed (mode: 100644) (index f6f3183..121ee6f)
... ... TsLuaLanguage::parse(const std::string &contents,
181 181 cpp17::pmr::monolithic &mr) const cpp17::pmr::monolithic &mr) const
182 182 { {
183 183 TreeBuilder tb(mr); TreeBuilder tb(mr);
184 TSTransformer t(contents, tsLanguage, tb, stypes, types, tabWidth, debug);
184 TSTransformer t(contents, tsLanguage, tb, stypes, types, badNodes, tabWidth,
185 debug);
185 186 t.transform(); t.transform();
186 187
187 188 return tb; return tb;
File src/ts/lua/TSLuaLanguage.hpp changed (mode: 100644) (index a7f2716..849268f)
18 18 #define ZOGRASCOPE__TS__LUA__TSLUALANGUAGE_HPP__ #define ZOGRASCOPE__TS__LUA__TSLUALANGUAGE_HPP__
19 19
20 20 #include <unordered_map> #include <unordered_map>
21 #include <unordered_set>
21 22
22 23 #include "Language.hpp" #include "Language.hpp"
23 24
 
... ... private:
89 90 const TSLanguage &tsLanguage; // Language description. const TSLanguage &tsLanguage; // Language description.
90 91 std::unordered_map<std::string, SType> stypes; // Maps nodes to STypes. std::unordered_map<std::string, SType> stypes; // Maps nodes to STypes.
91 92 std::unordered_map<std::string, Type> types; // Maps nodes to Types. std::unordered_map<std::string, Type> types; // Maps nodes to Types.
93 std::unordered_set<std::string> badNodes; // Lists nodes to ignore.
92 94 }; };
93 95
94 96 #endif // ZOGRASCOPE__TS__LUA__TSLUALANGUAGE_HPP__ #endif // ZOGRASCOPE__TS__LUA__TSLUALANGUAGE_HPP__
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/zograscope

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/zograscope

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master