Skip to content

Commit 323a705

Browse files
authored
Futhark: add missing tokens (#2118)
Adds recognition of 'def'/'type^'/'type~' keywords and adds some missing characters to the regexes for identifiers and punctuation.
1 parent 3f4c733 commit 323a705

File tree

3 files changed

+100
-43
lines changed

3 files changed

+100
-43
lines changed

pygments/lexers/futhark.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class FutharkLexer(RegexLexer):
3737

3838
other_types = ('bool', )
3939

40-
reserved = ('if', 'then', 'else', 'let', 'loop', 'in', 'with', 'type',
40+
reserved = ('if', 'then', 'else', 'def', 'let', 'loop', 'in', 'with',
41+
'type', 'type~', 'type^',
4142
'val', 'entry', 'for', 'while', 'do', 'case', 'match',
4243
'include', 'import', 'module', 'open', 'local', 'assert', '_')
4344

@@ -62,11 +63,11 @@ class FutharkLexer(RegexLexer):
6263

6364
# Identifiers
6465
(r'#\[([a-zA-Z_\(\) ]*)\]', Comment.Preproc),
65-
(r'!?(%s\.)*%s' % (identifier_re, identifier_re), Name),
66+
(r'[#!]?(%s\.)*%s' % (identifier_re, identifier_re), Name),
6667

6768
(r'\\', Operator),
6869
(r'[-+/%=!><|&*^][-+/%=!><|&*^.]*', Operator),
69-
(r'[][(),:;`{}]', Punctuation),
70+
(r'[][(),:;`{}?.\'~^]', Punctuation),
7071

7172
# Numbers
7273
(r'0[xX]_*[\da-fA-F](_*[\da-fA-F])*_*[pP][+-]?\d(_*\d)*' + num_postfix,
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
local let dotprod [n] 't
2+
(mul: t -> t -> t) (add: t -> t -> t) (zero: t)
3+
(a: [n]t) (b: [n]t): t =
4+
map2 mul a b |> reduce add zero
5+
16
module matmul (F: numeric) = {
27
type t = F.t
38
open F
49

5-
local let dotprod [n] (a: [n]t) (b: [n]t): t =
6-
map2 (*) a b |> reduce (+) (i32 0)
7-
8-
9-
let matmul [n1][n2][m] (xss: [n1][m]t) (yss: [m][n2]t): [n1][n2]t =
10-
map (\xs -> map (\ys -> dotprod xs ys) <| transpose yss) xss
10+
let matmul [n1][n2][m] (xss: [n1][m]t) (yss: [m][n2]t): *[n1][n2]t =
11+
map (\xs -> map (\ys -> dotprod (*) (+) (i32 0) xs ys) <| transpose yss) xss
1112
}
1213

1314
module matmul32 = matmul f32
1415

15-
let main [n][m] (xss: [n][m]f32) (yss: [m][n]f32): *[n][n]f32 =
16+
let main [n][m] (xss: [n][m]f32) (yss: [m][n]f32): ?[a][b].[a][b]f32 =
1617
matmul32.matmul xss yss

tests/examplefiles/futhark/example.fut.output

Lines changed: 88 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)