// TSyntaxMemoParser Script     for TABLO language
//--------------------------------------------------------------------------------------------------------------------
// The TABLO language is used as part of a suite of programs to
// solve economic models. It is laid out in much the same style as
// other programming languages. The language is not case sensitive
// or line based.
//
// It consists of a sequence of statements terminated by semicolons.
// A statement can span several lines or there can be several
// statements on one line;
//
// Each statement is associated with a keyword.  Normally, the
// statement begins with this keyword, but if not, the keyword
// associated with the preceding statement applies.  In other words,
// the initial keyword may be omitted, if it is the same as in the
// preceding statement.
//
// As well as keywords, there are reserved words including built-in
// functions. Keywords and reserved words are to appear bold.
//
// STRONG COMMENTS begin '![[!' and end with '!]]!'. All within to
// be coloured blue italic. WEAK COMMENTS begin '!' and end with
// '!'. All within to be coloured blue italic. Strong comments can
// be used to comment out a whole block of code that itself contains
// weak comments. There is no "end-of-line" comment.
//
// There are user declared identifiers (variables, coefficients,
// sets, files and equations) They are strings composed of the
// letters A-Z,a-z,0-9,underscore and @. However the first letter
// must be one of A-Z,a-z. User declared identifiers are to be
// coloured navy.
//
// A "line-no" consists of a "~" (tilde) character, followed by one
// or more digits 0-9,followed by a colon. It is coloured hotspot
// red.
//
// Operator symbols [+-*/=<>()[]{}^;:], '<>' '<=' '>=' are to be
// coloured normally except for the brace symbols '[]{}' which are
// to be bold;
//
// There are 2 sorts of string constants: "Double-quotes" are
// enclosed in double-quotes and are to be coloured maroon italic.
// "Descriptions" are enclosed in hashes (#) and are to be coloured
// normal italic. Neither type of string constant ought to enclose
// a line break.
//
//--------------------------------------------------------------------------------------------------------------------
// Macro definitions. Parameters may be specified and the replacement text terminates with the end of
// line (watch trailing blanks).
//
#define pt_DEFAULT                  0
#define pt_IDENTIFIER               1
#define pt_NUMBER                   2
#define pt_FUNCTION                 3
#define pt_RESERVED                 4
#define pt_COMMENT_WEAK             5
#define pt_COMMENT_STRONG           6
#define pt_SYMBOL                   7
#define pt_DOUBLEQUOTE              8
#define pt_DESCRIPTION              9
#define pt_KEYWORD                 10
#define pt_BRACE                   11
#define pt_LINENO                  12
#define pt_SEMICOLON               13
// for the analyser
#define pt_ShockedVar              14
#define pt_ExoNotShocked           15
#define pt_Endog                   16
#define pt_SubbedOut               17
#define pt_MixedClos               18

#define _letter_                 '[A-Za-z]'
#define _identchar_                 '[0-9@A-Z_a-z]'
#define _non_alpha_                 '[^_0-9@A-Z_a-z]'
#define _all_chars_                 '[\x00-\xFF]'
#define _dec_digit_                 '[0-9]'
#define _dont_care_                 _all_chars_
#define _DEFAULT_BACKGROUND         clWhite
#define _DEFAULT_FOREGROUND         clBlack

//--------------------------------------------------------------------------------------------------------------------
// %%language section
// Header section. Describes the textual name of the language, case sensitivity and options used by the language.
//
%%language
Name                      = 'GEMPACK'
Case                      = __INSENSITIVE
//eo_DEFAULT   =    eo_SYNTAX_HIGHLIGHT    { Default options -- print syntax h/lighting }
//                  or eo_PRINT_WRAP       { Wrap lines when printing                   }
//                  or eo_PRINT_LINENOS    { Print line numbers                         }
//                  or eo_PRINT_FILENAME   { Print filename in header                   }
//                  or eo_PRINT_DATE       { Print date in header                       }
//                  or eo_PRINT_PAGENOS    { Print page numbers at bottom of page       }
//                  or eo_AUTOINDENT       { Auto-indent on                             }
//                  or eo_TABCOLUMN        { TAB to next column                         }
//                  or eo_WORD_SELECT;
Options  = __DEFAULT_OPTIONS-__OPT_PRINT_LINENOS-__OPT_AUTOINDENT - __OPT_USE_TAB - __OPT_TABCOLUMN - __OPT_SMART_FILL
//Options =2+ __OPT_PRINT_WRAP+__OPT_PRINT_FILENAME+__OPT_PRINT_DATE+__OPT_PRINT_PAGENOS+__OPT_TABCOLUMN
//Options = __OPT_PRINT_WRAP+ //__OPT_PRINT_LINENOS+ __OPT_PRINT_FILENAME+ __OPT_PRINT_DATE+ __OPT_PRINT_PAGENOS //__OPT_WORDWRAP+ //__OPT_AUTOINDENT+ //__OPT_TABCOLUMN+ //__OPT_WRAP_OVERRIDE
// had a lot of trouble with the above.......
// effect I want is default except that:
//    not print linenos
//    not autoindent
//    not wordwrap onscreen
//    show visible margin at column 80


TabDefault = 4
WordWrapColumn            = 80
Gutter                    = _DEFAULT_GUTTER
Anchor                    = _DEFAULT_START_ANCHOR
FontName                  = 'Courier New'
ExampleText               = '! Here\'s a weak comment !\n\
                            \Coefficient TINY # very small number #;\n\
                            \![[! Here\'s a strong comment !]]!\n\
                            \Formula TINY = {0.0001}/10;\n\
                            \Write TINY to file STORE header "H001"\n\
                            \    longname "tiny number";\n'
EditableStyles              ('Reserved word', pt_RESERVED),
                            ('Weak Comment',  pt_COMMENT_WEAK),
                            ('Strong Comment',pt_COMMENT_STRONG),
                            ('Identifier',    pt_IDENTIFIER),
                            ('Description',   pt_DESCRIPTION),
                            ('Number',        pt_NUMBER),
                            ('Symbols',       pt_SYMBOL),
                            ('Quoted',        pt_DOUBLEQUOTE),
// WAS                            ('Default',       pt_DEFAULT)
                            ('Default',       pt_DEFAULT),
// Temporary to allow changing on the fly
                            ('Shocked Var',       pt_ShockedVar),
                            ('Exo Not Shocked Var',       pt_ExoNotShocked),
                            ('Endogenous Var',       pt_Endog),
                            ('Subbed Out',       pt_SubbedOut),
                            ('Mixed Exog/Endog',       pt_MixedClos)

//--------------------------------------------------------------------------------------------------------------------
// %%words section
//
// Used to specify simple language keywords.  These are constant value
// lexemes that always contain the same characters and only require the
// end style to be specified.  The words present here will always be
// tried first.  If they fail then the entries in the %%tokens section
// will be allowed to try a match.

