This project is read-only.
The following example comes from an Anise script used to configure a command-line tool used on the Pivot project. This example script is first listed whole, then broken down line-by-line to demonstrated exactly what is happening on each line.

Anise
    1: #environment on
    2: 
    3: #using Crawler
    4: #using LocalRcxmlDataSource
    5: #using SqlDataSource
    6: #using RegexFilterDataSource
    7: #using IDataSource
    8:
    9: #namespace Microsoft.LiveLabs.SeahorseServer
    10: 
    11: database-host = LL-SEHSQL01;
    12: database-name = CTP1_Collections_Master;
    13: collection-name = Kiva;
    14: working-directory = %inetroot%\private\server\output;
    15: generate-seadragon-files = true;
    16:
    17: crawler = {
    18:     _class = Crawler;
    19:     _constructor = [
    20:         @source,
    21:         # Target
    22:         {
    23:             _class = LocalRcxmlDataSource;
    24:             _constructor = [ @source._constructor.2 ];
    25:             WorkingDirectory = @working-directory;
    26:             GenerateSeadragonFiles = @generate-seadragon-files;
    27:         },
    28:     ];
    29:     ShouldUseSourceVersion = true;
    30:     Run = [ ];
    31: };
    32: 
    33: source = {
    34:     _class = Microsoft.LiveLabs.SeahorseServer.Data.SqlDataSource;
    35:     _constructor = [
    36:         @database-host,
    37:         @database-name,
    38:         @collection-name,
    39:     ];
    40: };
    41: 
    42: #build crawler


1: #environment on
This line enables the expansion of environment variables until the end of the file or it is turned off with the "#environment off" directive.
3: #using Crawler
4: #using LocalRcxmlDataSource
5: #using SqlDataSource
6: #using RegexFilterDataSource
7: #using IDataSource
These statements all specify various assemblies which will be needed to resolve the types used in the remainder of the script (e.g., Microsoft.LiveLabs.SeahorseServer.Crawler is defined in Crawler.dll ).
9: #namespace Microsoft.LiveLabs.SeahorseServer
This statement changes the default namespace for subsequent _class declarations. If this line were omitted, then each _class declaration would have to fully specify the class name.
11: database-host = LL-SEHSQL01;
12: database-name = CTP1_Collections_Master;
13: collection-name = Kiva;
Each of these statements define a new named object in the system which are all of the basic type, string . These values are referenced (occasionally multiple times) later in the script.
14: working-directory = %inetroot%\private\server\output;
Like the previous lines, this line also defines a named object of basic type String. However, this line contains an environment variable, "%inetroot%". Since environment variable expansion was turned on in line 1, the text, %inetroot% , will be replaced with the current value of of the appropriate environment variable when the script is parsed.
15: generate-seadragon-files = true;
Note that this line also defines a new named object of basic type String. There is no basic type for boolean values. Instead, this value will be converted using one of the built-in converters when it is actually used.
17: crawler = {
18: _class = Crawler;
These two lines declare a new instance of the Crawler class. Without the _class meta-property, this would only have declared a Dictionary . Note that the full name of the class is required in the _class meta-property. Since the #namespace declaration on line 9 already set the proper namespace, it can be omitted in this case.
19: _constructor = [
This meta-property declares that a specific constructor should be used (rather than just the default constructor). Note that the value portion of this Pair declaration is an Array. All Pairs which correspond to a constructor (or method) invocation must have an Array as their value.
20: @source,
The first element of the constructor's argument Array is a reference to an object named source . Note that this object is declared later in the file; Anise allows references to objects declared anywhere else in the file.
21: # Target
A comment.
22: {
23: _class = LocalRcxmlDataSource;
This declares a new instance of LocalRcxmlDataSource . Anise allows objects to be declared directly within one another, or as separately named objects.
22: _constructor = [ @source._constructor.2 ];
This line has a lot going on. First, it declares the use of a specific constructor having a single argument. Second, it declares that the sole argument is a Reference. Finally, you'll notice that the reference does not refer to a directly named object. Instead, it actually refers to an argument passed to another object's constructor. In fact, you may notice that the referenced object isn't actually a real object either; it's another reference. Anise is able to follow any number of references to find the actual object being referenced.
23: WorkingDirectory = @working-directory;
24: GenerateSeadragonFiles = @generate-seadragon-files;
These two lines assign a named object to a property. In the second one, the property is actually of type bool , and therefore, the actual value will automatically be converted from its native Anise type, string , to bool before it is assigned.
25: },
26: ];
These are the close declarations of the LocalRcxmlDataSource object and the constructor argument array, respectively. Note that the comma on line 25 is completely optional since it is the last element in its parent.
27: ShouldUseSourceVersion = true;
This is a direct property assignment which also requires conversion from the Anise basic type, string , to bool .
28: Run = [ ];
This line declares an invocation of the Run method which requires no arguments. In fact, the Crawler class is written so that this method is effectively the Main method for the whole program. The declaration of this method invocation, therefore, serves to start the program's execution as soon as the crawler object is instantiated.
29: };
This line closes the declaration of the crawler object. Note that the semi-colon is mandatory in this case since another Pair follows it.
31: source = {
32: _class = Microsoft.LiveLabs.SeahorseServer.Data.SqlDataSource;
In this case, this object does not reside in the same namespace as was previously declared by the #namespace directive. We could either add a new #namespace declaration, or override it by providing the fully-specified name for the class.
33: _constructor = [
34: @database-host,
35: @database-name,
36: @collection-name,
37: ];
38: };
All of the dependencies for this object are introduced through the constructor, and each of them is actually a reference to a named object declared at the top of the file.
40: #build crawler
This preprocessor directive causes the crawler object to be instantiated as soon as the file has finished being parsed. That way, the net effect of running the interpreter with this single file as an argument will be to create a custom-built instance of a Crawler object and to execute its Run method

Last edited Jun 28, 2010 at 12:58 AM by aminer, version 1

Comments

No comments yet.