# FTE mode for editing REXX files
# enhanced from the original by Michael DeBusk
# debu4335@eclipsetel.com
# Revision March 19, 2001

# Header Comment
# Note: If the environment variable USER is set,
# This macro will insert the contents after the
# word "Author:" and leave the cursor after
# "Purpose:". If it is not set, the macro will
# fail after "Author:".
sub REXX_Heading {
    InsertString "/*";
    LineNew; InsertString "* Filename: ";
    InsertString $FileName;
    LineNew; InsertString "*   Author: ";
    LineNew; InsertString "*  Created: ";
    InsertDate;
    LineNew; InsertString "*  Purpose: ";
    LineNew; InsertString "*  Changes: ";
    LineNew; InsertString "*/";
    4:MoveUp; MoveLineEnd; InsertUid;
    2:MoveDown; MoveLineEnd;
}

#Comment a blocked string
sub REXX_Comment {
    ?MoveBlockStart; InsertString "/* ";
    ?MoveBlockEnd; InsertString " */"; BlockUnmark;
}

# Load external functions
sub REXX_RexxUtil {
    InsertString "/* Load RexxUtil Library */";
    LineNew; InsertString "If RxFuncQuery('SysLoadFuncs') Then";
    LineNew; InsertString "Do";
    LineNew; InsertString "Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'";
    LineNew; InsertString "Call SysLoadFuncs";
    LineNew; InsertString "End";
    2:LineNew;
}

%if(OS_OS2)
sub REXX_RxSock {
    InsertString "/* Load RxSock Library */";
    LineNew; InsertString "If RxFuncQuery('SockLoadFuncs') Then";
    LineNew; InsertString "Do";
    LineNew; InsertString "Call RxFuncAdd 'SockLoadFuncs','RxSock','SockLoadFuncs'";
    LineNew; InsertString "Call SockLoadFuncs";
    LineNew; InsertString "End";
    2:LineNew;
}

sub REXX_RxFTP {
    InsertString "/* Load RxFTP Library */";
    LineNew; InsertString "If RxFuncQuery('FTPLoadFuncs') Then";
    LineNew; InsertString "Do";
    LineNew; InsertString "Call RxFuncAdd 'FTPLoadFuncs','RxFTP','FTPLoadFuncs'";
    LineNew; InsertString "Call FTPLoadFuncs";
    LineNew; InsertString "End";
    2:LineNew;
}
%endif

# Constructs
sub REXX_Do {
    InsertString "DO   [TO]  [BY]  [FOR] ";
    2:LineNew;
    InsertString "END";
    LineNew;
    3:MoveUp;
    MoveLineStart;
    3:MoveRight;
}

sub REXX_DoUntil {
    InsertString "DO   [TO]  [BY]  [FOR]   UNTIL ";
    2:LineNew;
    InsertString "END";
    LineNew;
    3:MoveUp;
    MoveLineStart;
    3:MoveRight;
}

sub REXX_DoWhile {
    InsertString "DO   [TO]  [BY]  [FOR]   WHILE ";
    2:LineNew;
    InsertString "END";
    LineNew;
    3:MoveUp;
    MoveLineStart;
    3:MoveRight;
}

sub REXX_DoForever {
    InsertString "DO FOREVER";
    2:LineNew;
    InsertString "END";
    LineNew;
    2:MoveUp;
    MoveLineEnd;
}

sub REXX_If {
    InsertString "IF   THEN";
    2:LineNew;
    InsertString "ELSE";
    LineNew;
    3:MoveUp; MoveLineStart; 3:MoveRight;
}
        
sub REXX_Select {
    InsertString "SELECT";
    LineNew; InsertString "WHEN   THEN";
    LineNew; InsertString "/* instruction */";
    LineNew; InsertString "WHEN   THEN";
    LineNew; InsertString "/* instruction */";
    LineNew; InsertString "WHEN   THEN";
    LineNew; InsertString "/* instruction */";
    LineNew; InsertString "OTHERWISE";
    LineNew; InsertString "/* instruction */";
    LineNew; InsertString "END"; LineNew;
    9:MoveUp; MoveLineStart; 9:MoveRight;
}

