Skip to content

Commit c738988

Browse files
committed
Add missing syntax highlighting for some constructs
1 parent f3a86ae commit c738988

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

solidity-mode.el

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@
6262
;;;###autoload
6363
(add-to-list 'auto-mode-alist '("\\.sol\\'" . solidity-mode))
6464

65+
(defun solidity-filter (condp lst)
66+
(delq nil
67+
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))
68+
6569
(defconst solidity-keywords
6670
'("after"
71+
"as"
72+
"assembly"
6773
"break"
6874
"constant"
6975
"anonymous"
@@ -78,12 +84,15 @@
7884
"for"
7985
"function"
8086
"if"
87+
"import"
8188
"in"
8289
"is"
8390
"indexed"
91+
"library"
8492
"mapping"
8593
"modifier"
8694
"new"
95+
"pragma"
8796
"private"
8897
"public"
8998
"internal"
@@ -92,13 +101,22 @@
92101
"struct"
93102
"switch"
94103
"this"
104+
"using"
95105
"var"
96106
"while"
97107
"enum"
98108
"throw"
99109
)
100110
"Keywords of the solidity language.")
101111

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+
102120
(defconst solidity-constants
103121
'("true" "false"
104122
"wei"
@@ -251,11 +269,15 @@
251269
;; http://ergoemacs.org/emacs/elisp_syntax_coloring.html
252270
(defconst solidity-font-lock-keywords
253271
(list
254-
`(,(regexp-opt solidity-keywords 'words) . font-lock-keyword-face)
272+
`(,(regexp-opt solidity-tofontify-keywords 'words) . font-lock-keyword-face)
255273
'(solidity-match-functions (1 font-lock-type-face)
256274
(2 font-lock-function-name-face))
257275
'(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))
259281
'(solidity-match-contract-decl (1 font-lock-keyword-face)
260282
(2 font-lock-variable-name-face))
261283
'(solidity-match-modifier-decl (1 font-lock-keyword-face)
@@ -287,6 +309,24 @@ First match should be a keyword and second an identifier."
287309
" *\\(contract\\) *\\(" solidity-identifier-regexp "\\)")
288310
limit))
289311

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+
290330
(defun solidity-match-struct-decl (limit)
291331
"Search the buffer forward until LIMIT matching struct declarations.
292332

0 commit comments

Comments
 (0)