Documentation generator for C++
theangryepicbanana (1395)

This is a program that generates doc comments for C++ code! I originally made this for my CS class since we have to include documentation for functions we make. It's not 100% perfect, but it definitely helps save a lot of time.

Also if you're wondering, I made this program in Raku (aka Perl 6).

Directions:
1) Paste your C++ code into in.txt.
2) Run the program.
3) Copy the code in out.txt (which is the output).

If you have any suggestions (minus cleaning up my code because I know it's ugly/messy), just let me know down in the comments.

You are viewing a single comment. View All
StudentFires (71)

Does this actually work? It looked pretty cool, so I grabbed one of my recent C++ files, and it did nothing. I tried out my file from a larger project that simply checks if the user enters "yes" (case insensitive) and it did nothing.

My URL: https://repl.it/@StudentFires/YES0Var.

theangryepicbanana (1395)

@StudentFires did you check the out.txt file in the file tree? the only things that doesn't work right now are type constructors

StudentFires (71)

@theangryepicbanana Yeah, I did. I made sure to run the program too. I even double-checked it. Can you test it yourself using the URL I provided? I doubt any program will understand my C++ code.

theangryepicbanana (1395)

@StudentFires oh it's probably because you have the { on a new line. I didn't think to check for that

StudentFires (71)

@theangryepicbanana No, it's actualy because you're not checking for "type name(void)". Check for () || (void)

theangryepicbanana (1395)

@StudentFires Ah that would explain it then. Thanks! If you'd like, you can look at the input/output that I already provided to test

StudentFires (71)

@theangryepicbanana You're already done with this and you've already moved on, huh?

theangryepicbanana (1395)

@StudentFires No, I was just saying that in case you wanted a bigger code example. The bug should be fixed now :)

StudentFires (71)

@theangryepicbanana It doesn't catch the sign of a datatype, nor does it document lambda expressions like it does functions.

https://repl.it/@StudentFires/cpp-docgen

theangryepicbanana (1395)

@StudentFires Whoops I forgot about all of the weird integer stuff like signs. I'll try to work on that. As for lambdas, I don't really think those would count unless they're top-level declarations (and then like why would you even do that).

StudentFires (71)

@theangryepicbanana Well, they're functions anyways. I'm always explicit in their return types using -> type, so that could be documented. But this documenter needs to really understand the C++ that it's documenting. It was funny seeing your documenter say "return type {signed}" because I left off the int, as it is automatically an int.

But hey you seem to know quite a few coding/scripting languages, you don't happen to know Bash by any chance, do you?

theangryepicbanana (1395)

@StudentFires In order to have this be 100% complete, I'd have to actually treat the input as c++ rather than using super fancy regex (which I could still do, however it'd take a lot of time). I hardly know any amount of Bash, and I generally try to use similar scripting languages that are easier such as Perl and Tcl for Linux stuff, so uh no I guess.

theangryepicbanana (1395)

@StudentFires Ok special number types should be working now

StudentFires (71)

@theangryepicbanana I tried to transpile C++ to JavaScript using a "super fancy regex" once. Unexpectedly, I gave up before I got too far. Also, I was too late anyway, they'd already make asm.js and emscripten. Regexing isn't the best way to do things.

It'd help to have syntax highlighting though:
Use open "out.cpp" and slurp("in.cpp").lines

The script can be modified to accept .cpp or .cc and output the input file's type, as opposed to a simple .txt file.

StudentFires (71)

@theangryepicbanana Surprisingly, it failed on static inline const unsigned char constexpr function(void){return '6';}. Dunno why. Dunno why I ever made a function look like that though, but I bet I've done it more than once.

theangryepicbanana (1395)

@StudentFires I'm not sure what the tldr is for, but I thought it'd be easier to do it in Raku since Raku's regexes can do way more than normal regex (e.g. they can: be recursive, nest inside one another, have inline expressions). Also for the highlighting thing, my program should have highlighting unless you're on mobile. As for the other thing, I keep forgetting that other storage qualifiers exist for functions so stuff like static, inline, and constexpr don't work yet :/

StudentFires (71)

@theangryepicbanana Repl can't use C++'s syntax highlighting on a .txt file, I don't think that we're on the same page. I only code on computers, it's extremely rare that I code on a mobile, so I'm using a pc rn.

theangryepicbanana (1395)

@StudentFires oh ok. I just used a text file because I didn't really think it mattered since you can just copy/paste the contents of the file to/from your computer

StudentFires (71)

@theangryepicbanana But for someone like you, just typing it directly would be easier to test it, right? And with Repl's syntax highlighting to make sure you spelled language-specific words correctly, it'd make life much easier.

theangryepicbanana (1395)

@StudentFires I mean I guess. If you want to change that in your fork then I guess you could.