carueda/tscfg

scala: option to use back ticks

Closed this issue · 1 comments

Currently (0.8.4):

From:

foo-object {
  bar-baz: string
}
other-stuff: int

the generated Scala is:

case class ScalaIssue30Cfg(
  foo_object  : ScalaIssue30Cfg.FooObject,
  other_stuff : scala.Int
)
object ScalaIssue30Cfg {
  case class FooObject(
    bar_baz : java.lang.String
  )
  ...

That is, regarding the characters that would make the identifiers invalid in Scala, tscfg either removes them (foo-object becomes FooObject) or replace them with underscores (other-stuff -> other_stuff; bar-baz -> bar_baz).

So, the suggested idea here is to add an option to instead use back ticks for such translations (which should probably have been the default behavior since this was implemented):

case class ScalaIssue30Cfg(
  `foo-object`  : ScalaIssue30Cfg.`Foo-Object`,
  `other-stuff` : scala.Int
)
object ScalaIssue30Cfg {
  case class `Foo-Object`(
    `bar-baz` : java.lang.String
  )
...

Note that back sticks have already been used but only for Scala reserved words.

Now, with 0.9.0:

From:

foo-object {
  bar-baz: string
  0: string
}
"other#stuff": int

and using the new --scala:bt option one gets:

case class ScalaIssue30Cfg(
  `foo-object`  : ScalaIssue30Cfg.`Foo-object`,
  `other#stuff` : scala.Int
)
object ScalaIssue30Cfg {
  case class `Foo-object`(
    `0`       : java.lang.String,
    `bar-baz` : java.lang.String
  )
...