21
Scala Diaries: Programmatically restoring sanity to sour syntax
0 Comments | Posted by outtatime in Uncategorized
Recently, I went a little too far with my usage of Scala’s syntactic (very sugary and sweet!) ability to allow:
SomeObject.someFunction(param)
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
114c114
< val ch = ContentHelper apply (false, content.jsonData)
---
> val ch = ContentHelper.apply(false, content.jsonData)
137c137
< 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:
- Scala Diaries: Play Framework 2.0.x, Play SBT Plugin Breakage
- HOWTO: Make IntelliJ + Scala run fast/smooth on Mac OS-X
No comments yet.
Leave a comment!
You must be logged in to post a comment.
<< Scala Diaries: Play Framework 2.0.x, Play SBT Plugin Breakage