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

Diff whitespace in diffables
Otherwise it might be hard to see what has changed.
Author: xaizek
Author date (UTC): 2022-07-19 16:46
Committer name: xaizek
Committer date (UTC): 2022-07-19 17:22
Parent(s): 45886d9ceff669995726196950e889d0e6a6a798
Signing key: 99DC5E4DB05F6BE2
Tree: 37f0bf086ac295cec649bf766003a3ac855a6ea9
File Lines added Lines deleted
src/Highlighter.cpp 13 4
tests/Printer.cpp 3 3
tests/alignment.cpp 2 2
tests/c/c-printing.cpp 3 3
File src/Highlighter.cpp changed (mode: 100644) (index 4b78fad..5a26594)
... ... toWords(boost::string_ref s)
613 613 return Word; return Word;
614 614 }; };
615 615
616 auto isNonWord = [](State state) {
617 return (state == Punctuation || state == WhiteSpace);
618 };
619
620 auto hasInput = [](State state) {
621 return (state != Start && state != End);
622 };
623
616 624 State currentState = Start; State currentState = Start;
617 625 std::size_t wordStart = 0U; std::size_t wordStart = 0U;
618 626 for (std::size_t i = 0U; i <= s.size(); ++i) { for (std::size_t i = 0U; i <= s.size(); ++i) {
619 627 const State newState = (i == s.size() ? End : classify(s[i])); const State newState = (i == s.size() ? End : classify(s[i]));
620 // Each punctuation character is treated as a separate "word".
621 if (currentState != newState || currentState == Punctuation) {
622 if (currentState == Punctuation || currentState == Word) {
628 // Each punctuation or whitespace character is treated as a separate
629 // "word".
630 if (currentState != newState || isNonWord(currentState)) {
631 if (hasInput(currentState)) {
623 632 words.emplace_back(s.substr(wordStart, i - wordStart)); words.emplace_back(s.substr(wordStart, i - wordStart));
624 633 } }
625 if (newState == Punctuation || newState == Word) {
634 if (hasInput(newState)) {
626 635 wordStart = i; wordStart = i;
627 636 } }
628 637 } }
File tests/Printer.cpp changed (mode: 100644) (index d0b5c24..dd8a2ea)
... ... TEST_CASE("Separators in diffable tokens are handled separately", "[printer]")
534 534 )"), true); )"), true);
535 535
536 536 std::string expected = normalizeText(R"( std::string expected = normalizeText(R"(
537 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
538 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
537 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
538 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
539 539 1 | 1 1 | 1
540 540 2 void f() { | 2 void f() { 2 void f() { | 2 void f() {
541 3 something("Destination doesn't exist"); {#~#} 3 something("Destination doesn't exist {+or+} {+not+} {+a+} {+directory+}");
541 3 something("Destination doesn't exist"); {#~#} 3 something("Destination doesn't exist{+ or not a directory+}");
542 542 4 } | 4 } 4 } | 4 }
543 543 )"); )");
544 544
File tests/alignment.cpp changed (mode: 100644) (index dd289ec..569ef93)
... ... TEST_CASE("Lines with matching nodes are aligned for multiline tokens",
236 236 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
237 237 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238 238 1 | 1 1 | 1
239 2 /* This is an example {-file-}. */ {#~#} 2 /* This {+file+} is an example {+used+}
240 - {+++} 3 {+*+} {+to+} {+compare+} {+diffs+}. */
239 2 /* This is an example {-file-}. */ {#~#} 2 /* This {+file +}is an example {+used+}
240 - {+++} 3 {+ * to compare diffs+}. */
241 241 3 int check({-int-}{- -}{-id-}, const char {~inf~}[]) { {#~#} 4 int check({+pid_t+}{+ +}{+pid+}, const char {~inf~}{+o+}[]{+,+}{+ +}{+time_t+}{+ +}{+start+}) { 3 int check({-int-}{- -}{-id-}, const char {~inf~}[]) { {#~#} 4 int check({+pid_t+}{+ +}{+pid+}, const char {~inf~}{+o+}[]{+,+}{+ +}{+time_t+}{+ +}{+start+}) {
242 242 4 int status; {#~#} 5 int status {+=+}{+ +}{+0+}; 4 int status; {#~#} 5 int status {+=+}{+ +}{+0+};
243 243 - {+++} 6 {+if+}{+ +}{+(+}{+start+}{+ +}{+!=+}{+ +}{+(+}{+time_t+}{+)+}{+-+}{+1+}{+)+}{+ +}{+{+} - {+++} 6 {+if+}{+ +}{+(+}{+start+}{+ +}{+!=+}{+ +}{+(+}{+time_t+}{+)+}{+-+}{+1+}{+)+}{+ +}{+{+}
File tests/c/c-printing.cpp changed (mode: 100644) (index de3f2d6..f478e7f)
... ... TEST_CASE("Directives are diffed", "[printer]")
30 30 ); );
31 31
32 32 std::string expected = normalizeText(R"( std::string expected = normalizeText(R"(
33 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 1 #define DEFINE (1 + 2 + 3) {#~#} 1 #define DEFINE (1 + 2 + 3 {+++} {+4+})
33 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35 1 #define DEFINE (1 + 2 + 3) {#~#} 1 #define DEFINE (1 + 2 + 3{+ + 4+})
36 36 )"); )");
37 37
38 38 REQUIRE(printed == expected); REQUIRE(printed == expected);
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