|
62 | 62 | ;;;###autoload |
63 | 63 | (add-to-list 'auto-mode-alist '("\\.sol\\'" . solidity-mode)) |
64 | 64 |
|
| 65 | +(defun solidity-filter (condp lst) |
| 66 | + (delq nil |
| 67 | + (mapcar (lambda (x) (and (funcall condp x) x)) lst))) |
| 68 | + |
65 | 69 | (defconst solidity-keywords |
66 | 70 | '("after" |
| 71 | + "as" |
| 72 | + "assembly" |
67 | 73 | "break" |
68 | 74 | "constant" |
69 | 75 | "anonymous" |
|
78 | 84 | "for" |
79 | 85 | "function" |
80 | 86 | "if" |
| 87 | + "import" |
81 | 88 | "in" |
82 | 89 | "is" |
83 | 90 | "indexed" |
| 91 | + "library" |
84 | 92 | "mapping" |
85 | 93 | "modifier" |
86 | 94 | "new" |
| 95 | + "pragma" |
87 | 96 | "private" |
88 | 97 | "public" |
89 | 98 | "internal" |
|
92 | 101 | "struct" |
93 | 102 | "switch" |
94 | 103 | "this" |
| 104 | + "using" |
95 | 105 | "var" |
96 | 106 | "while" |
97 | 107 | "enum" |
98 | 108 | "throw" |
99 | 109 | ) |
100 | 110 | "Keywords of the solidity language.") |
101 | 111 |
|
| 112 | +(defconst solidity-tofontify-keywords |
| 113 | + (solidity-filter |
| 114 | + (lambda (x) (not (member x '("contract" |
| 115 | + "library")))) |
| 116 | + solidity-keywords) |
| 117 | + "Keywords that will be fontified as they are and don't have special rules." |
| 118 | + ) |
| 119 | + |
102 | 120 | (defconst solidity-constants |
103 | 121 | '("true" "false" |
104 | 122 | "wei" |
|
251 | 269 | ;; http://ergoemacs.org/emacs/elisp_syntax_coloring.html |
252 | 270 | (defconst solidity-font-lock-keywords |
253 | 271 | (list |
254 | | - `(,(regexp-opt solidity-keywords 'words) . font-lock-keyword-face) |
| 272 | + `(,(regexp-opt solidity-tofontify-keywords 'words) . font-lock-keyword-face) |
255 | 273 | '(solidity-match-functions (1 font-lock-type-face) |
256 | 274 | (2 font-lock-function-name-face)) |
257 | 275 | '(solidity-match-mappings (1 font-lock-type-face) |
258 | | - (2 font-lock-function-name-face)) |
| 276 | + (2 font-lock-function-name-face)) |
| 277 | + '(solidity-match-pragma-stmt (1 font-lock-preprocessor-face) |
| 278 | + (2 font-lock-string-face)) |
| 279 | + '(solidity-match-library-decl (1 font-lock-keyword-face) |
| 280 | + (2 font-lock-variable-name-face)) |
259 | 281 | '(solidity-match-contract-decl (1 font-lock-keyword-face) |
260 | 282 | (2 font-lock-variable-name-face)) |
261 | 283 | '(solidity-match-modifier-decl (1 font-lock-keyword-face) |
@@ -287,6 +309,24 @@ First match should be a keyword and second an identifier." |
287 | 309 | " *\\(contract\\) *\\(" solidity-identifier-regexp "\\)") |
288 | 310 | limit)) |
289 | 311 |
|
| 312 | +(defun solidity-match-library-decl (limit) |
| 313 | + "Search the buffer forward until LIMIT matching library declarations. |
| 314 | +
|
| 315 | +First match should be a keyword and second an identifier." |
| 316 | + (solidity-match-regexp |
| 317 | + (concat |
| 318 | + " *\\(library\\) *\\(" solidity-identifier-regexp "\\)") |
| 319 | + limit)) |
| 320 | + |
| 321 | +(defun solidity-match-pragma-stmt (limit) |
| 322 | + "Search the buffer forward until LIMIT matching pragma statements. |
| 323 | +
|
| 324 | +First match should be a keyword and second an identifier." |
| 325 | + (solidity-match-regexp |
| 326 | + (concat |
| 327 | + " *\\(pragma\\) *\\(.*\\);") |
| 328 | + limit)) |
| 329 | + |
290 | 330 | (defun solidity-match-struct-decl (limit) |
291 | 331 | "Search the buffer forward until LIMIT matching struct declarations. |
292 | 332 |
|
|
0 commit comments