colorize REXX {
    SyntaxParser = 'REXX';
    
    color {
        { 'Normal',      'Editor_Default' },
        { 'Number',      'Lang_Number' },
        { 'Punctuation', 'Lang_Punctuation' },
        { 'String',      'Lang_String' },
        { 'Comment',     'Lang_Comment' },
        { 'Function',    'Lang_Function' },
    };
    # REXX Keyword Instructions
    keyword 'Editor_Keywords' {
        'ADDRESS',
        'ARG',
        'CALL',
        'DO',
        'DROP',
        'EXIT',
        'EXPOSE',
        'FORWARD',
        'GUARD',
        'IF',
        'INTERPRET',
        'ITERATE',
        'LEAVE',
        'NOP',
        'NUMERIC',
        'OPTIONS',
        'PARSE',
        'PROCEDURE',
        'PULL',
        'PUSH',
        'QUEUE',
        'RAISE',
        'REPLY',
        'RETURN',
        'SAY',
        'SELECT',
        'SELF',
        'SIGNAL',
        'SUPER',
        'TRACE',
        'USE',

    };
    # Parameters for keywords and functions
    keyword 'Editor_Keywords2' {
        'ADDITIONAL',
        'ANY',
        'APPEND',
        'ARRAY',
        'BINARY',
        'BOTH',
        'BY',
        'CASELESS',
        'CHAR',
        'CLOSE',
        'DATETIME',
        'DIGITS',
        'ELSE',
        'END',
        'ENGINEERING',
        'ERROR',
        'EXISTS',
        'FAILURE',
        'FLUSH',
        'FOR',
        'FOREVER',
        'FORM',
        'FUZZ',
        'HALT',
        'HANDLE',
        'LINE',
        'LOSTDIGITS',
        'LOWER',
        'NAME',
        'NOBUFFER',
        'NOMETHOD',
        'NORMAL',
        'NOSTRING',
        'NOTREADY',
        'NOVALUE',
        'OBJECT',
        'OFF',
        'ON',
        'OPEN',
        'OTHERWISE',
        'OVER',
        'POSITION',
        'QUERY',
        'READ',
        'RECLENGTH',
        'REPLACE',
        'SCIENTIFIC',
        'SEEK',
        'SIZE',
        'SOURCE',
        'STREAMTYPE',
        'SYNTAX',
        'SYS',
        'THEN',
        'TIMESTAMP',
        'TO',
        'UNTIL',
        'UPPER',
        'USER',
        'VALUE',
        'VAR',
        'VARIABLE',
        'VERSION',
        'WHEN',
        'WHILE',
        'WITH',
        'WRITE',
    };
    
    # Built-in functions
    keyword 'Editor_Keywords3' {
        'ABBREV',
        'ABS',
        'ADDRESS',
        'ARG',
        'BEEP',
        'BITAND',
        'BITOR',
        'BITXOR',
        'B2X',
        'CENTER',
        'CENTRE',
        'CHANGESTR',
        'CHARIN',
        'CHAROUT',
        'CHARS',
        'COMPARE',
        'CONDITION',
        'COPIES',
        'COUNTSTR',
        'C2D',
        'C2X',
        'DATATYPE',
        'DATE',
        'DELSTR',
        'DELWORD',
        'D2C',
        'D2X',
        'DIRECTORY',
        'ERRORTEXT',
        'ENDLOCAL',
        'FILESPEC',
        'FORMAT',
        'INSERT',
        'LASTPOS',
        'LEFT',
        'LENGTH',
        'LINEIN',
        'LINEOUT',
        'LINES',
        'MAX',
        'METHODS',
        'MIN',
        'OVERLAY',
        'POS',
        'QUEUED',
        'RANDOM',
        'REVERSE',
        'RIGHT',
        'RS',
        'RXFUNCADD',
        'RXFUNCDROP',
        'RXFUNCQUERY',
        'RXQUEUE',
        'SETLOCAL',
        'SIGN',
        'SOURCELINE',
        'SPACE',
        'STREAM',
        'STRIP',
        'SUBSTR',
        'SUBWORD',
        'SYMBOL',
        'TIME',
        'TRACE',
        'TRANSLATE',
        'TRUNC',
        'VERIFY',
        'WORD',
        'WORDINDEX',
        'WORDLENGTH',
        'WORDPOS',
        'WORDS',
        'XRANGE',
        'X2B',
        'X2C',
        'X2D',
    };
}

