Cuhdmidthiaumixcyafb
SkillsCast

Contextual: Easy compile-time checking of interpolated strings without macros!

8th December 2016 in London at Business Design Centre

There are 51 other SkillsCasts available from Scala eXchange 2016

Please log in to watch this conference skillscast.

Https s3.amazonaws.com prod.tracker2 resource 41088130 skillsmatter conference skillscast o9nohu

Interpolated strings, like the familiar `s""`, provide a convenient way to embed external DSLs in Scala source, allowing you to construct a new value at runtime from a string literal, with Scala expressions substituted within it. But unless you are prepared to implement the interpolator using a macro, the compiler provides no checks on the correctness or well-formedness of the embedded DSL.

Contextual is a small open-source library which does the heavy lifting work to make it trivial to write string interpolators which run at compile time, without requiring any macro code. A string interpolator which parses and checks a DSL at compile-time -- with its own custom error-messages -- can be written using contextual in just a few lines of ordinary "userspace" code, calling upon parsers, regular expressions or any other means to check the interpolated string.

This opens up a smorgasbord of possibilities for adding more compile-time safety to Scala code, not least the ability to introduce your own literal-like types, ranging from checked email addresses or URLs to compile-time-parsed YAML, CSS or GraphQL.

The Call for Papers is now open for Scala eXchange 2017! Submit your talk for the chance to join a stellar line-up of experts on stage. Find out more.


Get your tickets for Scala eXchange 2017!

YOU MAY ALSO LIKE:

Contextual: Easy compile-time checking of interpolated strings without macros!

Jon Pretty

Jon has been having fun riding the bleeding edge of Scala for over a decade, and he's not finished yet. While he's not travelling the world attending Scala conferences, or organizing Scala World, Jon spends his time working on a variety of open-source Scala libraries, and providing professional Scala training services.

SkillsCast

Please log in to watch this conference skillscast.

Https s3.amazonaws.com prod.tracker2 resource 41088130 skillsmatter conference skillscast o9nohu

Interpolated strings, like the familiar `s""`, provide a convenient way to embed external DSLs in Scala source, allowing you to construct a new value at runtime from a string literal, with Scala expressions substituted within it. But unless you are prepared to implement the interpolator using a macro, the compiler provides no checks on the correctness or well-formedness of the embedded DSL.

Contextual is a small open-source library which does the heavy lifting work to make it trivial to write string interpolators which run at compile time, without requiring any macro code. A string interpolator which parses and checks a DSL at compile-time -- with its own custom error-messages -- can be written using contextual in just a few lines of ordinary "userspace" code, calling upon parsers, regular expressions or any other means to check the interpolated string.

This opens up a smorgasbord of possibilities for adding more compile-time safety to Scala code, not least the ability to introduce your own literal-like types, ranging from checked email addresses or URLs to compile-time-parsed YAML, CSS or GraphQL.

The Call for Papers is now open for Scala eXchange 2017! Submit your talk for the chance to join a stellar line-up of experts on stage. Find out more.


Get your tickets for Scala eXchange 2017!

YOU MAY ALSO LIKE:

About the Speaker

Contextual: Easy compile-time checking of interpolated strings without macros!

Jon Pretty

Jon has been having fun riding the bleeding edge of Scala for over a decade, and he's not finished yet. While he's not travelling the world attending Scala conferences, or organizing Scala World, Jon spends his time working on a variety of open-source Scala libraries, and providing professional Scala training services.

Photos