Forums : The Ohcount Project

Dear Open Hub Users,

We’re excited to announce that we will be moving the Open Hub Forum to https://community.blackduck.com/s/black-duck-open-hub. Beginning immediately, users can head over, register, get technical help and discuss issue pertinent to the Open Hub. Registered users can also subscribe to Open Hub announcements here.


On May 1, 2020, we will be freezing https://www.openhub.net/forums and users will not be able to create new discussions. If you have any questions and concerns, please email us at [email protected]

Adding Forth

I'd like to add Forth to Ohcount. I browsed the Detector and Parser html docs, briefly I admit, and I have some questions about how I might go.

On the detector side, there are two popular extensions: 4th and fs. There's no problem with the former, but fs is also used by F#. I briefly considered ignoring it, but I checked OpenBios to see what extension it uses, and it is fs.

So, how do I handle this conflict? The html docs doesn't even begin to cover this.

On the parser side, the problem consists in the fact that Forth doesn't really have a grammar. It's impossible to parse it -- you have to run the code to make any sense out of it.

I can make an approximation for space, comments numbers and anything else, though it's guaranteed not to be accurate. What I can't do is make any parser that will identify Forth code as such, which brings me back to the .fs extension, in a way.

So, in addition to helping me with the .fs issue, any comments that might help?

Daniel Capo Sobral over 15 years ago
 

Conflicts on filename extentions are pretty common. Ohcount has a whole battery of functions named disambiguate_* whose purpose is to guess which language is actually used inside a file.

In this case, I think the best strategy would be to quickly grep through the *.fs files and look for F# keywords. If you find multiple such keywords, it's likely that the file is F# and not Forth.

I think an approximate Forth line counter is better than no line counter at all. I think it's fine to begin with some reasonable attempt that gets it mostly right.

Robin Luckey over 15 years ago