Working with Variables

Declaring a Variable

<dcs.Var Name="TestVar1" Type="String" SetTo="hello" />

The Name attribute is the variable name and will henceforth be referred to using a prepended $ to indicate we mean a variable. So use $TestVar1 to refer to the variable.

Note that the Name resolves to a string which is then used as the variable name. Therefore if you where to do this:

<dcs.Var Name="{$TestVar1}" Type="String" SetTo="goodbye" />

You would now have a variable named hello which could be addressed as $hello . Note also that if you want to force a variable to resolve as a String then use curly braces around it, as seen here to make $TestVar1 resolve to the string “hello” for use in the Name of this second variable.

Data Types

Scalar Types

String 16MB Integer json safe numbers -9007199254740991 to 9007199254740991 BigInteger much bigger (TODO research) Decimal BigDecimal Boolean Binary LocalDate \d{4}[/-]?(0[1-9]|1[012])[/-]?(0[1-9]|[12][0-9]|3[01]) LocalTime ([01]?[0-9]|2[0-3])(:[0-5][0-9])?(:[0-5][0-9])?(\.\d{3})? DateTime \d{4}(0[1-9]|1[012])(0[1-9]|[12][0-9]|3[01])T(0[0-9]|1[0-9]|2[0-4])([0-5][0-9])([0-5][0-9])(\d{3})?Z BigDateTime t\d{11,21}

Special Strings (Scalar)

BigString no logical limit dcLargeString 32000 dcString 4000 dcSmallString 250 dcTinyString 64 dcPath 4000 case sensitive literal search, for file paths dcMetaString 128 case sensitive literal search, often used for identities dcEmail 64 case sensitive literal search, for email addresses (([^<>()\[\]\\.,;:\s@\&]+(\.[^<>()\[\]\\.,;:\s@\&]+)*)|(\&.+\&))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))

Composite Types

List like an Array in JSON Record like an Object in JSON Xml [TODO research and example]

Variable (Type) Operations

Variables in dcScript are, by design and with few exceptions, mutable. Scalars can be updated as such:

<dcs.With Target="$TestVar1" SetTo="hello updated" />

The With statement indicates that we are working with a variable. The Target indicates which variable to work with.

Additional Operations

Each data type supports a variety of operations. These appear as children of the statement and do not include a prefix but are upper case. Operations are not treated as separate statements in dcScript, thus the lack of prefix.

<dcs.Var Name="TestVar1" Type="String" SetTo="hello" /> <dcs.With Target="$TestVar1"> <Append Value=" updated" /> </dcs.With> <dc.Out>$TestVar1</dc.Out>

Output:

hello updated

Integer Example

<dcs.Var Name="TestVar2" Type="Integer" SetTo="12" /> <dcs.With Target="$TestVar2"> <Add Value="7" /> </dcs.With> <dc.Out>$TestVar2</dc.Out>

Output:

19

Note that all the operations available to With are also available to Var, so the following would also work:

<dcs.Var Name="TestVar1" Type="String" SetTo="hello"> <Append Value=" updated" /> </dcs.Var> <dcs.Var Name="TestVar2" Type="Integer" SetTo="12"> <Add Value="7" /> </dcs.Var>

Integer variables can be incremented or decremented using the operations <Inc /> or <Dec /> , which are the the equivalent to '++' and '–' in other languages.

<dcs.Var Name="TestVar1" Type="Integer" SetTo="10" /> <dcs.With Target="$TestVar1"> <Inc /> </dcs.With> <dc.Out>$TestVar1</dc.Out>

Output:

11

Composites also have operations. To create a Record like this JSON Object:

{ "Phone": "608-333-0000", "FullName": "Andy White" }

Use this:

<dcs.Var Name="TestRecord1" Type="Record"> <SetField Name="FullName" Value="Andy White" /> <SetField Name="Phone" Value="608-333-0000" /> </dcs.Var>

To create a List like this JSON Array:

[ "green", "yellow", "orange" ]

Use this:

<dcs.Var Name="TestList1" Type="List"> <AddItem Value="green" /> <AddItem Value="yellow" /> <AddItem Value="orange" /> </dcs.Var>

