]> git.lizzy.rs Git - micro.git/blob - syntax_files/d.micro
Add syntax flags and fix a couple highlighting bugs
[micro.git] / syntax_files / d.micro
1 ## D syntax highlighting for GNU nano
2 ##
3 ## Author: Andrei Vinokurov
4 ## Based on D lexer specification (http://dlang.org/lex)
5
6 syntax "D" "\.(d(i|d)?)$"
7
8 ## Operators and punctuation
9 color green "(\*|/|%|\+|-|>>|<<|>>>|&|\^(\^)?|\||~)?="
10 color green "\.\.(\.)?|!|\*|&|~|\(|\)|\[|\]|\\|/|\+|-|%|<|>|\?|:|;"
11
12 ## Octal integer literals are deprecated
13 color ,red "(0[0-7_]*)(L[uU]?|[uU]L?)?"
14
15 ## Decimal integer literals
16 color brightyellow "([0-9]|[1-9][0-9_]*)(L[uU]?|[uU]L?)?"
17
18 ## Binary integer literals
19 color brightgreen "(0[bB][01_]*)(L[uU]?|[uU]L?)?"
20
21 ## Decimal float literals
22 color brightblue "[0-9][0-9_]*\.([0-9][0-9_]*)([eE][+-]?([0-9][0-9_]*))?[fFL]?i?"
23 color brightblue "[0-9][0-9_]*([eE][+-]?([0-9][0-9_]*))[fFL]?i?"
24 color brightblue "[^.]\.([0-9][0-9_]*)([eE][+-]?([0-9][0-9_]*))?[fFL]?i?"
25 color brightblue "[0-9][0-9_]*([fFL]?i|[fF])"
26
27 ## Hexadecimal integer literals
28 color brightcyan "(0[xX]([0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F]))(L[uU]?|[uU]L?)?"
29
30 ## Hexadecimal float literals
31 color blue "0[xX]([0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F])(\.[0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F])?[pP][+-]?([0-9][0-9_]*)[fFL]?i?"
32 color blue "0[xX]\.([0-9a-fA-F][0-9a-fA-F_]*|[0-9a-fA-F_]*[0-9a-fA-F])[pP][+-]?([0-9][0-9_]*)[fFL]?i?"
33
34
35 ## Character literals
36 color brightmagenta "'([^\']|\\(['"?\abfnrtv]|x[[:xdigit:]]{2}|[0-7]{1,3}|u[[:xdigit:]]{4}|U[[:xdigit:]]{8}|&.*;))'"
37
38 ## Keywords
39 ## a-e
40 color brightwhite "\b(abstract|alias|align|asm|assert|auto|body|break|case|cast|catch|class|const|continue|debug|default|delegate|do|else|enum|export|extern)\b"
41 ## f-l
42 color brightwhite "\b(false|final|finally|for|foreach|foreach_reverse|function|goto|if|immutable|import|in|inout|interface|invariant|is|lazy)\b"
43 ## m-r
44 color brightwhite "\b(macro|mixin|module|new|nothrow|null|out|override|package|pragma|private|protected|public|pure|ref|return)\b"
45 ## s-w
46 color brightwhite "\b(scope|shared|static|struct|super|switch|synchronized|template|this|throw|true|try|typeid|typeof|union|unittest|version|while|with)\b"
47 ## __
48 color brightwhite "\b(__FILE__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__gshared|__traits|__vector|__parameters)\b"
49
50 ## Deprecated keywords
51 color ,red "\b(delete|deprecated|typedef|volatile)\b"
52
53 ## Primitive types
54 color cyan "\b(bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong|ushort|void|wchar)\b"
55
56 ## Globally defined symbols
57 color cyan "\b(string|wstring|dstring|size_t|ptrdiff_t)\b"
58
59 ## Special tokens
60 color ,blue "\b(__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__)\b"
61
62
63 ## Special directives, etc.
64 color magenta "\\s *#\\s *"
65
66 ## String literals
67 ## TODO: multiline backtick and doublequote string. (Unlikely possible at all with nano.)
68 ### DoubleQuotedString
69 color yellow ""(\\.|[^"])*""
70  
71 ### WysiwygString
72 color yellow (s) "r".*?""
73 color yellow "`[^`]*`"
74
75 ### HexString
76 color ,yellow "x"([[:space:]]*[[:xdigit:]][[:space:]]*[[:xdigit:]])*[[:space:]]*""
77
78 ### DelimitedString
79 color yellow "q"\(.*\)""
80 color yellow "q"\{.*\}""
81 color yellow "q"\[.*\]""
82 color yellow "q"<.*>""
83 color yellow (s) "q"[^({[<"][^"]*$.*?^[^"]+""
84 color yellow "q"([^({[<"]).*\1""
85
86 ### TokenString
87 ### True token strings require nesting, so, again, they can't be implemented accurately here.
88 ### At the same time, the intended purpose of token strings makes it questionable to highlight them as strings at all.
89 ## color ,magenta (s) "q\{.*?\}"
90
91 ## Comments
92 ## NB: true nested comments are impossible to implement with plain regex
93 color brightblack "//.*"
94 color brightblack (s) "/\*.*?\*/"
95 color brightblack (s) "/\+.*?\+/"
96
97 ## Trailing whitespace
98 color ,green "^[[:space:]]+$"
99