Glich - v0.3.0 Manual
Define grammar
Home Development v0.3.0 Manual Hics Extension Define grammar

Statement: grammar

The grammar statement contains a number of sub-statements which describe how a scheme's 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-StatementUseExample
nameGive the grammar a text description.name "Julian calendar schemes";
inheritInherit all the settings from a previously defined grammar.inherit j;
fieldsList of base fields, must match base order.fields year month day;
calculatedList of calculated fields.calculated ce ceyear;
optionalList of optional fields.optional wday;
rankThe field ranking used by the format sub-statements.rank ce ceyear month day;
lexiconsThe list of lexicons used with this grammar.lexicons m w jce;
aliasAllow the use of alternative field names.alias field {WDay wday; ...};
functionA function to be available to an attached scheme.function code { ... result = this; };
useIndicate when functions are created by the scheme.use epoch;
formatThe description of the formats.format dmy "{day} |{month:m:a} |{year}";
preferredThe preferred format to use, unless otherwise stated.preferred dmy;

Sub-Statement: name

Gives a descriptive name to the grammar. This gives a way to document the purpose of the grammar, which will help in reuse.

Sub-Statement: inherit

Create a new grammar by extending an existing one. The action of the original grammar is not changed in any way.

Sub-Statement: fields

Declare the required fields that match the intended scheme base required 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 those given.

Sub-Statement: calculated

List fields which are calculated based on the required fields.

Sub-Statement: optional

Declare all the optional fields required. The format definitions can only refer to the required and calculated fields plus the extended fields listed here.

Sub-Statement: rank

This is the ranking order to be used by the format statements, unless the format statement has its own rank sub-statement.

Ranking is used with shortcut ranges. For example, "Jul 2023" is a shortcut for the range of all the days in July 2023.

We create the shortcut by omitting the fields to the right of the ranking list.

Sub-Statement: lexicons

Declare all the lexicon statements to be used. The format definitions can only refer to the lexicons listed here.

Sub-Statement: alias

In a number of places, it is preferable to use a different name than the default. The statement takes the form:-

alias type { alias field-name; alias field-name; ... };

Where type is one of: field, pseudo, unit or lexicon.

grammar alias Sub-Statement
Sub-StatementUseExample
alias fieldAllow the use of more user friendly field names.alias field {WDay wday; ...};
alias pseudoThe pseudonym matching numbers in the pseudo date.alias pseudo {w wday; dd day; ...};
alias unitAlternative field name when used as a unit.alias field {d day; m month; ...};
alias lexiconWhen the register name does not match the lexicon name.alias lexicon {wday day; ...};

Note, the alias does not replace the field-name, but gives a preferred alternative.

Sub-Statement: alias field

Create user friendly names for the fields used in the format strings.

Sub-Statement: alias pseudo

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.

Note, if a lexicon is used to provide output, the pseudo name will be provided by the lexicon definition.

Sub-Statement: alias unit

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.

Sub-Statement: function

This defines a function that can be used by any scheme which has attached the grammar. The function is defined in the same way as an object function.

The fixed, calculated and optional field names will be available to the function as local variables. To actually make changes to the scheme object, the function should set the result to 'this' (the modified scheme object).

The following functions are required when using calculated fields.

  1. A function named calculate. Converting a jdn (Julian Day Number) to a text string which uses calculated fields. The jdn is converted into the fixed fields and a function would complete the calculated fields before formulating the text string.
  2. A function named fixed When converting a text string to a jdn. The date elements are composed into their fields and any calculated fields are used to complete the fixed fields. The fixed fields are then used to obtain the jdn value.

If there are different ways to find the fixed fields, different formats may require the use of different functions depending on the calculated fields used. If a format does not use the "fixed" function for text input then it can be specified it with the use:in sub-statement.

Sub-Statement: use

Used to indicate when functions are automatically created by the scheme. The "calculated" and "fixed" functions are created when the grammar is attached to the scheme.

grammar use Sub-Statement
CodeNoteExample
use epoch; Used with schemes that define an epoch date. use epoch;

Sub-Statement: format

Apart from the grammar:format signature, the format sub-statement is the same as format statement.

A grammar may have many format sub-statements.

Sub-Statement: preferred

The preferred format to use. If this sub-statement is missing, the first format listed is used.

Home Development v0.3.0 Manual Hics Extension Define grammar

Managed by WebPageLayout Validated by HTML Validator (based on Tidy)

20th June 2023