Experiments with OCaml - Part 2
Jujutsu
Ok, so it was getting a bit on my nerves that I wasn't able to cleanly do the things I wanted to. So I switched to git back. Sorry for disappointing :/ Another issue I keep running into is the fact that for some god knows what reason emacs isn't able to find the LSP in the path and I need to set it manually. It's so annoying. I'm using helix for now, as everything works out of the box for it.
Anyways, right now my main focus is getting the tests up and running. So let's see.
Setting up unit tests
Okay, so I went through the docs and saw that the tests are in a separate file in the same
directory, but that's not really my style. So I'll go with the tests being in the test/
directory.
After setting up test/dune
, I just have one question. Why do both Alcotest and OUnit2 suck so much
ass?
Okay, maybe alcotest is not so bad after all. It's a bit tedious yes, but I think that's just the module in itself.
Modules are another story
Yeah, I don't understand OCaml's module system very well. This seems to be weird that I have to copy the public types across in both the places. One suggestion online is including the ml file that contains only the types, but come on. That's so bad.
Another thing suggested is using the _intf.ml
pattern. I don't understand a thing about it. But
let's see.
Nope, that also turns out to be useless. So I am left with just one choice, and that is to put the type in a separate file of its own and including it, and then later hiding it from dune. Let's do it.
Finally, after a bit of battling, I managed to get it in. Thank goodness!
Tests and Lexing
Now back to the testing. I have a couple of tests that are ready, and just need to see what becomes of them. Alcotest is relatively simple, and it worked out pretty well. What baffled me for a moment was the test vs module in test distinction in the dune file in test directory. Anyways, it was nice, and let's move on to stream processing now. So my idea is simple, I'll do a linear pass through the string and identify the tokens. These tokens carry with them the information about their starts and ends, so we can take the substring of the string post it.
Ok, so I refactored a bunch of shit and now it looks significantly better. Along with it I also wrote the small function to parse through the entire stream at once.