Now that we've entered 2019, I'm looking back at the past year, realizing that I have a lot of programming projects which I have yet to write about here on Steemit. On that note, I would like to share one of my latest projects, one i just recently finished.
I've been writing a lot of Gremlin code over the past few months, and despite the extensive Apache Tinkerpop documentation, there seems to be some mixed opinions about how to format the queries. In hopes of arriving at something which could be considered somewhat of a standard, I decided to spend a few days of this Christmas to write a Gremlin code formater.
Usually, when developing small widgets, I like to stick to a single HTML document containing all the JavaScript, HTML and CSS in a single file. I know this might not be the cleanest approach, but when it comes to open source software, I know that the chance of the code ever being used (or even tested) by someone else, quickly goes to zero if they are not able to easily run the code. Sticking to a single HTML file enables people to simply paste the code onto their website, or easily run the code locally opening it in a browser.
Having little experience with parsers (except from that time when we were encouraged to program the Oz programming language inside the Oz programming language...), I was a bit unsure about what approach to take. I considered taking a very functional approach, using multiple maps and filters, but in the end I realized that the formatting of each line depended very much on the previously formatted lines, so I decided to just parse the queries one character at a time, while simultaneously keeping a set of counters for unclosed parentesis, unclosed comments, unclosed strings, and so on.
The formatter would make sure to vertically align lines, properly indent nested method calls, add consistent quotes, and color code strings, parameters and comments.
A complicating factor I initially underestimated was the fact that Gremlin queries can contain Groovy code. Groovy is very different from Gremlin when it comes to parsing. The structure of a Gremlin query is very simple, so for instance, all whitespaces which are not inside a String can be removed, and the query will still work as before. Realizing that writing a separate formatter for Groovy would be a huge endeavor, I decided to simply retain the formatting of the parts of the queries which consist of Groovy. After all, I was writing a Gremlin formatter.
My iterative parsing approach scaled very quickly, and I suddenly found myself with a single function spanning 250 lines. Woops. But it works. For now.
Well, anyways, since I had made a linter/formatter for Gremlin, I decided to name it Gremlint. It's a pun.
It turns out that gremlint.com was available, so I bought it and put my freshly built formater online.
I had a lot of fun drawing small gremlin cartoons to fill the webpage.
Now that I had a website, I might as well write a Gremlin style guide to give the impression that I have some kind of authority in the Gremlin community.
The style guide is still very much a work in progress, but it would be fun to be the author of the world's best Gremlin style guide. It's such a niche market that I think it is very much possible.
If you want to checkout the Gremlint GitHub repo, you can do so here: https://github.com/OyvindSabo/gremlint
If you want to checkout the Gremlin Style Guide Github repo, you can do so here: https://github.com/OyvindSabo/gremlin-style-guide
Honor to you brother. It is not easy to find motivation for programming projects. Good for you for being able to smack em around a bit.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @oyvindsabo! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit