//--------------------------------------------------------------------------------------------------------------------
//
//
//
// Macro definitions. Parameters may be specified and the replacement text terminates with the end of
// line (watch trailing blanks).
//
#define ct_DEFAULT                  0
#define ct_COMMENT_LINE             1
#define ct_COMMENT_STAR             2
#define ct_IDENTIFIER               3
#define ct_STRING                   4
#define ct_NUMBER                   5
#define ct_COMMENT                  6
#define ct_OPERATOR                 7
#define ct_RESERVED                 8
#define ct_CHAR                     9
#define ct_VARIABLE					10
#define ct_MISC                     11
#define ct_KEYWORD                  12
#define ct_HEXNUMBER                13
#define ct_PHP						14
#define ct_PARENSTART				15
#define ct_PARENEND					16
#define ct_FUNCTION_KWD 			17
#define ct_FUNCTION_NAME			18
#define	ct_PHPEND					19
#define	ct_FUNCTION_CALL			20
// #define ct_INCLUDE					21
#define ct_MEMBER				    22
 
#define ss_DEFAULT					0
#define ss_FUNCTION_KWD 			1
#define ss_PHP						2

#define _alpha_chars_               '[_A-Za-z0-9]'
#define _non_alpha_                 '[^_A-Za-z0-9]'
#define _all_chars_                 '[\x00-\xFF]'
#define _no_chars_                  '[]'
#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                      = 'PHP Script'
Case                      = __INSENSITIVE
Options                   = __DEFAULT_OPTIONS + __OPT_LINE_NUMBERS - __OPT_SMART_FILL - __OPT_TABCOLUMN - __OPT_USE_TAB
WordWrapColumn            = _EDGE
Gutter                    = 24 // _DEFAULT_GUTTER
Anchor                    = _DEFAULT_START_ANCHOR
TabDefault				  = 2
ExampleText               = '/* Comment */\n\
                            \function bea_arthur($nude_photo = "yes")  {\n\
                            \  while ($i) doLook($i+42);\n\
                            \}\n'

EditableStyles              ('Comment',       ct_COMMENT),
                            ('String',        ct_STRING),
                            ('Reserved word', ct_KEYWORD),
                            ('Operator',      ct_MISC),
                            ('Identifier',    ct_IDENTIFIER),
                            ('Variable',	  ct_VARIABLE),
                            ('Number',        ct_NUMBER),
                            ('Function name', ct_FUNCTION_NAME),
                            ('Default',       ct_DEFAULT)




//--------------------------------------------------------------------------------------------------------------------
//
// %%words section
//
// Used to specify simple languge 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
//     Column 4          Optional state set in which the word is recognised in any one or more of the given states
//
%%words
'<?php'					_dont_care_				  ct_PHP 	 				
'<?'					_dont_care_				  ct_PHP					
'<?='					_dont_care_				  ct_PHP
'$'						_dont_care_				  ct_VARIABLE
'->'					_dont_care_				  ct_MEMBER				
'\/*'					_dont_care_				  ct_COMMENT_STAR 			 
'\/\/'					_dont_care_				  ct_COMMENT_LINE  			
'0'                     '[xX]'                    ct_HEXNUMBER							

%%kwtables

ForState [] endswith _non_alpha_
  (
   ct_OPERATOR is '++', '--', '+', '-', '*', '/', '&', '!', '~', '%', '>', 
       '<', '>>', '<<', '>=', '<=', '==', '=', '!=', '^', '|', '&&', '||', 
	   '?', ':', '+=', '-=', '*=', '/=', '%=', '>>=', '<<=', '&=', '^=', '|='
   ct_KEYWORD is 'include', 'require', 'auto', 'break', 'case', 'continue',
       'do', 'else', 'for', 'if', 'return', 'switch', 'while', 'array', 
	   'var', 'class', 'new', 'this', 'global', 'echo'			
   ct_MISC is ';', '[', ']', '{', '}'
   ct_FUNCTION_KWD is 'function'
   ct_PHPEND is '?>'
   ct_PARENSTART is '('
   ct_PARENEND is ')'
  )
  
//--------------------------------------------------------------------------------------------------------------------
//
// %%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
ct_COMMENT_LINE         '[^\n]'?                    '\n'           _discard_
ct_COMMENT_STAR         _all_chars_?                '*\/'          _use_
ct_VARIABLE             _alpha_chars_               _non_alpha_    _discard_
ct_MEMBER             	_alpha_chars_               _non_alpha_    _discard_
// ct_INCLUDE				_all_chars_					'[;\n]'		   _discard_
ct_HEXNUMBER            '[xX0-9A-Fa-f]'             '[^0-9a-fA-F]' _discard_

//--------------------------------------------------------------------------------------------------------------------
//
// %%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
ct_STRING             __STD_C_STRING
ct_CHAR               __STD_C_CHAR
ct_IDENTIFIER         __STD_IDENTIFIER
ct_NUMBER             __STD_NUMBER_OR_FP
//InState ss_PHP
//(
//  ct_FUNCTION_CALL		'[_a-zA-Z]'		  _alpha_chars_	 '('		 _discard_
//)

InState ss_FUNCTION_KWD
(
  ct_FUNCTION_NAME	    __STD_IDENTIFIER	   
)

//--------------------------------------------------------------------------------------------------------------------
//
// %%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
ct_DEFAULT              []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
ct_IDENTIFIER           []                          _DEFAULT_FOREGROUND         _DEFAULT_BACKGROUND
ct_STRING               []                  		clTeal                      _DEFAULT_BACKGROUND
ct_COMMENT              []                          clGreen                     _DEFAULT_BACKGROUND
ct_KEYWORD              [fsBold]                    clNavy                      _DEFAULT_BACKGROUND
ct_NUMBER               []                          clPurple  					_DEFAULT_BACKGROUND
ct_VARIABLE             []                          clBlue                      _DEFAULT_BACKGROUND
ct_MISC                 []                          clMaroon         			_DEFAULT_BACKGROUND
ct_PHP                  [fsBold]                    _DEFAULT_FOREGROUND			clYellow
ct_FUNCTION_NAME		[]							_DEFAULT_FOREGROUND			clSilver  // 'hotspot'
ct_FUNCTION_CALL		[]							clYellow					clBlack


%%states
ct_FUNCTION_KWD			(+[ss_FUNCTION_KWD])
ct_PARENSTART			(-[ss_FUNCTION_KWD])
// ct_PHP					(+[ss_PHP])
// ct_PHPEND				(-[ss_PHP])

//--------------------------------------------------------------------------------------------------------------------
//
// %%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
ct_IDENTIFIER           ct_IDENTIFIER
ct_STRING               ct_STRING
ct_NUMBER               ct_NUMBER
ct_COMMENT              ct_COMMENT
ct_COMMENT_LINE         ct_COMMENT
ct_COMMENT_STAR         ct_COMMENT
ct_FUNCTION_KWD         ct_KEYWORD
ct_KEYWORD              ct_KEYWORD
ct_MISC                 ct_MISC
ct_PARENSTART           ct_MISC
ct_PARENEND             ct_MISC
ct_VARIABLE				ct_VARIABLE
ct_CHAR                 ct_STRING
ct_OPERATOR             ct_MISC
ct_HEXNUMBER            ct_NUMBER
ct_PHP					ct_PHP
ct_PHPEND				ct_PHP
ct_FUNCTION_NAME		ct_FUNCTION_NAME
ct_FUNCTION_CALL		ct_FUNCTION_CALL
// ct_INCLUDE				ct_KEYWORD
ct_MEMBER				ct_VARIABLE