Both Lists and Records can access items or fields using dot notation. For example, referencing the list and record above, the following code would produce this output:

<dc.Out>$TestList1.1</dc.Out> <dc.Out>$TestRecord1.FullName</dc.Out>

Output:

yellow Andy White

Each Composite type has its own list of operations, however, there is a common idea across Composite types of an Set or an Update.

Composite Set and Update

TODO further examples?

Set (List)

The Set operation tried to parse text between the Set tags and assign the values to the List.

<dcs.Var Name="TestVar1" Type="List"> <Set> "ready", "steady", "GO!", 1000 </Set> </dcs.Var> <dc.Out>TestVar1 is {$TestVar1}<br /></dc.Out>

Output:

TestVar1 is [ "ready", "steady", "GO!", 1000 ]

Update (List)

The Update operation is similar to Set but will add on to an exising list and not clear out the values beforehand.

<dcs.Var Name="TestVar1" Type="List"> <AddItem Type="String" Value="car" /> <AddItem Type="String" Value="sun" /> <AddItem Type="String" Value="lime" /> <AddItem Type="Integer" Value="32" /> </dcs.Var> <dcs.With Target="$TestVar1"> <Update> "ready", "steady", "GO!", 1000 </Update> </dcs.With> <dc.Out>TestVar1 is {$TestVar1}<br /></dc.Out>

Set (Record)

The Set operation tried to parse a JSON like objective between the Set tags and assign the appropriate fields to the Record. (For more on on JSON, click here ) Note that the text does not need to be in exact, strict JSON format and the text can potentially be parsed from a JavaScript object, for example.

<dcs.Var Name="TestVar1" Type="Record"> <Set> { "Name": "Bob", "Age": 35 } </Set> </dcs.Var> <dc.Out>TestVar1 is {$TestVar1}<br /></dc.Out>

Output:

TestVar1 is { "Age": 35, "Name": "Bob" }

Update (Record)

The Update operation is similar to Set but will try to update existing fields and add new ones to a Record with already existing information.

<dcs.Var Name="TestVar1" Type="Record"> <SetField Name="Name" Type="String" Value="Dave" /> <SetField Name="Hometown" Type="String" Value="Bobville" /> </dcs.Var> <dc.Out>TestVar1 is {$TestVar1}<br /></dc.Out> <dcs.With Target="$TestVar1"> <Update> { "Name": "Bob", "Age": 35 } </Update> </dcs.With> <dc.Out>TestVar1 is {$TestVar1}<br /></dc.Out>

Output:

TestVar1 is { "Name": "Dave", "Hometown": "Bobville" } TestVar1 is { "Age": 35, "Name": "Bob", "Hometown": "Bobville" }

Below is an example of a Record variable with nested Lists and Records inside.

<dcs.Var Name="TestRecord1" Type="Record"> <Set> <Field Name="FullName" Value="Andy" /> <Field Name="Phone">608-333-8936</Field> <Field Name="Colors"> <List> <Item Value="green" /> <Item>orange</Item> </List> </Field> <Field Name="Address"> <Record> <Field Name="City" Value="Madison" /> <Field Name="State" Value="WI" /> </Record> </Field> <Field Name="Employers"> <List> <Record> <Field Name="Name" Value="Epic" /> <Field Name="Boss" Value="Dann" /> </Record> <Record VarName="TestRecord1MATCInfo"> <Field Name="Name" Value="MATC" /> <Field Name="Boss" Value="Sallly" /> </Record> <List VarName="TestRecord1EmpList"> <Item Value="ISU" /> <Item>ipswitch</Item> </List> <Item>self</Item> </List> </Field> </Set> </dcs.Var>

Output:

{ "Phone": "608-333-8936", "FullName": "Andy", "Colors": [ "green", "orange" ] , "Address": { "State": "WI", "City": "Madison" } , "Employers": [ { "Boss": "Dann", "Name": "Epic" } , { "Boss": "Sallly", "Name": "MATC" } , [ "ISU", "ipswitch" ] , "self" ] }