Chi Banner

Okay, I think I’m figuring this out. When I make a filler post for the streak, it should be an unabashed filler post, so I can accumulate some of the blogging time I find each day to work on a serious post (and for doing the other important stuff I should be doing!) instead of wasting it right away.

Life. I’m programming something for Dad involving a parser using Jison, and one of the tasks involved stuffing a custom lexer into the parser. I was struggling to get my custom lexer to track locations properly. I thought this might be because I didn’t properly understand which components of which location went in which variables of the lexer, which seemed to be a plausible source of trouble since I had glanced at the sample code and it seemed to have a weird half-open range of columns and lines that I didn’t understand how to mimic in my code.

Then I looked more closely at the sample code.

this.yyloc = {
    first_column: 0,
    first_line: 1,
    last_line: 1,
    last_column: 0
};

In literary terms, this is called a chiasmus — the term comes from the shape of the Greek letter χ, chi — or possibly the more specific variant antimetabole. Both of these terms are courtesy of my TIL log, 2014/11/16. (Wow, it’s been a while.)

But why would you ever build an object like this?? Why???? This pattern of declarations doesn’t belong in code. It should be banned.

So, anyway, that wasn’t the issue; the issue turned out to be that neither my code nor the parser code made defensive copies of .yylloc (the l stands for “lookahead”), so my mutations leaked into the rest of the parser. Darn. It’s my fault, but I miss the functional paradigm.

(Bonus puzzle: as you might have suspected, the title and its incorporation into the narrative is quite forced. What is its significance?)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s