Writing a Lexer and Parser in Go - Part 2

In part one of this series I introduced the concepts around lexical analysis and parsing. We took a look at the basics behind what makes up an INI file, and started setting up structures and constants that will help us perform lexical analysis, or lexing, on an input text, which is an INI file in our case.

In part two we actually dive into the details of the process of performing a lexical analysis. Lexing is the process of converting an input text into a series of tokens. Tokens represent smaller units of the input that, when put together, become something useful, like a program, or configuration file, and more. In an INI file tokens include left bracket, right bracket, section name, key name, value, and equal sign. Put together in the correct order and you have an INI file. The job of the lexer is to read the INI file and create tokens, placing them onto a channel for a parser to pick up and do something useful with.

Writing a Lexer and Parser in Go - Part 1

In this three-part series I will talk about building a simple lexer and parser in Go. The work presented here is heavily based on a 2011 presentation by Rob Pike titled Lexical Scanning in Go. This series will conclude with a fully functional set of code that can parse INI files. The series breaks down into these three parts.

  1. Introduction to Lexing, Parsing, and Getting Started
  2. Performing Lexical Analysis
  3. Parsing the Results

Communication Is An Interesting Thing

There has been a lot of talk about effective communication in my day-to-day lately. At work I have set goals to work on improving how I communicate with coworkers and superiors. On-line I see talk in communities about how to effectively conduct discussions and dialog. In all of this it seems that being able to talk about something, convince someone, or even disseminate information can be an interesting and challenging thing.

What makes this so dang hard??

Waiting For Goroutines to Finish Running Before Exiting

Swirly Lights Image copyright Faizal Sugi

Goroutines are primitives in Google’s Go language that allow a developer to easily write concurrent applications to make use of modern multi-core CPUs. Because these are baked into the language and super easy to use it becomes simple to make quick use of them in your applications. As you start to write more sophisticated server applications you realize you need a way to gracefully exit your application. This means that you may not want your application to exit before all your Goroutines are done executing. In this entry I’ll talk about one way to handle this with a sync.WaitGroup and channels.

Using A Middleware in Your Go Web Applications

Bikes Lined Up Image copyright Ryan McGuire

Middleware in Go HTTP applications is a way to chain HTTP handlers in a sequence to alter the request and response chain prior to your primary handler getting it. This is useful for activities such as logging, input sanitization, handling authorization and security, and more. This concept is supported in the Go standard library with functions like http.StripPrefix and http.TimeoutHandler. Each of the previously mentioned functions take a reference to a handler and return a new handler, wrapping the original with its own logic and processing of the request and response chain. In this post I will show how you can use a middleware called Alice to perform this task.

My First SVN Post-Commit Hook in Go - Part 2

Talking Image copyright Ryan McGuire

This is part two of the two part series on how I created a Subversion post-commit hook using Go, and post a message in a HipChat room. This post follows part one by talking about how to post the message to HipChat. I did this for the teams at my day job. Please note that certain pieces of code have been changed to protect the innocent, and opinions here do not necessarily reflect those of my employer.

In part one of this two part series I talked about how to execute svnlook.exe on the command line using Go, then capture that output. Once captured the idea is to post a message in HipChat (or any other communication platform, should you choose to) to let teams know what code is going into a trunk/master/main/release branch. Please note that this code demonstrates consuming the HipChat API v1, which was current enough at the time I wrote this hook. HipChat has now published version 2 of their API and will deprecate version 1.

My First SVN Post-Commit Hook in Go - Part 1

Man with headphones Image copyright Ryan McGuire

This is part one of a two part series on how I created a Subversion post-commit hook using Go, and post a message in a HipChat room. I did this for the teams at my day job. Please note that certain pieces of code have been changed to protect the innocent, and opinions here do not necessarily reflect those of my employer.

There has been an ongoing effort with the various teams I work with to improve code review. To provide more visibility to code being committed to our trunk branch in Subversion I decided a post-commit hook could help us achieve that visibility. This post-commit hook would send a message to a HipChat room, dedicated to reviewing code changes and information about each commit. This would allow teams to know when changes were made to our trunk branch and have the chance to review the code across teams. This strategy has been an effective one in reducing errors in code and improving overall code quality. This post will deal with utilizing Subversion to retrieve information about a commit. This information is what will be used in part 2 to post a message in HipChat.

JavaScript Multiselect Widget, With No jQuery!

Last night I decided to write a multi-select JavaScript widget. I need such a widget to allow the users of a little app I am working on to select one or more items. I wanted it to look a little more pretty than the default <select> box and I also didn’t want to force users to have to hold CTRL to select more than one item. I did a little searching around the internet and found a number of controls that do exactly what I want, but all of them required an external library, such as jQuery, Angular, and even Mootools. This particular project is not using jQuery on purpose which makes those libraries out of the question. So I start writing my own.


Response To Adam Cameron's Code Review

A few weeks ago I submitted a response to a code puzzle on Adam Cameron’s blog that I wrote using Go. He has (finally) submitted a review! First let me say that it is about time Mr. Cameron! I have waited with bated breath! That review can be read here. In this post I will comment on his commentary.

Handling CTRL+C In Go Command Line Applications

Command line and server-style application often allow you to press a key combination, such as CTRL+C to gracefully exit. In Go this is a pretty easy task to accomplish, and in this entry I will show you how you can add this ability in your own applications.