# FORTRAN-90 mode
# Contributed by: Andrew Pitonyak <pitonyak@math.tu-dresden.de>

# Operators include +, -, *, /, **, %, //
# Comments start with ! and go to the end of the line
# Comparison operators <, <=, ==, >, >=, /=, .LT, .LTE., .EQ., .GT.,.GTE., .NE.
# Logical operators, .AND., .OR., .NOT.
#
# I should probably add the things like .EQ. to the keywords, I already
# added .OR. and such.
# How about a line comment command and then this will be pretty much
# finished!
#
# In Fortran, arrays are accessed with () so you can not assume that
# xpy(<something>) means that a function call is about to happen, it
# could be an
# array reference or a substring reference.

colorize FORTRAN {
    SyntaxParser = 'SIMPLE';

    color {
        { 'Normal',        'Editor_Default' },
        { 'Number',        'Lang_DecimalNumber' },
        { 'HexNumber',     'Lang_HexNumber' },
        { 'Punctuation',   'Lang_Punctuation' },
        { 'String',        'Lang_String' },
        { 'Comment',       'Lang_Comment' },
        { 'CPreprocessor', 'Lang_Preprocessor' },
        { 'Function',      'Lang_Function' },
        { 'Label',         'Lang_Label' },
    };

    keyword 'Editor_Keywords' {
        'abs', 'achar', 'acos', 'adjustl', 'adjustr',
        'aimag', 'aint', 'all', 'allocatable', 'allocate',
        'allocated', '.and.',
        'anint', 'any', 'asin', 'assignment',
        'associated', 'atan', 'atan2', 'backspace', 'bit_size',
        'block', 'blockdata', 'btest', 'call', 'random_number',
        'random_seed', 'system_clock', 'call', 'case', 'ceiling',
        'char', 'character', 'close', 'cmplx', 'common', 'complex',
        'conjg', 'contains', 'continue', 'cos', 'cosh', 'count',
        'cshift', 'cycle', 'data', 'date_and_time', 'dble',
        'deallocate', 'default', 'digits', 'dim', 'dimension', 'do',
        'dot_product', 'double', 'doubleprecision', 'dprod', 'else', 'elseif',
        'elsewhere', 'end', 'endblock', 'endblockdata', 'enddo',
        'endfile', 'endif', 'endinterface', 'endselect', 'endtype',
        'endwhere', 'entry', 'eoshift', 'epsilon', 'equivalence',
        'exit', 'exp', 'exponent', 'external', 'file', 'floor', 'format.',
        'fraction', 'function', 'go', 'goto', 'huge', 'iachar', 'iand',
        'ibclr', 'ibits', 'ibset', 'ichar', 'ieor', 'if', 'implicit', 'in',
        'index', 'inout', 'inquire', 'int', 'integer', 'intent', 'interface',
        'intrinsic', 'iolength', 'ior', 'ishftc', 'ishift', 'kind', 'lbound',
        'len', 'len_trim', 'lge', 'lgt', 'lle', 'llt', 'log', 'log10',
        'logical', 'matmul', 'max', 'maxexponent', 'maxloc', 'maxval',
        'merge', 'min', 'minexponent', 'minloc', 'minval', 'mod', 'module',
        'modulo', 'mvbits', 'namelist', 'nearest', 'nint', 'none', '.not.',
        'nullify', 'only', 'open', 'operator', 'optional', '.or.', 'out', 'pack',
        'parameter', 'pointer', 'precision', 'present', 'print', 'private',
        'procedure', 'product', 'program', 'public', 'radix', 'rangereal',
        'read', 'real', 'recursive', 'repeat', 'reshape', 'result',
        'return', 'rewrind', 'rrspacing', 'save', 'scale', 'scan', 'select',
        'selectcase', 'selected_int_kind', 'selected_real_kind', 'sequence',
        'set_exponent', 'shape', 'sign', 'sin', 'sinh', 'size', 'spacing',
        'spread', 'sqrt', 'stop', 'subroutine', 'sum', 'tan', 'tanh',
        'target', 'then', 'tiny', 'to', 'transfer', 'transpose',
        'trim', 'type', 'unbound', 'unpack', 'use', 'verify',
        'where', 'while', 'write'
    };

    # Syntax Parser by Marko Macek
    # not complete, see comments below

    h_state 0 { 'Normal' }
    h_trans { 1, '-s', 'a-zA-Z_', 'Normal' }
    h_trans { 2, '<', '!', 'Comment' }
    h_trans { 3, '<', '"', 'String' }
    h_trans { 4, '<', '\'', 'String' }
    h_trans { 5, '<s', '0-9', 'Number' }
    h_trans { 0, 'S', '_a-zA-Z0-9', 'Punctuation' }

    h_state 1 { 'Normal' }
    h_trans { 0, '$', '', 'Normal' }
    h_wtype { 1, 1, 0, '', 'a-zA-Z0-9_' }

    h_state 2 { 'Comment' }
    h_trans { 0, '$', '', 'String' }       # can comments can be continued ?

    h_state 3 { 'String' }                 # are strings accross multiple lines
    h_trans { 0, '>', '"', 'String' }      # how can things be quoted?
    h_trans { 0, '$', '', 'String' }

    h_state 4 { 'String' }
    h_trans { 0, '>', '\'', 'String' }
    h_trans { 0, '$', '', 'String' }

    h_state 5 { 'Number' }
    h_trans { 0, '-S', '0-9', 'Normal' }
    h_trans { 0, '$', '', 'Normal' }
}

mode FORTRAN: PLAIN {
    FileNameRx          = /\.\c{F||{F90}|{F9P}|{FPP}}$/;
    HilitOn             = 1;
    Colorizer           = 'FORTRAN';
    AutoIndent          = 1;
    IndentMode          = 'PLAIN';
    MatchCase           = 1;
    Trim                = 1;
    MultiLineHilit      = 1;
    AutoHilitParen      = 1;

    SaveFolds           = 2;      # save fold info at end of line
    CommentStart        = ' !';
    CommentEnd          = '';

    # ? RoutineRegexp       = /^\w[\w_:*&~]+[\w\s_:*&~]@\([^;]*$/;
}
