The idea that is that I would like to be able to text -> tokens -> text For text -> tokens (RBScanner on: 'self classVariables: { #A . #B }' readStream) contents collect: #value I wrote a little method that takes the result of the RBScanner and recreate the text But I cannot get this method to work. I’m puzzled because the symbols are eaten. expressionStringFrom: aLine "self new expressionStringFrom: #('self' 'classVariables:' ${ #A $. #B $}) >>> 'self classVariables: { A . B }' " ^ String streamContents: [ :s | aLine do: [ :each | s << each ] separatedBy: [ s space ]] I tried with print:, printOn:, but I failed. Any idea? S. -------------------------------------------- Stéphane Ducasse 03 59 35 87 52 Assistant: Julie Jonas FAX 03 59 57 78 50 TEL 03 59 35 86 16 S. Ducasse - Inria 40, avenue Halley, Parc Scientifique de la Haute Borne, Bât.A, Park Plaza Villeneuve d'Ascq 59650 France |
On Jan 19, 2020, at 1:50 PM, Stéphane Ducasse <[hidden email]> wrote:
|
#foo printString.
'#foo' String streamContents: [ :out | out print: #foo ]. '#foo' String streamContents: [ :out | out << #foo ]. 'foo' I would not use #storeOn: directly, I would consider the fact that String>>#printOn: uses it an implementation detail, and a confusing one at that. > On 20 Jan 2020, at 03:54, Eliot Miranda <[hidden email]> wrote: > > > >> On Jan 19, 2020, at 1:50 PM, Stéphane Ducasse <[hidden email]> wrote: >> >> >> The idea that is that I would like to be able to >> >> text -> tokens -> text >> >> For text -> tokens >> >> (RBScanner on: 'self classVariables: { #A . #B }' readStream) >> contents collect: #value >> >> >> I wrote a little method that takes the result of the RBScanner and recreate the text >> But I cannot get this method to work. >> I’m puzzled because the symbols are eaten. >> >> >> expressionStringFrom: aLine >> >> "self new >> expressionStringFrom: #('self' 'classVariables:' ${ #A $. #B $}) >> >>> >> 'self classVariables: { A . B }' >> " >> ^ String streamContents: [ :s | >> aLine >> do: [ :each | s << each ] >> separatedBy: [ s space ]] >> >> I tried with print:, printOn:, but I failed. >> >> Any idea? > > With Symbols one needs to use storeOn: > >> >> S. >> >> >> >> >> -------------------------------------------- >> Stéphane Ducasse >> http://stephane.ducasse.free.fr / http://www.pharo.org >> 03 59 35 87 52 >> Assistant: Julie Jonas >> FAX 03 59 57 78 50 >> TEL 03 59 35 86 16 >> S. Ducasse - Inria >> 40, avenue Halley, >> Parc Scientifique de la Haute Borne, Bât.A, Park Plaza >> Villeneuve d'Ascq 59650 >> France |
Hi sven I think that I will have to hack my own, I was just surprised that we do not have a nice way back from tokens back to code. (not talking about quote inside strings). String streamContents: [ :s | #('self' 'classVariables:' ${ #A $. #B $}) do: [ :each | s print: each ] separatedBy: [ s space ]]. '''self'' ''classVariables:'' ${ #A $. #B $}’ S.
|
In fact I did it because this is irregular in the sense that binary selector should not printed with # while the keywords based symbol should.
(RBScanner on: '(RBScanner on: 'Object < #MyObject classVariables: { #A. #B }; package: #MyPackage' readStream) contents collect: #value readStream) contents collect: #value >>> #('Object' #< #MyObject 'classVariables:' ${ #A $. #B $} $; 'package:' #MyPackage) and back should be 'Object < #MyObject classVariables: { #A. #B }; package: #MyPackage'
|
Free forum by Nabble | Edit this page |