|parrotcode: CodeString PMC Class|
|Contents | PMCs|
src/pmc/codestring.pmc - CodeString PMC Class
CodeString is a class intended to simplify the process of emitting code strings.
Ideally this will eventually become a form of "CodeBuffer" that is more efficient than string concatenation,
but for now it works well enough for me.
The primary method for
CodeString objects is
which appends a line (or lines) of code to the string according to a format parameter.
The line can contain substitution markers (ala printf) that indicate where other parameters to the call should be placed.
CodeString is just a subclass of Parrot's native
so it's easy to combine CodeString objects with other strings outside of the
emit(string fmt [, pmc args ] [, pmc hash ])
CodeStringobject according to
fmtstring can contain any number of "%-replacements" which are replaced by the corresponding values from
hashprior to being appended to the string. (Here
argsis a slurpy array, and
hashis a slurpy hash.)
%0 %1 ... %9 the value from the args array at index 0..9 %, the values of the args array separated by commas %% a percent sign
uniquereturns a unique number, or if a
fmtparameter is given it returns a unique string beginning with
fmt. (This may eventually be generalized to allow uniqueness anywhere in the string.) The function starts counting at 10 (so that the values 0..9 can be considered "safe").
strsuitable for including in PIR. If the string contains any non-ASCII characters, then it's prefixed with 'unicode:'.
key( string name1 [, string name2, ...] )