Skip to content

Commit 08474cf

Browse files
committed
Basic Rust highlighting support
1 parent caf0540 commit 08474cf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Fancydiff/Lexer.x

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ $nonwhitspace = . # $white
9898

9999
@golangRsv = @golangRsv1 | @golangRsv2 | @golangRsv3 | @golangRsv4
100100

101+
@rustRsv1 = abstract|alignof|as|become|box|break|const|continue|crate|do
102+
@rustRsv2 = else|enum|extern|false|final|fn|for|if|impl|in|let|loop|macro
103+
@rustRsv3 = match|mod|move|mut|offsetof|override|priv|proc|pub|pure|ref|return
104+
@rustRsv4 = Self|self|sizeof|static|struct|super|trait|true|type|typeof
105+
@rustRsv5 = unsafe|unsized|use|virtual|where|while|yield
106+
107+
@rustRsv = @rustRsv1 | @rustRsv2 | @rustRsv3 | @rustRsv4 | @rustRsv5
108+
101109
@javaRsv1 = abstract|assert|boolean|break|byte|case|catch|char|class|const
102110
@javaRsv2 = continue|default|do|double|else|enum|extends|final|finally|float
103111
@javaRsv3 = for|goto|if|implements|import|instanceof|int|interface|long|native
@@ -196,6 +204,18 @@ state:-
196204
<golang> @punct { tok Ignore }
197205
<golang> . { tok Ignore }
198206

207+
<rustlang> @sp { tok Ignore }
208+
<rustlang> [\"] { tokPush String str }
209+
<rustlang> [\'] { tokPush Char charx }
210+
<rustlang> [\'] [a-z]+ { tok Identifier }
211+
<rustlang> "/*" { tokPush Comment ccomm }
212+
<rustlang> "//" { tokPush Comment comm2 }
213+
<rustlang> @rustRsv { tok Keyword }
214+
<rustlang> @number { tok Number }
215+
<rustlang> @cId { tok Identifier }
216+
<rustlang> @punct { tok Ignore }
217+
<rustlang> . { tok Ignore }
218+
199219
<pmstr1> [\"][\"][\"] { tokPop String }
200220
<pmstr1> [\"][\"] { tok String }
201221
<pmstr1> [\"] { tok String }

src/Fancydiff/SourceHighlight.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ data Highlighter
157157
| Haskell
158158
| Python
159159
| GoLang
160+
| Rust
160161
| Java
161162
| Generic
162163
deriving (Enum, Ord, Eq, Bounded)
@@ -181,6 +182,10 @@ syntaxMap = Map.fromList
181182
proceduralMatcher Lexer.golang,
182183
[".go"]))
183184

185+
, ("rust", (Rust,
186+
proceduralMatcher Lexer.rustlang,
187+
[".rs"]))
188+
184189
, ("javascript",
185190
(JavaScript,
186191
proceduralMatcher Lexer.js,

0 commit comments

Comments
 (0)