// %%words table entries have 3 columns:
//  Column 1  Quoted string giving the characters that make up the word
//  Column 2  Quoted string that specifies how the word is terminated
//  Column 3  Token value returned when word is recognised
//
%%words
'![[!'                  _dont_care_                 pt_COMMENT_STRONG
'!'                     _dont_care_                 pt_COMMENT_WEAK
'#'                     _dont_care_                 pt_DESCRIPTION
'"'                     _dont_care_                 pt_DOUBLEQUOTE
'~'                     _dont_care_                 pt_LINENO
'+'                     _dont_care_                 pt_SYMBOL
'-'                     _dont_care_                 pt_SYMBOL
'*'                     _dont_care_                 pt_SYMBOL
'\/'                    _dont_care_                 pt_SYMBOL
'<='                    _dont_care_                 pt_SYMBOL
'>='                    _dont_care_                 pt_SYMBOL
'='                     _dont_care_                 pt_SYMBOL
'<>'                    _dont_care_                 pt_SYMBOL
'<'                     _dont_care_                 pt_SYMBOL
'>'                     _dont_care_                 pt_SYMBOL
'('                     _dont_care_                 pt_SYMBOL
')'                     _dont_care_                 pt_SYMBOL
'['                     _dont_care_                 pt_BRACE
']'                     _dont_care_                 pt_BRACE
'{'                     _dont_care_                 pt_BRACE
'}'                     _dont_care_                 pt_BRACE
'^'                     _dont_care_                 pt_SYMBOL
','                     _dont_care_                 pt_SYMBOL
';'                     _dont_care_                 pt_SEMICOLON
':'                     _dont_care_                 pt_SYMBOL
'assertion'             _non_alpha_                 pt_KEYWORD
'coefficient'           _non_alpha_                 pt_KEYWORD
'display'               _non_alpha_                 pt_KEYWORD
'formula & equation'    _non_alpha_                 pt_KEYWORD
'equation'              _non_alpha_                 pt_KEYWORD
'file'                  _non_alpha_                 pt_KEYWORD
'formula'               _non_alpha_                 pt_KEYWORD
'mapping'               _non_alpha_                 pt_KEYWORD
'read'                  _non_alpha_                 pt_KEYWORD
'set'                   _non_alpha_                 pt_KEYWORD
'subset'                _non_alpha_                 pt_KEYWORD
'update'                _non_alpha_                 pt_KEYWORD
'transfer'              _non_alpha_                 pt_KEYWORD
'variable'              _non_alpha_                 pt_KEYWORD
'write'                 _non_alpha_                 pt_KEYWORD
'zerodivide'            _non_alpha_                 pt_KEYWORD
// Complementarity added for Release 8.0
'complementarity'       _non_alpha_                 pt_KEYWORD

'$POS'                  _non_alpha_                 pt_RESERVED
'allsets'               _non_alpha_                 pt_RESERVED
'all'                   _non_alpha_                 pt_RESERVED
'and'                   _non_alpha_                 pt_RESERVED
'by_elements'           _non_alpha_                 pt_RESERVED
'change'                _non_alpha_                 pt_RESERVED
'default'               _non_alpha_                 pt_RESERVED
'elements'              _non_alpha_                 pt_RESERVED
'for_updates'           _non_alpha_                 pt_RESERVED
'from'                  _non_alpha_                 pt_RESERVED
'gams'                  _non_alpha_                 pt_RESERVED
'header'                _non_alpha_                 pt_RESERVED
'initial'               _non_alpha_                 pt_RESERVED
'integer'               _non_alpha_                 pt_RESERVED
'intersect'             _non_alpha_                 pt_RESERVED
'is'                    _non_alpha_                 pt_RESERVED
'levels'                _non_alpha_                 pt_RESERVED
'linear'                _non_alpha_                 pt_RESERVED
'longname'              _non_alpha_                 pt_RESERVED
'maximum'               _non_alpha_                 pt_RESERVED
'new'                   _non_alpha_                 pt_RESERVED
'not'                   _non_alpha_                 pt_RESERVED
'none'                  _non_alpha_                 pt_RESERVED
'of'                    _non_alpha_                 pt_RESERVED
'off'                   _non_alpha_                 pt_RESERVED
'onto'                  _non_alpha_                 pt_RESERVED
'orig_level'            _non_alpha_                 pt_RESERVED
'or'                    _non_alpha_                 pt_RESERVED
'parameter'             _non_alpha_                 pt_RESERVED
'prod'                  _non_alpha_                 pt_RESERVED
'size'                  _non_alpha_                 pt_RESERVED
'sum'                   _non_alpha_                 pt_RESERVED
'LE'                    _non_alpha_                 pt_RESERVED
'LT'                    _non_alpha_                 pt_RESERVED
'EQ'                    _non_alpha_                 pt_RESERVED
'NE'                    _non_alpha_                 pt_RESERVED
'GE'                    _non_alpha_                 pt_RESERVED
'GT'                    _non_alpha_                 pt_RESERVED
// TO not for analyser since GTAP has a variable called to
'to'                    _non_alpha_                 pt_RESERVED
'text'                  _non_alpha_                 pt_RESERVED
'updated'               _non_alpha_                 pt_RESERVED
'union'                 _non_alpha_                 pt_RESERVED
'unread'                _non_alpha_                 pt_RESERVED
'unwritten'             _non_alpha_                 pt_RESERVED
'zero_by_zero'          _non_alpha_                 pt_RESERVED
'nonzero_by_zero'       _non_alpha_                 pt_RESERVED
// Lower/upper_bound added for Complementarity
'lower_bound'           _non_alpha_                 pt_RESERVED
'upper_bound'           _non_alpha_                 pt_RESERVED

