Features of 'The Worlds 3rd Simplest Code Generator'

Basic Use

Paste a comma-separated list in the first box.

Type a 'pattern' into the second box.

Press 'Generate' to apply the pattern to every row of the list.

You Want A Basic example?

Say you've got a list something like this:

And the pattern looked like this:

I think that $1 are $2.

Then the result would look like this:

Okay, even the original version could do that.

But Check Out The Wonderful New Features!

RowNumber

You can use the special "RowNumber" command to print out the row number.

This is row $RowNumber

If Statements

You can now use 'if' statements to filter or customize the output.

Example pattern:

$if $7 = "M" then
$1 is a man.$end if
$if $7 = "F" then
$1 is a woman.$end if

Note that text values are enclosed in double quotes.

For 'does not equal' use '!=', just like in C style languages.

For numeric values you don't need the double quotes, and you can use 'greater than' and 'less than' symbols ('>' and '<').

You can't use Ands and Or's yet (maybe next version), but you can nest 'if' statements inside each other, to get the same effect.

And sorry, but there's no 'else' statement yet. Again, you can create two if statements and get the same effect.

(The word 'then' is optional. Leave it off if you prefer. 'Endif' or 'End if': either is fine. Commands are not case-sensitive.)

You can also use the RowNumber command with an If statement. For example, this pattern... $if $RowNumber!=1
,$endif $1

... creates a nice comma separated list of just the first column of your data, that DOESN'T include the extra comma you would be used to seeing if you've used earlier version of the generator.

Loops

The coolest new feature is 'Loops Mode', which is turned off by default. (Click the checkbox to turn it on)

In loops mode you can have multiple 'ForEach Row' statements.

For example:

Say you want a pattern that declares a bunch of variables, then exposes them as properties... you need two loops!

#region private declarations
$ForEach Row
  private $2 _$1;
$Next
#end region

#region public properties
$ForEach Row
  public $2 $1
  {
    get { return _$1; }
    set { _$1 = value; }
  }
$Next
#end region

Using this feature you can write a whole data access layer, or get some pretty powerful stuff happening. The united nations want me to ban this feature. But I'm not backing down on it.

Using an if inside a ForEach loop is a pretty nifty trick, bound to impress the ladies:

#Region private declarations
$ForEach Row
  private $2 _$1;
$Next
#end region

#Region public properties
$ForEach Row
  public $2 $1
  {
    get { return _$1; }
$if $3 != "readonly"
    set { _$1 = value; }
$endif  }
$Next
#end region

Comments

You can put comments in your patterns, to help you remember how to use them.

Comments begin with $Comment. You can also use $Rem, or $// or $--.

$// $1 is the variable name, e.g. 'Height', 'Age'
$// $2 is the type, e.g. String
#Region private declarations
$ForEach Row
  private $2 _$1;
$Next
#end region

#Region public properties
$ForEach Row
  public $2 $1
  {
    get { return _$1; }
    set { _$1 = value; }
  }
$Next
#end region

XML and XSL

The generator is entirely powered by XML and XSL.

But the fun thing is, it allows you to see the XML and XSL that is generated.

In fact, some people might use the generator for creating XSL in a hurry.

Writing XSL by hand is not fun at all. For example the "$1" command in 'Pattern language' is replaced by this monster in XSL:

<xsl:value-of select="field[@number=1]"/>

Flexible

There's also a lot of 'options' provided, to make the tool more flexible.

If you paste data in from Excel, or from a grid, it will probably have tabs delimiting each column. To handle for this, type '\t' into the 'column delimiter' text box. (There's tool-tip help that reminds you of this.)

Say each row of your data is delimited by pipe characters: just type that into the 'row delimiter' text box.

You don't like using the "$" symbol to denote commands? Use any character you like, specify it as the "Code Symbol Prefix". You can even specify a character to mark the end of each command.