New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 11801 for utils – NEMO

Changeset 11801 for utils


Ignore:
Timestamp:
2019-10-25T17:13:45+02:00 (4 years ago)
Author:
nicolasmartin
Message:

Add some syntax patterns to highlight

  • Modules and routines declarations with USE and CALL statements (Name.Function token)
  • Output format with WRITE (Name.Label)
  • CPP simple directives (define|else|endif|if|ifdef|undef)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils/developer/fortran.py

    r11788 r11801  
    4040    tokens = { 
    4141 
     42        # 
    4243        'root': [ 
    43             include('cmt' ), 
    44             include('nlst'), 
     44            include('cmt'), 
     45 
     46            # Namelist 
     47            (r'^&[a-z]\w*', Name.Namespace), 
     48            (r'^\/$'      , Name.Namespace), 
     49 
    4550            include('str' ), 
     51 
     52            # Modules and routines 
     53            (r'(MODULE)(\s+)?([a-z]\w*)'    , bygroups( 
     54                Keyword, Text, Name.Function 
     55            )), 
     56            (r'(USE)(\s+)?([a-z]\w*)(\s*)?(,)?(\s*)?(ONLY)?(\s*)?(:)?(\s*)?([a-z]\w*)?(\s*)?(!.*)?$', bygroups( 
     57                Keyword, Text, Name.Function, 
     58                Text, Punctuation, Text, 
     59                Keyword, Text, Punctuation, Text, Name.Function, 
     60                Text, Comment 
     61            )), 
     62            (r'(CALL)(\s+)?([a-z]\w*)'      , bygroups( 
     63                Keyword, Text, Name.Function 
     64            )), 
     65            (r'(SUBROUTINE)(\s+)?([a-z]\w*)', bygroups( 
     66                Keyword, Text, Name.Function 
     67            )), 
     68 
     69            # Format 
     70            (r'^\d+', Name.Label), 
     71            (r'(WRITE)(\()([a-z]\w*)(,)(\d+)?', bygroups( 
     72                Keyword, Punctuation, Name, Punctuation, Name.Label 
     73            )), 
     74 
     75            include('core'), include('opr' ), include('bool'), include('punc'), 
     76            include('var'), 
    4677            include('num' ), 
    47             include('bool'), 
    48             include('opr' ), 
    49             include('punc'), 
    50             include('core'), 
     78 
     79            # End 
    5180            (r'[a-z][\w$]*', Name), 
    5281            (r'[\s]+', Text), 
    5382        ], 
    5483 
    55         'cmt': [ 
    56             (r'^#.*\n', Comment.Preproc), 
    57             (r'!.*\n' , Comment        ), 
     84        # Commment 
     85        'cmt' : [ 
     86            (r'^(#)(\s*)(define|if|ifdef|undef)(\s+)?(!)?(\s+)?(defined)?', bygroups( 
     87                Comment.Preproc, Text, Comment.Preproc, Text, Operator.Word, Text, Comment.Preproc 
     88            )), 
     89            (r'^(#)(\s*)(else|endif)', Comment.Preproc), 
     90            (r'!.*\n' , Comment) 
     91         ], 
     92 
     93        # Variable 
     94        'var': [ 
     95            (r'([a-z]\w*)(\()?(\s+)?(\d+)?(\))?(%[a-z]\w*)?(\s*)(=)', bygroups( 
     96                Name.Variable, Punctuation, Text, Number.Integer, Punctuation, Name.Variable, 
     97                Text, Operator 
     98            )), 
     99        ], 
     100 
     101        # String 
     102        'str' : [ 
     103            (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double), 
     104            (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single), 
     105        ], 
     106 
     107        # Number 
     108        'num' : [ 
     109            (r'\d+(?![.e])(_[a-z]\w+)?'                 , Number.Integer), 
     110            (r'[+-]?\d*\.\d+([ed][-+]?\d+)?(_[a-z]\w+)?', Number.Float  ), 
     111            (r'[+-]?\d+\.\d*([ed][-+]?\d+)?(_[a-z]\w+)?', Number.Float  ), 
     112            (r'[+-]?\d+(\.\d*)?[ed][-+]?\d+(_[a-z]\w+)?', Number.Float  ), 
     113        ], 
     114 
     115        # Booleans 
     116        'bool': [ (r'\.(true|false)\.', Keyword.Constant) ], 
     117 
     118        # Punctuation 
     119        'punc': [ (r'[()\[\],:&%;.]', Punctuation)], 
     120 
     121        # Operators 
     122        'opr' : [ 
     123            (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)'       , Operator     ), 
     124            (r'\.(eq|ne|lt|le|gt|ge|not|and|or|eqv|neqv)\.', Operator.Word) 
    58125        ], 
    59126 
     
    66133                'CODIMENSION', 'COMMON', 'CONCURRRENT', 'CONTIGUOUS', 'CONTAINS', 
    67134                'CONTINUE', 'CRITICAL', 'CYCLE', 'DATA', 'DEALLOCATE', 'DECODE', 
    68                 'DEFERRED', 'DIMENSION', 'DO', 'ELEMENTAL', 'ELSE', 'ENCODE', 'END', 'ENDIF', 
     135                'DEFERRED', 'DIMENSION', 'DO', 'ELEMENTAL', 'ELSE', 'ENCODE', 'END', 
    69136                'ENTRY', 'ENUM', 'ENUMERATOR', 'EQUIVALENCE', 'EXIT', 'EXTENDS', 
    70137                'EXTERNAL', 'EXTRINSIC', 'FILE', 'FINAL', 'FORALL', 'FORMAT', 
     
    72139                'IMPORT', 'IMPURE', 'INCLUDE', 'INQUIRE', 'INTENT', 'INTERFACE', 
    73140                'INTRINSIC', 'IS', 'LOCK', 'MEMORY', 'MODULE', 'NAMELIST', 'NULLIFY', 
    74                 'NONE', 'NON_INTRINSIC', 'NON_OVERRIDABLE', 'NOPASS', 'OPEN', 'OPTIONAL', 
     141                'NONE', 'NON_INTRINSIC', 'NON_OVERRIDABLE', 'NOPASS', 'ONLY', 'OPEN', 'OPTIONAL', 
    75142                'OPTIONS', 'PARAMETER', 'PASS', 'PAUSE', 'POINTER', 'PRINT', 'PRIVATE', 
    76143                'PROGRAM', 'PROCEDURE', 'PROTECTED', 'PUBLIC', 'PURE', 'READ', 
     
    150217            ), prefix=r'\b', suffix=r'\s*\b'), Name.Builtin), 
    151218        ], 
    152  
    153         'bool': [ 
    154             # Booleans 
    155             (r'\.(true|false)\.', Keyword.Constant), 
    156         ], 
    157  
    158         'opr': [ 
    159             # Operators 
    160             (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator), 
    161  
    162             # Comparing Operators 
    163             (r'\.(eq|ne|lt|le|gt|ge|not|and|or|eqv|neqv)\.', Operator.Word), 
    164         ], 
    165  
    166         'punc': [ 
    167             # Punctuation 
    168             (r'[()\[\],:%;.]', Punctuation), 
    169             (r'&(?=\s)'      , Punctuation), 
    170         ], 
    171  
    172         'nlst': [ 
    173             (r'^&[a-z]\w*', Name.Namespace), 
    174             (r'([a-z]\w*)(\()?(\s*)?(\d*)?(\s*)?(\))?(%[a-z]\w*)?(\s*)(=)', bygroups( 
    175                 Name.Variable, 
    176                 Punctuation  , Text         , Number.Integer, Text, Punctuation, 
    177                 Name.Variable, 
    178                 Text         , Operator 
    179             )), 
    180             (r'^\/$', Name.Namespace), 
    181         ], 
    182  
    183         'str': [ 
    184             (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double), 
    185             (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single), 
    186         ], 
    187  
    188         'num': [ 
    189             (r'\d+(?![.e])(_[a-z]\w+)?'                 , Number.Integer), 
    190             (r'[+-]?\d*\.\d+([ed][-+]?\d+)?(_[a-z]\w+)?', Number.Float  ), 
    191             (r'[+-]?\d+\.\d*([ed][-+]?\d+)?(_[a-z]\w+)?', Number.Float  ), 
    192             (r'[+-]?\d+(\.\d*)?[ed][-+]?\d+(_[a-z]\w+)?', Number.Float  ), 
    193         ], 
    194219    } 
    195220 
Note: See TracChangeset for help on using the changeset viewer.