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

More reliable parsing of files with srcml
There are some issues/complications to work around.
Author: xaizek
Author date (UTC): 2020-03-30 16:47
Committer name: xaizek
Committer date (UTC): 2020-03-30 16:47
Parent(s): 93ad6219d98b12150facb3971a22d63b4d5c9cf2
Signing key: 99DC5E4DB05F6BE2
Tree: 6fa9eef0e5ac6d13419ee65320770c1fcccf9554
File Lines added Lines deleted
src/srcml/SrcmlTransformer.cpp 17 3
File src/srcml/SrcmlTransformer.cpp changed (mode: 100644) (index 342709f..eec97cb)
... ... SrcmlTransformer::SrcmlTransformer(const std::string &contents,
94 94 const std::unordered_set<std::string> &keywords) const std::unordered_set<std::string> &keywords)
95 95 : contents(contents), path(path), tb(tb), language(language), : contents(contents), path(path), tb(tb), language(language),
96 96 map(map), keywords(keywords) map(map), keywords(keywords)
97 {
98 }
97 { }
99 98
100 99 void void
101 100 SrcmlTransformer::transform() SrcmlTransformer::transform()
 
... ... SrcmlTransformer::transform()
117 116 std::string xml = readCommandOutput(cmd, std::string()); std::string xml = readCommandOutput(cmd, std::string());
118 117
119 118 ti::XMLDocument doc; ti::XMLDocument doc;
120 doc.Parse(xml.data(), xml.size());
119 if (doc.Parse(xml.data(), xml.size()) == ti::XML_SUCCESS &&
120 doc.RootElement() == nullptr) {
121
122 // Work around srcml's issues with parsing files. Sometimes it can't
123 // read them from file (when extension is ".z" it thinks it's an
124 // archive) and sometimes from stdin (bugs of previous versions), so try
125 // both ways.
126 cmd.pop_back();
127 xml = readCommandOutput(cmd, contents);
128 doc.Parse(xml.data(), xml.size());
129 }
130
121 131 if (doc.Error()) { if (doc.Error()) {
122 132 throw std::runtime_error("Failed to parse: " + throw std::runtime_error("Failed to parse: " +
123 133 std::string(doc.ErrorStr())); std::string(doc.ErrorStr()));
 
... ... SrcmlTransformer::transform()
134 144 PNode * PNode *
135 145 SrcmlTransformer::visit(ti::XMLNode *node, int level) SrcmlTransformer::visit(ti::XMLNode *node, int level)
136 146 { {
147 if (node == nullptr) {
148 return tb.addNode();
149 }
150
137 151 SType stype = {}; SType stype = {};
138 152 auto it = map.find(node->Value()); auto it = map.find(node->Value());
139 153 if (it != map.end()) { if (it != map.end()) {
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