Hi
I want to write a method that generate a method that when I execute this recreates the objects that I STONified. (I love STON). So I did something like that descriptionMethodFrom: descriptionItems "self new descriptionMethodFrom: ChrysalConfigurationDescription itemDescriptionForXX" ^ String streamContents: [ :s | s nextPutAll: 'descriptions'; cr. s nextPutAll: '^ STON fromString: '. s nextPutAll: (STON toStringPretty: descriptionItems) ] and I get of course something wrong :) because the strings are not doubel quoted and the first expression is not surrounded by single quote. And I could do it but I want a smart way to do it. I was thinking that may be I'm missing something obvious. descriptions ^ STON fromString: [ StringConfigurationItem { #propertyName : 'title', #default : 'my super cool book' }, BooleanConfigurationItem { #propertyName : 'verbose', #default : 'true' }, StringConfigurationItem { #propertyName : 'attribution', #default : 'me, myself and I' }, StringConfigurationItem { #propertyName : 'series', #default : 'Square Bracket Associate Collection' } ] |
So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object.
Let's say you want to STON-ify the following object: { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. Note there is a single quote character inside the #note. You can do that using #print: when needed. Here is an expression to see how that works: Compiler evaluate: (String streamContents: [ :out | out nextPutAll: 'STON fromString: '; print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). The Smalltalk expression then looks like this: STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. Is this what you need ? > On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: > > Hi > > I want to write a method that generate a method that when I execute > this recreates the objects that I STONified. > (I love STON). > > So I did something like that > > descriptionMethodFrom: descriptionItems > "self new descriptionMethodFrom: ChrysalConfigurationDescription > itemDescriptionForXX" > > ^ String streamContents: [ :s | > s nextPutAll: 'descriptions'; cr. > s nextPutAll: '^ STON fromString: '. > s nextPutAll: (STON toStringPretty: descriptionItems) ] > > and I get of course something wrong :) because the strings are not > doubel quoted and the first expression is not surrounded by single > quote. > > And I could do it but I want a smart way to do it. I was thinking that > may be I'm missing something obvious. > > descriptions > ^ STON fromString: [ > StringConfigurationItem { > #propertyName : 'title', > #default : 'my super cool book' > }, > BooleanConfigurationItem { > #propertyName : 'verbose', > #default : 'true' > }, > StringConfigurationItem { > #propertyName : 'attribution', > #default : 'me, myself and I' > }, > StringConfigurationItem { > #propertyName : 'series', > #default : 'Square Bracket Associate Collection' > } > ] > |
Tx sven got caught by a flu... freezing in my bed.
I will check. On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: > So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. > > Let's say you want to STON-ify the following object: > > { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. > > Note there is a single quote character inside the #note. > > You can do that using #print: when needed. Here is an expression to see how that works: > > Compiler evaluate: (String streamContents: [ :out | > out > nextPutAll: 'STON fromString: '; > print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). > > The Smalltalk expression then looks like this: > > STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' > > The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. > > Is this what you need ? > >> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >> >> Hi >> >> I want to write a method that generate a method that when I execute >> this recreates the objects that I STONified. >> (I love STON). >> >> So I did something like that >> >> descriptionMethodFrom: descriptionItems >> "self new descriptionMethodFrom: ChrysalConfigurationDescription >> itemDescriptionForXX" >> >> ^ String streamContents: [ :s | >> s nextPutAll: 'descriptions'; cr. >> s nextPutAll: '^ STON fromString: '. >> s nextPutAll: (STON toStringPretty: descriptionItems) ] >> >> and I get of course something wrong :) because the strings are not >> doubel quoted and the first expression is not surrounded by single >> quote. >> >> And I could do it but I want a smart way to do it. I was thinking that >> may be I'm missing something obvious. >> >> descriptions >> ^ STON fromString: [ >> StringConfigurationItem { >> #propertyName : 'title', >> #default : 'my super cool book' >> }, >> BooleanConfigurationItem { >> #propertyName : 'verbose', >> #default : 'true' >> }, >> StringConfigurationItem { >> #propertyName : 'attribution', >> #default : 'me, myself and I' >> }, >> StringConfigurationItem { >> #propertyName : 'series', >> #default : 'Square Bracket Associate Collection' >> } >> ] >> > > |
On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse
<[hidden email]> wrote: > Tx sven got caught by a flu... freezing in my bed. > I will check. > > On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: >> So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. >> >> Let's say you want to STON-ify the following object: >> >> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. >> >> Note there is a single quote character inside the #note. >> >> You can do that using #print: when needed. Here is an expression to see how that works: >> >> Compiler evaluate: (String streamContents: [ :out | >> out >> nextPutAll: 'STON fromString: '; >> print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). >> >> The Smalltalk expression then looks like this: >> >> STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' >> >> The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. >> >> Is this what you need ? >> >>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >>> >>> Hi >>> >>> I want to write a method that generate a method that when I execute >>> this recreates the objects that I STONified. >>> (I love STON). >>> >>> So I did something like that >>> >>> descriptionMethodFrom: descriptionItems >>> "self new descriptionMethodFrom: ChrysalConfigurationDescription >>> itemDescriptionForXX" >>> >>> ^ String streamContents: [ :s | >>> s nextPutAll: 'descriptions'; cr. >>> s nextPutAll: '^ STON fromString: '. >>> s nextPutAll: (STON toStringPretty: descriptionItems) ] >>> >>> and I get of course something wrong :) because the strings are not >>> doubel quoted and the first expression is not surrounded by single >>> quote. >>> >>> And I could do it but I want a smart way to do it. I was thinking that >>> may be I'm missing something obvious. >>> >>> descriptions >>> ^ STON fromString: [ >>> StringConfigurationItem { >>> #propertyName : 'title', >>> #default : 'my super cool book' >>> }, >>> BooleanConfigurationItem { >>> #propertyName : 'verbose', >>> #default : 'true' >>> }, >>> StringConfigurationItem { >>> #propertyName : 'attribution', >>> #default : 'me, myself and I' >>> }, >>> StringConfigurationItem { >>> #propertyName : 'series', >>> #default : 'Square Bracket Associate Collection' >>> } >>> ] >>> >> >> |
I originally did
addDescriptionMethodBodyIn: aStream forItems: descriptionItems aStream nextPutAll: 'STON fromString: '. STON put: descriptionItems onStream: aStream and I get STON fromString: [StringConfigurationItem{#propertyName:'title',#default:'my super cool book'},BooleanConfigurationItem{#propertyName:'verbose',#default:'true'},StringConfigurationItem{#propertyName:'attribution',#default:'me, myself and I'},StringConfigurationItem{#propertyName:'series',#default:'Square Bracket Associate Collection'},StringConfigurationItem{#propertyName:'keywords',#default:'Pharo'},FolderConfigurationItem{#propertyName:'outputDirectory',#default:'build'},FileConfigurationItem{#propertyName:'mainDocument',#default:'book'},FileConfigurationItem{#propertyName:'latexTemplate',#default:'_support/templates/main.latex.mustache'},FileConfigurationItem{#propertyName:'latexChapterTemplate',#default:'_support/templates/chapter.latex.mustache'},FileConfigurationItem{#propertyName:'htmlTemplate',#default:'_support/templates/html.mustache'},FileConfigurationItem{#propertyName:'htmlChapterTemplate',#default:'_support/templates/html.mustache'},NewLineConfigurationItem{#propertyName:'newLine',#defaultKey:#unix},SymbolConfigurationItem{#propertyName:'latexWriter',#default:#'latex:sbabook'}] I see that you pass via a string and me via a stream but I wonder why with my solution strings where not escaped. Stef On Tue, Mar 13, 2018 at 5:13 PM, Stephane Ducasse <[hidden email]> wrote: > On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse > <[hidden email]> wrote: >> Tx sven got caught by a flu... freezing in my bed. >> I will check. >> >> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: >>> So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. >>> >>> Let's say you want to STON-ify the following object: >>> >>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. >>> >>> Note there is a single quote character inside the #note. >>> >>> You can do that using #print: when needed. Here is an expression to see how that works: >>> >>> Compiler evaluate: (String streamContents: [ :out | >>> out >>> nextPutAll: 'STON fromString: '; >>> print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). >>> >>> The Smalltalk expression then looks like this: >>> >>> STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' >>> >>> The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. >>> >>> Is this what you need ? >>> >>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >>>> >>>> Hi >>>> >>>> I want to write a method that generate a method that when I execute >>>> this recreates the objects that I STONified. >>>> (I love STON). >>>> >>>> So I did something like that >>>> >>>> descriptionMethodFrom: descriptionItems >>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription >>>> itemDescriptionForXX" >>>> >>>> ^ String streamContents: [ :s | >>>> s nextPutAll: 'descriptions'; cr. >>>> s nextPutAll: '^ STON fromString: '. >>>> s nextPutAll: (STON toStringPretty: descriptionItems) ] >>>> >>>> and I get of course something wrong :) because the strings are not >>>> doubel quoted and the first expression is not surrounded by single >>>> quote. >>>> >>>> And I could do it but I want a smart way to do it. I was thinking that >>>> may be I'm missing something obvious. >>>> >>>> descriptions >>>> ^ STON fromString: [ >>>> StringConfigurationItem { >>>> #propertyName : 'title', >>>> #default : 'my super cool book' >>>> }, >>>> BooleanConfigurationItem { >>>> #propertyName : 'verbose', >>>> #default : 'true' >>>> }, >>>> StringConfigurationItem { >>>> #propertyName : 'attribution', >>>> #default : 'me, myself and I' >>>> }, >>>> StringConfigurationItem { >>>> #propertyName : 'series', >>>> #default : 'Square Bracket Associate Collection' >>>> } >>>> ] >>>> >>> >>> |
> On 13 Mar 2018, at 18:09, Stephane Ducasse <[hidden email]> wrote: > > I originally did > > addDescriptionMethodBodyIn: aStream forItems: descriptionItems > aStream nextPutAll: 'STON fromString: '. > STON put: descriptionItems onStream: aStream > > > and I get > > STON fromString: > [StringConfigurationItem{#propertyName:'title',#default:'my super cool > book'},BooleanConfigurationItem{#propertyName:'verbose',#default:'true'},StringConfigurationItem{#propertyName:'attribution',#default:'me, > myself and I'},StringConfigurationItem{#propertyName:'series',#default:'Square > Bracket Associate > Collection'},StringConfigurationItem{#propertyName:'keywords',#default:'Pharo'},FolderConfigurationItem{#propertyName:'outputDirectory',#default:'build'},FileConfigurationItem{#propertyName:'mainDocument',#default:'book'},FileConfigurationItem{#propertyName:'latexTemplate',#default:'_support/templates/main.latex.mustache'},FileConfigurationItem{#propertyName:'latexChapterTemplate',#default:'_support/templates/chapter.latex.mustache'},FileConfigurationItem{#propertyName:'htmlTemplate',#default:'_support/templates/html.mustache'},FileConfigurationItem{#propertyName:'htmlChapterTemplate',#default:'_support/templates/html.mustache'},NewLineConfigurationItem{#propertyName:'newLine',#defaultKey:#unix},SymbolConfigurationItem{#propertyName:'latexWriter',#default:#'latex:sbabook'}] > > I see that you pass via a string and me via a stream but I wonder why > with my solution strings where not escaped. You're sick that is why you are not thinking clearly ;-) This has nothing to do with STON, but with Smalltalk syntax. Say you want to write out a Date creation expression, then the following (what you do) would not work: Compiler evaluate: (String streamContents: [ :out | out << 'Date fromString: '. Date today printOn: out ]). But the following does (as I did): Compiler evaluate: (String streamContents: [ :out | out << 'Date fromString: '. out print: Date today printString ]). You need to take the printed representation and turn it into a Smalltalk String literal. If you just put it there, all the characters will be there but the string will not be quoted, nor will embedded quotes be escaped properly. > Stef > > On Tue, Mar 13, 2018 at 5:13 PM, Stephane Ducasse > <[hidden email]> wrote: >> On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse >> <[hidden email]> wrote: >>> Tx sven got caught by a flu... freezing in my bed. >>> I will check. >>> >>> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: >>>> So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. >>>> >>>> Let's say you want to STON-ify the following object: >>>> >>>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. >>>> >>>> Note there is a single quote character inside the #note. >>>> >>>> You can do that using #print: when needed. Here is an expression to see how that works: >>>> >>>> Compiler evaluate: (String streamContents: [ :out | >>>> out >>>> nextPutAll: 'STON fromString: '; >>>> print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). >>>> >>>> The Smalltalk expression then looks like this: >>>> >>>> STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' >>>> >>>> The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. >>>> >>>> Is this what you need ? >>>> >>>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >>>>> >>>>> Hi >>>>> >>>>> I want to write a method that generate a method that when I execute >>>>> this recreates the objects that I STONified. >>>>> (I love STON). >>>>> >>>>> So I did something like that >>>>> >>>>> descriptionMethodFrom: descriptionItems >>>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription >>>>> itemDescriptionForXX" >>>>> >>>>> ^ String streamContents: [ :s | >>>>> s nextPutAll: 'descriptions'; cr. >>>>> s nextPutAll: '^ STON fromString: '. >>>>> s nextPutAll: (STON toStringPretty: descriptionItems) ] >>>>> >>>>> and I get of course something wrong :) because the strings are not >>>>> doubel quoted and the first expression is not surrounded by single >>>>> quote. >>>>> >>>>> And I could do it but I want a smart way to do it. I was thinking that >>>>> may be I'm missing something obvious. >>>>> >>>>> descriptions >>>>> ^ STON fromString: [ >>>>> StringConfigurationItem { >>>>> #propertyName : 'title', >>>>> #default : 'my super cool book' >>>>> }, >>>>> BooleanConfigurationItem { >>>>> #propertyName : 'verbose', >>>>> #default : 'true' >>>>> }, >>>>> StringConfigurationItem { >>>>> #propertyName : 'attribution', >>>>> #default : 'me, myself and I' >>>>> }, >>>>> StringConfigurationItem { >>>>> #propertyName : 'series', >>>>> #default : 'Square Bracket Associate Collection' >>>>> } >>>>> ] >>>>> >>>> >>>> > |
In reply to this post by Stephane Ducasse-3
Now I did
addDescriptionBodyIn: aStream forItems: descriptionItems aStream print: (STON toStringPretty: descriptionItems) and it works sometimes. testDescriptionBuilder | builder string | builder := ChrysalConfigurationBuilder new. string := String streamContents: [ :s | builder addDescriptionBodyIn: s forItems: ChrysalConfigurationDescription itemDescriptionForXX ]. self assert: (STON fromString: string) size equals: ChrysalConfigurationDescription itemDescriptionForXX size And I have no idea why I get 47 and 13 instead of 13 and 13. This is super super strange. Stef On Tue, Mar 13, 2018 at 6:09 PM, Stephane Ducasse <[hidden email]> wrote: > I originally did > > addDescriptionMethodBodyIn: aStream forItems: descriptionItems > aStream nextPutAll: 'STON fromString: '. > STON put: descriptionItems onStream: aStream > > > and I get > > STON fromString: > [StringConfigurationItem{#propertyName:'title',#default:'my super cool > book'},BooleanConfigurationItem{#propertyName:'verbose',#default:'true'},StringConfigurationItem{#propertyName:'attribution',#default:'me, > myself and I'},StringConfigurationItem{#propertyName:'series',#default:'Square > Bracket Associate > Collection'},StringConfigurationItem{#propertyName:'keywords',#default:'Pharo'},FolderConfigurationItem{#propertyName:'outputDirectory',#default:'build'},FileConfigurationItem{#propertyName:'mainDocument',#default:'book'},FileConfigurationItem{#propertyName:'latexTemplate',#default:'_support/templates/main.latex.mustache'},FileConfigurationItem{#propertyName:'latexChapterTemplate',#default:'_support/templates/chapter.latex.mustache'},FileConfigurationItem{#propertyName:'htmlTemplate',#default:'_support/templates/html.mustache'},FileConfigurationItem{#propertyName:'htmlChapterTemplate',#default:'_support/templates/html.mustache'},NewLineConfigurationItem{#propertyName:'newLine',#defaultKey:#unix},SymbolConfigurationItem{#propertyName:'latexWriter',#default:#'latex:sbabook'}] > > I see that you pass via a string and me via a stream but I wonder why > with my solution strings where not escaped. > > > > Stef > > On Tue, Mar 13, 2018 at 5:13 PM, Stephane Ducasse > <[hidden email]> wrote: >> On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse >> <[hidden email]> wrote: >>> Tx sven got caught by a flu... freezing in my bed. >>> I will check. >>> >>> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: >>>> So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. >>>> >>>> Let's say you want to STON-ify the following object: >>>> >>>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. >>>> >>>> Note there is a single quote character inside the #note. >>>> >>>> You can do that using #print: when needed. Here is an expression to see how that works: >>>> >>>> Compiler evaluate: (String streamContents: [ :out | >>>> out >>>> nextPutAll: 'STON fromString: '; >>>> print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). >>>> >>>> The Smalltalk expression then looks like this: >>>> >>>> STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' >>>> >>>> The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. >>>> >>>> Is this what you need ? >>>> >>>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >>>>> >>>>> Hi >>>>> >>>>> I want to write a method that generate a method that when I execute >>>>> this recreates the objects that I STONified. >>>>> (I love STON). >>>>> >>>>> So I did something like that >>>>> >>>>> descriptionMethodFrom: descriptionItems >>>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription >>>>> itemDescriptionForXX" >>>>> >>>>> ^ String streamContents: [ :s | >>>>> s nextPutAll: 'descriptions'; cr. >>>>> s nextPutAll: '^ STON fromString: '. >>>>> s nextPutAll: (STON toStringPretty: descriptionItems) ] >>>>> >>>>> and I get of course something wrong :) because the strings are not >>>>> doubel quoted and the first expression is not surrounded by single >>>>> quote. >>>>> >>>>> And I could do it but I want a smart way to do it. I was thinking that >>>>> may be I'm missing something obvious. >>>>> >>>>> descriptions >>>>> ^ STON fromString: [ >>>>> StringConfigurationItem { >>>>> #propertyName : 'title', >>>>> #default : 'my super cool book' >>>>> }, >>>>> BooleanConfigurationItem { >>>>> #propertyName : 'verbose', >>>>> #default : 'true' >>>>> }, >>>>> StringConfigurationItem { >>>>> #propertyName : 'attribution', >>>>> #default : 'me, myself and I' >>>>> }, >>>>> StringConfigurationItem { >>>>> #propertyName : 'series', >>>>> #default : 'Square Bracket Associate Collection' >>>>> } >>>>> ] >>>>> >>>> >>>> |
And my string is just so it is plain normal but when I do not STON
fromString: .... I get 47 elements instead of 13. When I do it manually I get of course 13. But the test failed with 47 :) '[ StringConfigurationItem { #propertyName : ''title'', #default : ''my super cool book'' }, BooleanConfigurationItem { #propertyName : ''verbose'', #default : ''true'' }, StringConfigurationItem { #propertyName : ''attribution'', #default : ''me, myself and I'' }, StringConfigurationItem { #propertyName : ''series'', #default : ''Square Bracket Associate Collection'' }, StringConfigurationItem { #propertyName : ''keywords'', #default : ''Pharo'' }, FolderConfigurationItem { #propertyName : ''outputDirectory'', #default : ''build'' }, FileConfigurationItem { #propertyName : ''mainDocument'', #default : ''book'' }, FileConfigurationItem { #propertyName : ''latexTemplate'', #default : ''_support/templates/main.latex.mustache'' }, FileConfigurationItem { #propertyName : ''latexChapterTemplate'', #default : ''_support/templates/chapter.latex.mustache'' }, FileConfigurationItem { #propertyName : ''htmlTemplate'', #default : ''_support/templates/html.mustache'' }, FileConfigurationItem { #propertyName : ''htmlChapterTemplate'', #default : ''_support/templates/html.mustache'' }, NewLineConfigurationItem { #propertyName : ''newLine'', #defaultKey : #unix }, SymbolConfigurationItem { #propertyName : ''latexWriter'', #default : #''latex:sbabook'' } ]' On Tue, Mar 13, 2018 at 6:35 PM, Stephane Ducasse <[hidden email]> wrote: > Now I did > > addDescriptionBodyIn: aStream forItems: descriptionItems > aStream print: (STON toStringPretty: descriptionItems) > > and it works sometimes. > > testDescriptionBuilder > | builder string | > builder := ChrysalConfigurationBuilder new. > string := String > streamContents: [ :s | builder > > addDescriptionBodyIn: s > forItems: > ChrysalConfigurationDescription itemDescriptionForXX ]. > self > assert: (STON fromString: string) size > equals: ChrysalConfigurationDescription itemDescriptionForXX size > > > And I have no idea why I get 47 and 13 instead of 13 and 13. This is > super super strange. > > Stef > > On Tue, Mar 13, 2018 at 6:09 PM, Stephane Ducasse > <[hidden email]> wrote: >> I originally did >> >> addDescriptionMethodBodyIn: aStream forItems: descriptionItems >> aStream nextPutAll: 'STON fromString: '. >> STON put: descriptionItems onStream: aStream >> >> >> and I get >> >> STON fromString: >> [StringConfigurationItem{#propertyName:'title',#default:'my super cool >> book'},BooleanConfigurationItem{#propertyName:'verbose',#default:'true'},StringConfigurationItem{#propertyName:'attribution',#default:'me, >> myself and I'},StringConfigurationItem{#propertyName:'series',#default:'Square >> Bracket Associate >> Collection'},StringConfigurationItem{#propertyName:'keywords',#default:'Pharo'},FolderConfigurationItem{#propertyName:'outputDirectory',#default:'build'},FileConfigurationItem{#propertyName:'mainDocument',#default:'book'},FileConfigurationItem{#propertyName:'latexTemplate',#default:'_support/templates/main.latex.mustache'},FileConfigurationItem{#propertyName:'latexChapterTemplate',#default:'_support/templates/chapter.latex.mustache'},FileConfigurationItem{#propertyName:'htmlTemplate',#default:'_support/templates/html.mustache'},FileConfigurationItem{#propertyName:'htmlChapterTemplate',#default:'_support/templates/html.mustache'},NewLineConfigurationItem{#propertyName:'newLine',#defaultKey:#unix},SymbolConfigurationItem{#propertyName:'latexWriter',#default:#'latex:sbabook'}] >> >> I see that you pass via a string and me via a stream but I wonder why >> with my solution strings where not escaped. >> >> >> >> Stef >> >> On Tue, Mar 13, 2018 at 5:13 PM, Stephane Ducasse >> <[hidden email]> wrote: >>> On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse >>> <[hidden email]> wrote: >>>> Tx sven got caught by a flu... freezing in my bed. >>>> I will check. >>>> >>>> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: >>>>> So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. >>>>> >>>>> Let's say you want to STON-ify the following object: >>>>> >>>>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. >>>>> >>>>> Note there is a single quote character inside the #note. >>>>> >>>>> You can do that using #print: when needed. Here is an expression to see how that works: >>>>> >>>>> Compiler evaluate: (String streamContents: [ :out | >>>>> out >>>>> nextPutAll: 'STON fromString: '; >>>>> print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). >>>>> >>>>> The Smalltalk expression then looks like this: >>>>> >>>>> STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' >>>>> >>>>> The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. >>>>> >>>>> Is this what you need ? >>>>> >>>>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >>>>>> >>>>>> Hi >>>>>> >>>>>> I want to write a method that generate a method that when I execute >>>>>> this recreates the objects that I STONified. >>>>>> (I love STON). >>>>>> >>>>>> So I did something like that >>>>>> >>>>>> descriptionMethodFrom: descriptionItems >>>>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription >>>>>> itemDescriptionForXX" >>>>>> >>>>>> ^ String streamContents: [ :s | >>>>>> s nextPutAll: 'descriptions'; cr. >>>>>> s nextPutAll: '^ STON fromString: '. >>>>>> s nextPutAll: (STON toStringPretty: descriptionItems) ] >>>>>> >>>>>> and I get of course something wrong :) because the strings are not >>>>>> doubel quoted and the first expression is not surrounded by single >>>>>> quote. >>>>>> >>>>>> And I could do it but I want a smart way to do it. I was thinking that >>>>>> may be I'm missing something obvious. >>>>>> >>>>>> descriptions >>>>>> ^ STON fromString: [ >>>>>> StringConfigurationItem { >>>>>> #propertyName : 'title', >>>>>> #default : 'my super cool book' >>>>>> }, >>>>>> BooleanConfigurationItem { >>>>>> #propertyName : 'verbose', >>>>>> #default : 'true' >>>>>> }, >>>>>> StringConfigurationItem { >>>>>> #propertyName : 'attribution', >>>>>> #default : 'me, myself and I' >>>>>> }, >>>>>> StringConfigurationItem { >>>>>> #propertyName : 'series', >>>>>> #default : 'Square Bracket Associate Collection' >>>>>> } >>>>>> ] >>>>>> >>>>> >>>>> |
In reply to this post by Sven Van Caekenberghe-2
>
> Say you want to write out a Date creation expression, then the following (what you do) would not work: > > Compiler evaluate: (String streamContents: [ :out | > out << 'Date fromString: '. > Date today printOn: out ]). > > But the following does (as I did): > > Compiler evaluate: (String streamContents: [ :out | > out << 'Date fromString: '. > out print: Date today printString ]). > > You need to take the printed representation and turn it into a Smalltalk String literal. If you just put it there, all the characters will be there but the string will not be quoted, nor will embedded quotes be escaped properly. Yes I thought about it. I was thinking that we are pretty low-level for template programming. May be RBrewritter is the way to go. |
In reply to this post by Sven Van Caekenberghe-2
Sven I was thinking about the API
you could you have a variant of put: onStream: that put the printed version of the argument. Because this is what I thought it was doing. Stef On Tue, Mar 13, 2018 at 6:32 PM, Sven Van Caekenberghe <[hidden email]> wrote: > > >> On 13 Mar 2018, at 18:09, Stephane Ducasse <[hidden email]> wrote: >> >> I originally did >> >> addDescriptionMethodBodyIn: aStream forItems: descriptionItems >> aStream nextPutAll: 'STON fromString: '. >> STON put: descriptionItems onStream: aStream >> >> >> and I get >> >> STON fromString: >> [StringConfigurationItem{#propertyName:'title',#default:'my super cool >> book'},BooleanConfigurationItem{#propertyName:'verbose',#default:'true'},StringConfigurationItem{#propertyName:'attribution',#default:'me, >> myself and I'},StringConfigurationItem{#propertyName:'series',#default:'Square >> Bracket Associate >> Collection'},StringConfigurationItem{#propertyName:'keywords',#default:'Pharo'},FolderConfigurationItem{#propertyName:'outputDirectory',#default:'build'},FileConfigurationItem{#propertyName:'mainDocument',#default:'book'},FileConfigurationItem{#propertyName:'latexTemplate',#default:'_support/templates/main.latex.mustache'},FileConfigurationItem{#propertyName:'latexChapterTemplate',#default:'_support/templates/chapter.latex.mustache'},FileConfigurationItem{#propertyName:'htmlTemplate',#default:'_support/templates/html.mustache'},FileConfigurationItem{#propertyName:'htmlChapterTemplate',#default:'_support/templates/html.mustache'},NewLineConfigurationItem{#propertyName:'newLine',#defaultKey:#unix},SymbolConfigurationItem{#propertyName:'latexWriter',#default:#'latex:sbabook'}] >> >> I see that you pass via a string and me via a stream but I wonder why >> with my solution strings where not escaped. > > You're sick that is why you are not thinking clearly ;-) > > This has nothing to do with STON, but with Smalltalk syntax. > > Say you want to write out a Date creation expression, then the following (what you do) would not work: > > Compiler evaluate: (String streamContents: [ :out | > out << 'Date fromString: '. > Date today printOn: out ]). > > But the following does (as I did): > > Compiler evaluate: (String streamContents: [ :out | > out << 'Date fromString: '. > out print: Date today printString ]). > > You need to take the printed representation and turn it into a Smalltalk String literal. If you just put it there, all the characters will be there but the string will not be quoted, nor will embedded quotes be escaped properly. > >> Stef >> >> On Tue, Mar 13, 2018 at 5:13 PM, Stephane Ducasse >> <[hidden email]> wrote: >>> On Tue, Mar 13, 2018 at 5:12 PM, Stephane Ducasse >>> <[hidden email]> wrote: >>>> Tx sven got caught by a flu... freezing in my bed. >>>> I will check. >>>> >>>> On Mon, Mar 12, 2018 at 11:01 PM, Sven Van Caekenberghe <[hidden email]> wrote: >>>>> So I guess that you want a Smalltalk expression that, when evaluated, returns an arbitrary STON-ified object as a real object. >>>>> >>>>> Let's say you want to STON-ify the following object: >>>>> >>>>> { #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary. >>>>> >>>>> Note there is a single quote character inside the #note. >>>>> >>>>> You can do that using #print: when needed. Here is an expression to see how that works: >>>>> >>>>> Compiler evaluate: (String streamContents: [ :out | >>>>> out >>>>> nextPutAll: 'STON fromString: '; >>>>> print: (STON toString: ({ #firstName->'Stéphane'. #lastName->'Ducasse'. #note->'Look: '', that was a single quote.' } asDictionary)) ]). >>>>> >>>>> The Smalltalk expression then looks like this: >>>>> >>>>> STON fromString: '{#note:''Look: \'', that was a single quote.'',#firstName:''Stéphane'',#lastName:''Ducasse''}' >>>>> >>>>> The double single quotes are Smalltalk's syntax's escaping, while the backslashes are STON's. Yes, that is a bit confusing, but consistent. >>>>> >>>>> Is this what you need ? >>>>> >>>>>> On 12 Mar 2018, at 22:43, Stephane Ducasse <[hidden email]> wrote: >>>>>> >>>>>> Hi >>>>>> >>>>>> I want to write a method that generate a method that when I execute >>>>>> this recreates the objects that I STONified. >>>>>> (I love STON). >>>>>> >>>>>> So I did something like that >>>>>> >>>>>> descriptionMethodFrom: descriptionItems >>>>>> "self new descriptionMethodFrom: ChrysalConfigurationDescription >>>>>> itemDescriptionForXX" >>>>>> >>>>>> ^ String streamContents: [ :s | >>>>>> s nextPutAll: 'descriptions'; cr. >>>>>> s nextPutAll: '^ STON fromString: '. >>>>>> s nextPutAll: (STON toStringPretty: descriptionItems) ] >>>>>> >>>>>> and I get of course something wrong :) because the strings are not >>>>>> doubel quoted and the first expression is not surrounded by single >>>>>> quote. >>>>>> >>>>>> And I could do it but I want a smart way to do it. I was thinking that >>>>>> may be I'm missing something obvious. >>>>>> >>>>>> descriptions >>>>>> ^ STON fromString: [ >>>>>> StringConfigurationItem { >>>>>> #propertyName : 'title', >>>>>> #default : 'my super cool book' >>>>>> }, >>>>>> BooleanConfigurationItem { >>>>>> #propertyName : 'verbose', >>>>>> #default : 'true' >>>>>> }, >>>>>> StringConfigurationItem { >>>>>> #propertyName : 'attribution', >>>>>> #default : 'me, myself and I' >>>>>> }, >>>>>> StringConfigurationItem { >>>>>> #propertyName : 'series', >>>>>> #default : 'Square Bracket Associate Collection' >>>>>> } >>>>>> ] >>>>>> >>>>> >>>>> >> > > |
Free forum by Nabble | Edit this page |