#411 \$ in strings: what does it represent?

Stuart Longland Thu 23 Jun 2016

Hi all,

I'm debugging an issue that hszinc encountered parsing a grid from SkySpark. I've distilled it down to the offending row and have anonymised the data.

ver:"2.0" projName:"AProjName"
id,ahu,ahuGroup,disMacro,elec,elecMeterLoad,equip,equipRef,floorRef,gas,hvac,lighting,lightsGroup,meter,navName,parking,plug,regionRef,rooftop,siteMeter,sitePoint,siteRef,submeterOf,water,mod
@SiteName.EquipName "SiteName Equip Name",,,"\$foo \$bar",,@SiteName.EquipName-SubEquipName "SiteName EquipName-SubEquipName",M,,,,,,M,,"Equip Name",,,@aabbccdd-eeff0011 "A City",,,,@SiteName "SiteName",,,2016-05-04T03:02:01.987Z

hszinc presently barfs on the \$ construct. Strings are presently escaped using C-style escapes. However, \$ is not a C-style escape string, not in any dialect of C that I've ever encountered anyway (ANSI or K&R).

Replace \$ with $ in the raw grid, and everything works.

So, if I see a dollar sign, with or without a proceeding backslash, what am I supposed to emit?

Thanks in advance.

Brian Frank Tue 28 Jun 2016

Its just an escape for the $ character which can be used for interpolation. See the grammar:

<strEscChar>  := "\b" | "\f" | "\n" | "\r" | "\r" | "\t" | "\"" |  "\\" | "\$ | <uEscChar>
<uriEscChar>  := "\:" | "\/" | "\?" | "\#" | "\[" | "\]" | "\@" | "\`" | "\\" | "\&" | "\=" | "\;" | <uEscChar>
<uEscChar>    := "\u" <hexDigit> <hexDigit> <hexDigit> <hexDigit>

Stuart Longland Wed 29 Jun 2016

Ahh fair enough, I tried looking around but as I say, no dialect of C I've ever come across had an escape sequence for \$. Haven't seen it in other languages either.

The grammar is great for telling me what is valid, however it doesn't tell me what it maps to (e.g. \r does not become r, it becomes a carriage return character).

I've now resolved that issue and a new release of hszinc is out that corrects the issue seen.

Steve Eynon Wed 29 Jun 2016

Hi Stuart,

I think the reason why \$ is an allowed escape sequence is historical and would have been because SkySpark is written in Fantom.

In Fantom, the $ symbol is used to interpolate strings:

name := "Mum"
msg  := "Hello $name!"

The escape sequence \$ is then used to print the $ symbol.

msg := "Show me the \$\$\$!"

Whereas the escape sequence \$ is not particularly useful to zinc (since it simply maps to $), it does allows Fantom programs to use some in-built serialisation mechanisms when printing zinc strings.

Hope this helps,

Steve.

Login or Signup to reply.