This project is read-only.

Strings

Strings are the simplest type in the Anise language. A String is simply a sequence of characters up to some stop character (determined by the context in which it's used, more will be said on this point later). If you would like to include a stop character in the String, you can either escape it using a backslash ( \ ), or enclose that portion of the string in double-quotes ( " ). Whitespace which occurs within a string is preserved, but whitespace before and after the string is removed. To preserve whitespace before or after a string, enclose the entire string in double-quotes.

Arrays

An Array is a sequence of basic types. The order of elements is preserved (if the instance created from the array supports it). Arrays may be nested or arbitrarily combined with the other basic types. There is no restriction that elements of an Array must be all of the same type unless it is required by the instance which is ultimately created from it. An Array has the following syntax:

[ <Basic Type>, <Basic Type>, ..., <Basic Type> ]

Pairs

A Pair maps a value to a name. The root elements of an Anise script are all Pairs, each defining an instance in the graph. Once the script has been interpreted, the values are each accessible using the names associated with them. Each Pair has the following syntax:

<String> = <Basic Type>
The key is a String which stops at the first = (unless quoted or escaped). The value may be any of the other four basic types (e.g., String, Array, Dictionary, or Reference). As with any String, leading and trailing whitespace is removed from the key. A semicolon is required between each pair (although it's optional after the last pair in a set). Consider the following example Anise script:

Anise
    1: alpha = Hello world!;
    2: bravo = It's a nice world, isn't it?


This example defines two pairs, each mapping a String to an instance name. The following code fragment shows using an existing AniseEngine to retrieve the two strings we just defined:

C#
    1: String alpha = aniseEngine.GetObject<String>("alpha");
    2: String bravo = aniseEngine.GetObject<String>("bravo");
    3: 
    4: Output.WriteLine("alpha contains: " + alpha);
    5: Output.WriteLine("bravo contains: " + bravo);


Which produces the following output on the console:

Console
    1: alpha contains: Hello world!
    2: bravo contains: It's a nice world, isn't it?

Dictionary

A Dictionary is a sequence of Pairs. Dictionaries also support a number special purpose keys which allow them to be instantiated as specific classes and have other special handling. Each of these special purpose keys, or Meta-Properties is discussed in following sections. Here is the syntax for a Dictionary:

{ <Pair>; <Pair>; ...; <Pair> }
As with the Array, the delimiter (a semi-colon in this case), is mandatory between each Pair, but is optional following the last one. Here is an example of a Dictionary declaration:

Anise
    1: alpha = {
    2:     bravo = [ br, av, o ];
    3:     charlie = [ ch, ar, li, e ];
    4:     delta = [ de, lt, a ];
    5: };


In this example, the Dictionary's Pairs each has an Array for a value. Each Array contains a sequence of Strings. Here is what it would look like to get this object out of an existing AniseEngine:

C#
    1: Dictionary<List<String>> alpha =
    2:     aniseEngine.GetObject<Dictionary<List<String>>>("alpha");
    3: 
    4: Output.WriteLine("Value: " + alpha["bravo"][0] + alpha["charlie"][1]
    5:     + alpha["delta"][2]);


Which produces the following output on the console:

Console
    1: Value: brara

Reference

A Reference creates an alias from one place in an object graph to another. This is how you would create multiple objects which depend upon the same third object, or create cycles in the object graph. The syntax for a Reference is:

@<String>
Where the given String must refer to the name of another object in the object graph. The name given may refer to any object in the object graph, however, even if it isn't declared in the root of the script. For example, all of the following Reference declarations are valid:

Anise
    1: alpha = {
    2:     bravo = [ br, av, o ];
    3:     charlie = [ ch, ar, li, e ];
    4:     delta = [ de, lt, a ];
    5: };
    6: 
    7: echo = @alpha;
    8: foxtrot = @alpha.bravo;
    9: golf = @alpha.charlie.2;


Where each of the references values are: the entire Dictionary (referenced as "echo"), the first Array declaration (referenced as "foxtrot") , and the String containing the letters "li" (referenced as "golf"). You'll note that when referring to an element of an Array, the name of that element is simply its (zero-based) index in the Array.

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

Comments

No comments yet.