Supercharging operations with Common Expression Language in the browser

For this article, I’ve asked DALL-E Mini to create a picture of an NPM library.

Finding a query language

I could’ve tried to write one of these myself. I don’t think that would’ve been a good idea.

https://xkcd.com/927/
"1 == 1"
"999u == x"
"true ? 1 : 2"
"false && 32"
"3 in [5, 4, 3, 2, 1]"

Until I made one

I installed the Myna Parser, a TypeScript library for defining custom grammars and parsing logic. Starting from the top of my grammar’s definition, I start to define a variety of parser types. They start out fairly simple, laying out how various number formats are represented in a string.

Evaluating Grammars

How do I actually make any sense of this grammar? First I need to create a text formatter. Basically, a concrete definition of how the grammar can is converted into an output.

How do I know this works?

Wow this is quite complicated. Worse, it looks fragile. A simple grammar change could result in cascading breakages.

Wrapping up

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nick Felker

Social Media Expert -- Rowan University 2017 -- IoT & Assistant @ Google