Jay Taylor | programmer notes



Scala Diaries: Programmatically restoring sanity to sour syntax

Recently, I went a little too far with my usage of Scala’s syntactic (very sugary and sweet!) ability to allow:

to be written as:
SomeObject someFunction param

This is cool. However, it is also possible to do something which I have decided is difficult to read and understand:

SomeObject anotherFunction (param1, param2, param3)

Regretful as the situaton is, I wrote a quick line of sed to fix it in the affected files:

The first step was to identify which files had this ugliness:
jay@secretcode:~$ grep ' *[a-z0-9_.]+ +[a-z0-9_]+ +(.*,.*) *$' app/* -r -n

Then it was a matter of formulating the regular expression transform to be evaluated by sed:
jay@secretcode:~$ sed -i.bak -e 's/( *[a-z0-9_.]{1,}) {1,}([a-z0-9_]{1,}) {1,}((.*,.*) *)$/1.23/g' Perk.scala
jay@secretcode:~$ diff Perk.scala.bak Perk.scala
< val ch = ContentHelper apply (false, content.jsonData)
> val ch = ContentHelper.apply(false, content.jsonData)
< val hashtag = ch get ("hashtag", "html")
> val hashtag = ch.get("hashtag", "html")

NB: The above sed expression is compatible with both the OS-X and Linux versions of sed

Whew, catastrophe averted!

Related posts:

  1. Scala Diaries: Play Framework 2.0.x, Play SBT Plugin Breakage
  2. HOWTO: Make IntelliJ + Scala run fast/smooth on Mac OS-X

RSS Feed

No comments yet.

Leave a comment!

You must be logged in to post a comment.



Find it!