# Using the editor

## Introduction

The Mads editor gets automatically activated when a file with the name extention ‘.mads’ gets created or opened from the Package Explorer or the navigator.

In addition to the standard editing functions available through the Edit menu or the corresponding key combinations (e.g. Ctrl-C and Ctrl-V for Cut and Paste), the editor provides for two very important key-commands:

- the ctrl-space key combination triggers content assist (see below)
- the ctrl-slash key combination toggles the commenting-out of the line where the cursor is located

The key services provided by the editor are syntax checking and content assist, data validation, and variable scope.

### Contents

Syntax checking
Content assist
Data validation
Variable scope

## Syntax Checking

Syntax checking means that anything typed in the editor that does not conform to the Mads syntax will be flagged by red marks in the editor, both in the left margin and under the word(s) causing the error. The editor will then be in ‘error condition’ and it will not be possible to run calculations till the error is corrected. This is illustrated below, where the keyword plan has been mis-typed.

In addition, putting the cursor either over the wrong word or over the mark in the margin will display an error message. This is shown below. The message “no viable alternative at input 'plain'” tells us that this word has no meaning in the Mads syntax.

Back to top

## Content assist

The Content assist feature of the editor is triggered by the ctrl-space key combination. It will provide valid content proposals as well as templates for data entry, based on the position of the cursor in the text.

When a new .mads file is created manually, it is empty and the editor shows an error mark. Placing the cursor over the error mark will display the message: “mismatched input ' < EOF > ' expecting RULE_STRING”, meaning that string data is expected. Pressing by the ctrl-space key combination will display the following box:

The first line of the box tells us that the editor expects a piece of text within simple or double quotes (a STRING) that would correspond to the variable “countryName”. A double-click on that first line of the box will insert “countryName” in the text, and create an error mark saying that the string should be followed by a semicolon. The proper value of the string can then be entered. The last two lines of the box tell us that it is also possible to insert keywords, namely Country name or Nom du Pays, before the string with the actual name value.

The second and third lines of the box tell us that the editor could insert one of two templates for header data / empty model – by a double-click on the corresponding line of the box – in the text. Important tip : if double-clicking does not seem to work, insert a space in the empty file and try again.

The templates for header data, that are shown in the Headers section of the MADS Grammar, show a number of fields that are ‘boxed’ and display some default value. The tab key will jump the cursor from one such field to the next, and when a list of alternative values exists then one can be selected from a drop-down list, as shown below:

The image above also shows the way optional sections are often handled in a template. The double interrogation mark ?? is an illegal input and that draws the attention of the user to the need to either keep and complete that section, including deleting the two ?? , or delete it all-together.

Back to top

## Data validation

The editor makes the following checks on some of the data:

Headers:
- Opportunity cost of capital: OCC must be > 0 and <= 100
- ExchangeRate must be > 0
- Project life must be > 0

Debt service function: Grace on interest cannot be > grace

Table attributes: ‘totals’ and ‘allColumns’ do not apply to BUDGET tables

Table years:
- Table years must be > 0 and within project life
- Table years must be in increasing order
- Budget Table: list of years must be 2 values at most

Plan: A plan cannot include itself, either directly or through nested plans

Herd:
- Duration of age group classes must be > 0
- Initial and maximum size must be >= 0
- A data-by-cat section (i.e. ‘Parturition and milk’, ‘Intakes’, ‘Feed Requirements’ or ‘Other products and costs’) cannot include a herd class reference more than once

Back to top

## Variable scope

In Mads all data entities as well as script variables are given a unique ID name. By default, any ID would be ‘visible’, i.e. could be used, anywhere in the model definition text. The editor modifies this default behavior as follows:

- Reference to a plan ID in the definition of a plan: the ID of the plan being defined is not visible so that a plan cannot include itself as a component. Data validation also ensures that a plan cannot include itself through nested plans.

- Reference to a variable ID in the definition of a table: variables that were defined in a script as ‘local’ are not visible and thus cannot be referenced in a table definition.

- Reference to a variable ID in the definition of a script item: variables that were defined in a different script and as ‘local’ are not visible and thus cannot be referenced in a script definition.

- Reference to a herd age group ID is visible only as part of the specification of herd results for the corresponding Herd entity in a table or script.

Back to top