File: fortran_highlighter.py

package info (click to toggle)
gnat-gps 18-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 45,716 kB
  • sloc: ada: 362,679; python: 31,031; xml: 9,597; makefile: 1,030; ansic: 917; sh: 264; java: 17
file content (42 lines) | stat: -rw-r--r-- 1,467 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from highlighter.common import *

keywords = [
    "assign", "backspace", "block ""data", "call", "close", "common",
    "continue", "data", "dimension", "do", "else", "else ""if", "end",
    "endfile", "endif", "entry", "equivalence", "external", "format",
    "function", "goto", "if", "implicit", "inquire", "intrinsic", "open",
    "parameter", "pause", "print", "program", "read", "return", "rewind",
    "rewrite", "save", "stop", "subroutine", "then", "write"
    "allocatable", "allocate", "case", "contains", "cycle", "deallocate",
    "elsewhere", "exit", "include", "interface", "intent", "module",
    "namelist", "nullify", "only", "operator", "optional", "pointer",
    "private", "procedure", "public", "recursive", "result", "select",
    "sequence", "target", "use", "while", "where"
]

hl_cont_line = simple(r"\\\n", tag=tag_type)

hl_strings = region_template(
    matchall=False, tag=tag_string,
    highlighter=(hl_cont_line, hl_inside_strings)
)

register_highlighter(
    language="fortran 90",
    spec=(
        # Match comments lines
        region(r"!", "\n", tag=tag_comment, highlighter=(hl_comment_notes,)),

        # Match string literals
        hl_strings(r"'", r"'|[^\\]$"),
        hl_strings(r'"', r'"|[^\\]$'),

        region(
            r"'", r"'|[^\\]$", matchall=False, tag=tag_string,
            highlighter=(hl_cont_line, hl_inside_strings)
        ),

        words(keywords, tag=tag_keyword),
    ),
    igncase=True
)