Template-Axiom-Query (TAQ)

Scopes

A scope combines a namespace, a locale and properties. The locale provides context-sensitive formatting and parsing of numbers and currencies. A scope can also contain variables that are evaluated prior to the launch of a query.

The TAQ compiler automatically creates the initial scope, called the "global" scope because it is the fallback location to find an artifact when a search from within a non-global scope comes up empty. Any additional scope can only be declared in the global scope as nesting of scopes is not allowed.

A scope change is possible when a query progresses from one stage to the next or when a query call occurs. A scope change is signaled by the use of a 2-part name for the target,

Attributes

There is a small set of attributes shared by all scopes. To get the scope name, use the notation

scope.name

The other attributes relate to locale and are covered in Locales.

Properties

A scope declaration may define one or more properties. To read a property, use the scope keyword with a right arrow -> pointing to the property name. calc-square-miles3.taq has 3 queries which display the area of USA and Australia using units of either square kilometers or square miles depending on which query is used. It uses a "location" scope property to signify the country for which the application is targeted which in turn indicates what units to use. The property is read as scope->location.

One thing to keep in mind is that unless all scopes, including the global one, define the same property, then there is the risk of an attempt to read a property in a scope where it is not defined. Doing so causes a blank value to be returned. A blank matches an empty string and can be updated to a value of any type. calc-square-miles3.taq includes a query in the global scope for which the location property is not defined. In this case, the query completes, as intended, using the default square kilometers unit.

scope usa (location = "United States")
scope australia (location = "Australia")

flow country_area
(
country ? { "United States" , "Australia" },
double surface_area = surface_area_Km2,
string units = "km2",
? scope->location == "United States"
{ surface_area *= 0.3861, units = "mi2" }
)

query<axiom> au_surface_area_query(surface_area : australia.country_area)
query<axiom> us_surface_area_query(surface_area : usa.country_area)
query<axiom> xx_surface_area_query(surface_area : country_area)

Context List

A context list is one which has a reserved combination of name and type. Several scopes can then each contain a context list which is referenced by name but only one is selected depending on which is the current scope. The reservation of the list type ensures interoperability when switching between scopes. This feature requires a context list declaration to be placed at the top of an TAQ program. It is distinguished by placing a dollar sign in front of a list declaration containing just a name and type:

$ list<type> name.

In normal usage, a context list is created for every scope other than the global scope. Then all context list references are placed in the global scope. This allows global templates and flows to be shared among scopes.

Word Translation Example

foreign-total.taq has German and French scopes each configured with a query to print out a Euro amount + 10% tax along with the word "Total" in the language of the scope. The translation of the word "Total" is provided by a context term list named "lexicon".

$ list<term> lexicon

axiom german.lexicon
( Total)
{"Gesamtkosten"}
axiom french.lexicon>
( Total)
{""le total"}

Notice when an axiom list is declared with only a single axiom, the compiler automatically creates an axiom term list to reference the same axiom as well.

This is the template which formats the text to output:

template format_total
{ currency amount }
(
. amount *= 1.1,
string total_text =
lexicon->Total + " + tax: " + amount.format()
)

The context list works here because the "format_total" template is referenced by the French query as "french.format_total". and by the German query as "german.format_total".

The solution to the query is:

total_text = Gesamtkosten + tax: 13.580,24 EUR
total_text = le total + tax: 13 580,24 EUR