'ABS'                   _non_alpha_                 pt_FUNCTION
'EXP'                   _non_alpha_                 pt_FUNCTION
'ID01'                  _non_alpha_                 pt_FUNCTION
'ID0V'                  _non_alpha_                 pt_FUNCTION
'LOG10'                 _non_alpha_                 pt_FUNCTION
'LOGE'                  _non_alpha_                 pt_FUNCTION
'MAX'                   _non_alpha_                 pt_FUNCTION
'MIN'                   _non_alpha_                 pt_FUNCTION
'SQRT'                  _non_alpha_                 pt_FUNCTION
// for analyser
// 'VeryWierdShockedVar'   _non_alpha_                 pt_ShockedVar   
// 'VeryWierdExoNotShocked'   _non_alpha_              pt_ExoNotShocked   
// 'VeryWierdEndog'       _non_alpha_                 pt_Endog   
// 'VeryWierdSubbedOut'   _non_alpha_                 pt_SubbedOut   
// 'VeryWierdMixedClos'   _non_alpha_                 pt_MixedClos   
// magic place for analyser

//--------------------------------------------------------------------------------------------------------------------
//
// %%handler section
//
// The %%handler section gives rules to be applied once an entry in the %%words
// table has been recognised. Normally
// no further processing is required but sometimes a token starts with
// a fixed set of characters but may be followed
// by a character class rather than a known sequence.
//
// %%handler table entries have 4 columns:
//     Column 1          Token value to be processed
//     Column 2          Character specifier that follows recognised word
//     Column 3          Quoted string specifying end sequence
//     Column 4          Whether end sequence is part of lexeme
//
// The <character specifier> is defined as:
//     Column 2          A single character specifier or pre-defined system character macro:
//                         _PASCAL_CHAR         Pascal style character specifier
//                         _C_CHAR              C style character specifier
//                       If the lexeme can optionally have these characters then append '?' to the end
//                       of the quoted string.
//     Column 3          Up to 2 characters may be given as a sequence to terminate the lexeme.
//                       Characters are specified using a simplified regular expression. If this
//                       string is empty then the lexeme will never be matched.
//
%%handler
// pt_COMMENT_STRONG     _all_chars_?    '!]]!'     _use_
pt_COMMENT_STRONG   match(42)
pt_COMMENT_WEAK       '[^!]'?         '!'        _use_
pt_DESCRIPTION        '[^#]'?         '[#\n]'    _use_
pt_DOUBLEQUOTE        '[^"]'?         '["\n]'    _use_
pt_LINENO             _dec_digit_     ':'        _use_

//--------------------------------------------------------------------------------------------------------------------
//
// %%tokens section
//
// Used to specify how to recognise non-fixed lexemes. Non-fixed lexemes are only tried if the table entries in the
// %%words section have failed. The non-fixed lexeme is defiened by 5 columns as below:
//     Column 1          Token value
//     Column 2          Single start character specifier
//     Column 3          Single contains character specifier
//     Column 4          End sequence specifier
//     Column 5          Whether end sequence is part of lexeme
// Pre-defined token styles are implemented.
// If used they should be specified in Column 2. The implemented ones are:
//  __STD_PASCALSTRING   Pascal string -- starts with ' ands with ' and uses '' to represent
//                       ' within a string. Does not extend beywond end of line.
//  __STD_IDENTIFIER     Standard identifier. Starts with [_a-zA-Z], contains [_a-zA-Z0-9] and ends with
//                       a non-alpha numeric character that is not part of the lexeme
//  __STD_NUMBER_OR_FP   Integer or floating point constant of syntax:
//                           <Digit String> [ '.' <Digit string> ] [ e|E [+-] <Digit string> ]
//
%%tokens
//pt_IDENTIFIER       '[a-zA-Z]' '[_@a-zA-Z0-9]'? '[^_@a-zA-Z0-9]' _discard_
pt_IDENTIFIER       _letter_  _identchar_?  _non_alpha_  _discard_
pt_NUMBER            __STD_NUMBER_OR_FP
pt_DEFAULT          '[\s\t\n]'  '[\s\t\n]'? '[^\s\t\n]' _discard_


