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 11781 – NEMO

Changeset 11781


Ignore:
Timestamp:
2019-10-23T21:02:18+02:00 (5 years ago)
Author:
nicolasmartin
Message:

Improve Fortran lexer by creating distinct states for comment, boolean, operator and punctuation
Respectively cmt, bool, opr & punc.

The regexps were from the 'core' state which was reduced to statements, data types and builtins
The punctuation state has evolved to handle & character more wisely:
highlight only if followed by whitespace (continuation line), if not

Tested with tracers.rst which includes routine, namelist and code-block.
Still a small issue with on a specific namelist.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • utils/developer/fortran.py

    r11779 r11781  
    4040    tokens = { 
    4141        'root': [ 
    42             (r'^#.*\n', Comment.Preproc), 
    43             (r'^&[a-z]\w*', Name.Namespace, 'namelist'), 
    44             (r'!.*\n', Comment), 
    45             include('strings'), 
     42            include('cmt' ), 
     43            include('nlst'), 
     44            include('str' ), 
     45            include('bool'), 
     46            include('opr' ), 
     47            include('punc'), 
    4648            include('core'), 
    4749            (r'[a-z][\w$]*', Name), 
    48             include('nums'), 
     50            include('num'), 
    4951            (r'[\s]+', Text), 
     52        ], 
     53        'cmt': [ 
     54            (r'^#.*\n', Comment.Preproc), 
     55            (r'!.*\n', Comment), 
    5056        ], 
    5157        'core': [ 
     
    8591             Keyword.Type), 
    8692 
    87             # Operators 
    88             (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator), 
    89  
    90             #  
     93            # 
    9194            (r'(::)', Keyword.Declaration), 
    9295 
     
    144147                'ZLog', 'ZSin', 'ZSqRt'), prefix=r'\b', suffix=r'\s*\b'), 
    145148             Name.Builtin), 
    146  
     149        ], 
     150        'bool': [ 
    147151            # Booleans 
    148             (r'\.(true|false)\.', Name.Builtin), 
     152            (r'\.(true|false)\.', Keyword.Constant), 
     153        ], 
     154        'opr': [ 
     155            # Operators 
     156            (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator), 
    149157 
    150158            # Comparing Operators 
    151159            (r'\.(eq|ne|lt|le|gt|ge|not|and|or|eqv|neqv)\.', Operator.Word), 
    152  
     160        ], 
     161        'punc': [ 
    153162            # Punctuation 
    154             (r'[()\[\],:&%;.]', Punctuation), 
    155         ], 
    156         'namelist': [ 
    157             (r'!.*\n', Comment), 
    158             (r'([a-z]\w*)(\()?(\s*)?(\d*)?(\s*)?(\))?(%[a-z]\w*)?(\s*)(=)', bygroups( 
    159                Name.Variable, Punctuation, Text, Number.Integer, Text, Punctuation,  
    160                Name.Variable, Text, Operator)), 
    161             (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator), 
    162             (r'\.(true|false)\.', Name.Builtin), 
    163             include('strings'), 
    164             include('nums'), 
    165             (r'[()\[\],:&%;.]', Punctuation), 
    166             (r'[\s]+', Text), 
     163            (r'[()\[\],:%;.]', Punctuation), 
     164            (r'&(?=\s)'      , Punctuation), 
     165        ], 
     166        'nlst': [ 
     167            (r'^&[a-z]\w*', Name.Namespace), 
     168#            include('cmt'), 
     169            (r'^(\s*)([a-z]\w*)(\()?(\s*)?(\d*)?(\s*)?(\))?(%[a-z]\w*)?(\s*)(=)', 
     170             bygroups(Text, Name.Variable, 
     171                      Punctuation  , Text, Number.Integer, Text, Punctuation, 
     172                      Name.Variable, 
     173                      Text, Operator                                         )), 
     174            (r'([+-])', Operator), 
    167175            (r'^\/$', Name.Namespace), 
    168176        ], 
    169         'strings': [ 
     177        'str': [ 
    170178            (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double), 
    171179            (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single), 
    172180        ], 
    173         'nums': [ 
     181        'num': [ 
    174182            (r'\d+(?![.e])(_[a-z]\w+)?', Number.Integer), 
    175183            (r'[+-]?\d*\.\d+([ed][-+]?\d+)?(_[a-z]\w+)?', Number.Float), 
Note: See TracChangeset for help on using the changeset viewer.