galaxykate / tracery

Tracery: a story-grammar generation library for javascript
Apache License 2.0
2.12k stars 251 forks source link

Variable expansion breaks on commas in variable text. #20

Open v21 opened 8 years ago

v21 commented 8 years ago
{

    "origin":"[clippath1:#clippath-path#]<clipPath id=\"overlay1\">#clippath1#</clipPath>",

    "clippath-path":["<path d=\"M 512 0 L 0 0 L 0 #h# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint# #curvepoint#  M 512 0 Z\"></path>"],
    "curvepoint":"q #dist_half# #h_rel_half#, #dist# #h_rel#",

    "dist":["2#digit#","2#digit#","4#digit#","3#digit#","5#digit#","6#digit#","7#digit#","8#digit#"],
    "dist_half":["#digit#","#digit#","#0-5#"],
    "h_rel":["-2#digit#", "1#digit#", "-1#digit#","#digit#", "-#digit#","2#digit#"],
    "h_rel_half":["-#digit#", "#0-5#", "-#0-5#","#digit#"],
    "h" : ["2#digit##digit#","2#digit##digit#","3#digit##digit#","1#digit##digit#"],

    "digit":["0","1","2","3","4","5","6","7","8","9"],
    "0-5":["0","1","2","3","4","5"]
}

should produce something like

<clipPath id="overlay1"><path d="M 512 0 L 0 0 L 0 251 q 2 -4 24 28 q 0 3 23 2 q 1 2 41 -28 q 5 -3 47 11 q 5 6 21 -27 q 1 -0 44 14 q 4 6 43 13 q 4 -1 29 2 q 4 -3 27 19 q 3 0 24 17 q 5 2 27 15 q 5 -7 63 -14 q 0 -3 26 1 q 0 -2 76 -5 q 6 -4 28 9 q 2 4 76 -21 q 2 7 23 8 q 0 2 20 -27 q 4 -2 86 -6 q 5 -5 30 -4 q 3 -1 75 -16 q 1 -3 27 5 q 8 -3 22 -19 q 1 -2 80 4 q 2 6 35 -1 q 9 3 73 29 q 6 -3 56 26 q 1 4 47 25 q 5 0 36 20 q 4 8 31 4 q 1 0 73 9 q 1 -1 70 -3 q 0 -2 56 10 q 8 4 20 -13 q 1 9 20 -14 q 0 -5 23 3 q 5 -1 45 -11 q 3 -4 54 -16 M 512 0 Z"></path></clipPath>

but instead it produces something like

<clipPath id="overlay1"> 62 28 q 3 -1</clipPath>

Changing "curvepoint":"q #dist_half# #h_rel_half#, #dist# #h_rel#", to "curvepoint":"q #dist_half# #h_rel_half# #dist# #h_rel#", solves the problem.

Miltage commented 8 years ago

Seeing as you're generating code, this work around won't work for you, but for others like me who are just generating sentences, I found the lower single quote to be a nice work around.

hugovk commented 8 years ago

This code:

{
    "origin": ["#defthing#The #WOTSIT#s #thing#"]
,    "defthing": ["[WOTSIT:colour][thing:#colour#]", "[WOTSIT:animal][thing:#animal#]"]
,    "colour": ["orange, blue and white"]
,    "animal": ["unicorn, raven and sparrow"]
}

works on Tracery Writer:

The colours orange, blue and white The animals unicorn, raven and sparrow

and Tracery for Python:

$ python -m tracery test.json 2
The colours orange, blue and white
The animals unicorn, raven and sparrow

but not on CBDQ:

The colours blue and white The colours orange The animals raven and sparrow The animals unicorn

serin-delaunay commented 4 years ago

It doesn't work on CBDQ frontend (previews and manual tweets), but it does work on CBDQ backend (regular scheduled tweets):

The colours orange, blue and white