mode REXX: PLAIN {                    # REXX mode
    FileNameRx          = /\.\c{CMD}|{REXX?}$/;
    HilitOn             = 1;
    Colorizer           = 'REXX';
    TabSize             = 8;
    AutoIndent          = 1;
    IndentMode          = 'REXX';
    MultiLineHilit      = 1;
    AutoHilitParen      = 1;
    SaveFolds           = 2;      # save fold info at end of line
    CommentStart        = ' /*';
    CommentEnd          = '*/';
    RoutineRegexp       = /^[\w_]+:/;
}

colorize NETREXX: REXX {
    SyntaxParser = 'REXX';

    color {
        { 'Normal',      'Editor_Default' },
        { 'Number',      'Lang_Number' },
        { 'Punctuation', 'Lang_Punctuation' },
        { 'String',      'Lang_String' },
        { 'Comment',     'Lang_Comment' },
        { 'Function',    'Lang_Function' },
    };
    
    # keywords don't inherit? they probably should...
    
    # REXX Keyword Instructions
    keyword 'Editor_Keywords' {
        'ADDRESS',
        'ARG',
        'CALL',
        'CLASS',
        'DO',
        'DROP',
        'EXIT',
        'EXPOSE',
        'IF',
        'IMPORT',
        'INTERPRET',
        'ITERATE',
        'LEAVE',
        'LOOP',
        'METHOD',
        'NOP',
        'NUMERIC',
        'OPTIONS',
        'PACKAGE',
        'PARSE',
        'PROCEDURE',
        'PROPERTIES',
        'PULL',
        'PUSH',
        'QUEUE',
        'RETURN',
        'SAY',
        'SELECT',
        'SIGNAL',
        'TRACE',
    };
    
    # Parameters for keywords and functions
    keyword 'Editor_Keywords2' {
        'ALL',
        'ABSTRACT',
        'BY',
        'CATCH',
        'CONSTANT',
        'DIGITS',
        'ELSE',
        'END',
        'ENGINEERING',
        'ERROR',
        'EXTENDS',
        'FAILURE',
        'FINAL',
        'FINALLY',
        'FOR',
        'FOREVER',
        'FORM',
        'FUZZ',
        'HALT',
        'IMPLEMENTS',
        'INHERITABLE',
        'INTERFACE',
        'LABEL',
        'METHODS',
        'NAME',
        'NATIVE',
        'NOTREADY',
        'NOVALUE',
        'OFF',
        'ON',
        'OTHERWISE',
        'OVER',
        'PRIVATE',
        'PROTECT',
        'PUBLIC',
        'RESULTS',
        'RETURNS',
        'SCIENTIFIC',
        'SIGNALS',
        'SOURCE',
        'STATIC',
        'SYNTAX',
        'THEN',
        'TO',
        'UNTIL',
        'UPPER',
        'USES',
        'VALUE',
        'VAR',
        'VERSION',
        'VOLATILE',
        'WHEN',
        'WHILE',
        'WITH',
    };
    
    # Primitives and other stuff
    keyword 'Editor_Keywords3' {
        'BOOLEAN',
        'BYTE',
        'CHAR',
        'CROSSREF',
        'DIAG',
        'DOUBLE',
        'FLOAT',
        'INT',
        'LONG',
        'NOCROSSREF',
        'NODIAG',
        'NOFORMAT',
        'NOREPLACE',
        'NOSTRICTARGS',
        'NOSTRICTASSIGN',
        'NOSTRICTCASE',
        'NOSTRICTSIGNAL',
        'NOTRACE',
        'NOUTF9',
        'NOVERBOSE',
        'NOVERBOSEX',
        'NULL',
        'REXX',
        'SHORT',
        'STRICTARGS',
        'STRICTASSIGN',
        'STRICTCASE',
        'STRICTSIGNAL',
        'UTF9',
        'VERBOSE',
        'VERBOSEX',
    };
}

mode NETREXX: REXX {
    FileNameRx          = /\.\c{NRX}$/;
    Colorizer           = 'NETREXX';
}