//--------------------------------------------------------------------------------------------------------------------
//
// %%effects section
//
// Used to specify the default colors and font styles used for each token
//
//     Column 1          Token value
//     Column 2          Font styles
//     Column 3          Foreground color
//     Column 4          Background color
//     Column 5          Optional column specifying whether map entry is a 'hotspot'
//
// Columns 1-4 must be completed for all rows, Column 5 defaults to non-hotspot.
//
%%effects
//pt_DEFAULT      []         _DEFAULT_FOREGROUND  clYellow
pt_DEFAULT      []         _DEFAULT_FOREGROUND  _DEFAULT_BACKGROUND
pt_IDENTIFIER   []         clGreen              _DEFAULT_BACKGROUND
pt_DOUBLEQUOTE  [fsItalic] clMaroon             _DEFAULT_BACKGROUND
pt_DESCRIPTION  [fsItalic] _DEFAULT_FOREGROUND  _DEFAULT_BACKGROUND
pt_COMMENT_WEAK [fsItalic] clBlue               _DEFAULT_BACKGROUND
pt_COMMENT_STRONG []       clBlack               clAqua
pt_RESERVED     [fsBold]   _DEFAULT_FOREGROUND  _DEFAULT_BACKGROUND
pt_NUMBER       []         _DEFAULT_FOREGROUND  _DEFAULT_BACKGROUND
pt_SYMBOL       []         _DEFAULT_FOREGROUND  _DEFAULT_BACKGROUND
pt_LINENO       []         clRed                _DEFAULT_BACKGROUND 'hotspot'

pt_ShockedVar       [fsBold]      clRed             _DEFAULT_BACKGROUND
pt_ExoNotShocked    [fsItalic]    clRed             _DEFAULT_BACKGROUND 
// pt_Endog is same as pt_IDENTIFIER
pt_Endog            []      clGreen            _DEFAULT_BACKGROUND 
// Are also clDkGray and clLtGray (Dark and Light Gray)
// Are also clNavy and clPurple
// Are also clMaroon
pt_SubbedOut        [fsItalic]    clGray            _DEFAULT_BACKGROUND
pt_MixedClos        [fsBold]      clPurple           _DEFAULT_BACKGROUND



//--------------------------------------------------------------------------------------------------------------------
//
// %%map section
//
// Used to specify which entry in the %%effects table each token value uses. By default all token values map onto
// __DEFAULT_TOKEN which is defined as zero. Table has 2 columns:
//     Column 1          Recognised token value
//     Column 2          Map table entry (i.e. %%effects table entry)
// Normally the %%map table consists of identical value entries.
%%map
pt_IDENTIFIER           pt_IDENTIFIER
pt_NUMBER               pt_NUMBER
pt_COMMENT_STRONG       pt_COMMENT_STRONG
pt_LINENO               pt_LINENO
pt_COMMENT_WEAK         pt_COMMENT_WEAK
pt_DESCRIPTION          pt_DESCRIPTION
pt_DOUBLEQUOTE          pt_DOUBLEQUOTE
pt_RESERVED             pt_RESERVED
pt_BRACE                pt_RESERVED
pt_FUNCTION             pt_RESERVED
pt_KEYWORD              pt_RESERVED
pt_SYMBOL               pt_SYMBOL
pt_SEMICOLON            pt_SYMBOL

pt_ShockedVar      pt_ShockedVar
pt_ExoNotShocked   pt_ExoNotShocked
pt_Endog           pt_Endog
pt_SubbedOut       pt_SubbedOut
pt_MixedClos       pt_MixedClos
