2019-07-17 22:13:52

I want to write a script that will print to a log file that tells a bunch of things like:

  • Lines in main script, and then lines in total scripts, main script+includes.

  • Same thing, but with number of chars.

  • And then stuff like total vars, total ints, strings, bools, classes, etc.

And a bunch of misc stats like that.
I also want this to work in tandom with the generate_profile function, pasting all the other stats after the info from generate_profile. But, of course, I don't want it to be deleted when generate_profile happens. Any ideas on how to write this? if it's even possible?

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-07-17 23:18:59 (edited by amerikranian 2019-07-17 23:20:32)

That can be done with a one giant loop.  I would create a loop that goes through the route of your script folder, see if there are any files with .bgt Extensions, open, and then parse them. You may also want to check for the includes folder while you’re at it.
A few things to note: I won’t tell you exactly how to parse the file, but I will give tips.
First, make sure that the loop scans through strings by looking for semicolons.  The reason why you do not want to look for new lines is this:
int x =;0double y =5.66;
While most people do not write their code like that, some may.
At this point you should have a string of text when reading a file. Now it’s simple to check what it starts with  and do things based on what is the outcome of the check. That is the most basic outline, but it should, in theory, get you started.
Functions are a little more trickier, but I will let you figure that out on your own.
Also, you may want to look at Carter’s github.  I believe he has something on there that already does what you want.

2019-07-17 23:58:17

The first part is not that hard. the second part about intigrating this with generate_profile would be extremely difficult to say the least. You don't get that much control over the BGT profiler, so you can't tell it to append rather than overwrite to a file. It also just doesn't make sense IMO, because a profile is something that is created over the course of a scripts execution. You'd have to run the script, and that script would have to already have code to generate a profile. Once ran for a bit you'd have to then kill it and rename the profile results, something no one would want in a stats application I think. You can't just run the profiler on a given script. Also, parsing it perfectly will be almost impossible because there are so many edge cases. It can be done of course, I mean just look at how cython parses code and of course how languages themselves do it, but for that kind of parsing you really need to know what your doing. Like you have to factor in quotes, different coding styles, different positions of the braces, etc etc. So unless you want to spend weeks and weeks writing this application to make it detect all the things you want it to detect, it's almost impossible to just throw something quickly together like that.

I am a web designer, and a game developer. If you wish see me at http://www.samtupy.com

2019-07-17 23:59:20

That's for python I believe. Code stats is anyway.

-
"There is beauty in simplicity."

2019-07-18 00:31:50

Its not that hard to parse a programming language, because you just need to replicate whatever the compiler does already, since the language does have a fixed syntax. All you need to do is re-implement the very same syntax rules again and e.g. create an AST (abstract syntax tree) for the code you're analyzing. It is true however that this is a rather advanced topic and I don't think that you're that advanced yet already.
Best Regards.
Hijacker

2019-07-19 08:15:22

Uhh, no? CodeStats might be written in python but it supports literally any language in existence. The idea is rather minimalistic, not taking in account syntactical intricacies for reasons already outlined here. Writing a script to do this for one language, reading through line by line and interpreting constructs meanwhile paying heed to a variety of coding styles... that's the job of a preprocessor. Then factor in the many different programming languages in use today. Sounds like a bunch of work without much info to be gained overall. You can find CodeStats here.

Mason made one that would go through all scripts, tallying up lines, strings, ints, functions, etc etc. Problem was it only conformed to his BGT coding style. If anyone still has a copy lying around, it can be broken without much effort.