grammar Statement
The grammar statement contains a number of sub-statements which describe how the attached schemes' input and output is written.
The grammar must be given a unique (within all other grammars) code name by which it can be referred to. It may then contain the following sub-statements in between '{' and '}' braces.
grammar Sub-Statement List | ||
---|---|---|
Sub-Statement | Use | Example |
inherit | Inherit all the settings from a previously defined grammar. | inherit j; |
fields | List of base fields, must match base order. | fields year month day; |
optional | Use the listed optional fields. | optional wday, ce, ceyear; |
rank | The field ranking used by the format sub-statements. | rank ce, ceyear, month, day, wday; |
lexicons | The list of lexicons used with this grammar. | lexicons m, w, jce; |
calculate | Calculate an element based on other fields. | calculate Era {output @if(year<500,ce,?);} |
alias | Allow the use of more user friendly field names. | alias field {WDay, wday; ...} |
format | The description of a format. | format dmy, "(Day) |(Month:m:a) |(Year)"; |
pref | The preferred format to use, unless otherwise stated. | pref dmy; |
inherit Sub-Statement
Create a new grammar by extending an existing one. The action of the original grammar is not changed in any way.
fields Sub-Statement
Declare the fields that match the scheme base fields. This list is checked whenever the grammar is attached to a scheme. If the match fails, an error is generated.
If the grammar inherits, then the inherited fields are appended to these fields, if any.
optional Sub-Statement
Declare all the optional fields required. The format definitions can only refer to the default fields for the base calendar plus the extended fields listed here.
This sub-statement must be positioned before any sub-statement that uses these fields.
rank Sub-Statement
This is the ranking order to be used by the format statements, unless the format statement has its own rank sub-statement.
lexicons Sub-Statement
Declare all the lexicon statements to be used. The format definitions can only refer to the lexicons listed here.
calculate Sub-Statement
Creates a new field which is not part of the scheme's record, but related to it by means of a mathematical expression.
grammar calculate Sub-Statement | ||
---|---|---|
Sub-Statement | Use | Example |
output | An expression to process the element before outputting. | output @if( year<500, ce, ? ); |
pseudo | The text to show in the pseudo date for this element. | pseudo "[CE<500]"; |
alias Sub-Statement
Provide user friendly alternative names for the base and optional field names. Because HistoryCal Script is case sensitive and the built-in field name are always lower case, the alias sub-statement is often used to give a proper cased name.
When referring to a field by name, either the alias or the default name may be used.
The alias has one of the type names listed in the table below, followed by a series of name pairs giving the alias name followed by a comma and then the field name. The pairs are separated by ';' semi-colons and the list enclosed in between '{' and '}' braces.
grammar alias Sub-Statement | ||
---|---|---|
Sub-Statement | Use | Example |
alias field | Allow the use of more user friendly field names. | alias field {WDay, wday; ...} |
alias pseudo | The pseudonym matching numbers in the pseudo date. | alias pseudo {w, WDay; dd, Day; ...} |
alias unit | Alternative field name when used as a unit. | alias field {d, day; m, month; ...} |
alias field Sub-Statement
Create user friendly names for the fields used in the format strings.
alias pseudo Sub-Statement
When the date format needs to show that numbers will be displayed for a particular element in a particular position, the pseudo alias shown here will be used in creating the pseudo date.
alias unit Sub-Statement
This area is still being worked and evolving.
The universal unit format ":u" expects input in one or more 'number unit' pairs. The unit given is (in order of lookup) the unit alias, the field alias or the default field name.
format Sub-Statement
Apart from the grammar:format signature, the format sub-statement is the same as format statement.
A grammar may have many format sub-statements.
pref Sub-Statement
The preferred format to use. If this sub-statement is missing, the first format listed is used.