Skip to content

Commit 652c13b

Browse files
authored
Added Nickel language (#7432)
* init commmit * updated grammars * moved samples around * updated NCL heuristics * updated heuristic test entires * udpated vendor * updated NCL ref samples to be more verbose
1 parent f970808 commit 652c13b

File tree

13 files changed

+264
-5
lines changed

13 files changed

+264
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,9 @@
959959
[submodule "vendor/grammars/nesC"]
960960
path = vendor/grammars/nesC
961961
url = https://github.com/cdwilson/nesC.tmbundle
962+
[submodule "vendor/grammars/nickel"]
963+
path = vendor/grammars/nickel
964+
url = https://github.com/tweag/nickel.git
962965
[submodule "vendor/grammars/nix-linguist"]
963966
path = vendor/grammars/nix-linguist
964967
url = https://github.com/sambacha/nix-linguist.git

grammars.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,8 @@ vendor/grammars/nemerle.tmbundle:
890890
- source.nemerle
891891
vendor/grammars/nesC:
892892
- source.nesc
893+
vendor/grammars/nickel:
894+
- source.nickel
893895
vendor/grammars/nix-linguist:
894896
- source.nix
895897
vendor/grammars/nu-grammar:

lib/linguist/heuristics.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,19 @@ disambiguations:
542542
pattern: '^\s*<\?xml\s+version'
543543
- language: Gerber Image
544544
pattern: '^[DGMT][0-9]{2}\*(?:\r?\n|\r)'
545+
- language: Nickel
546+
pattern:
547+
- '^let(?:\srec)?(?:\s[a-zA-Z_][a-zA-Z0-9_]*)?'
548+
- '^import\s"[^"]+"\s+as\s'
549+
- 'std\.[a-zA-Z_][a-zA-Z0-9_]*\.'
545550
- language: Text
546551
pattern: 'THE_TITLE'
552+
- language: NCL
553+
pattern:
554+
- '^load "'
555+
- '^begin$'
556+
- '[0-9]\.$'
557+
- '^;'
547558
- extensions: ['.nl']
548559
rules:
549560
- language: NL

lib/linguist/languages.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4894,6 +4894,14 @@ Nginx:
48944894
codemirror_mode: nginx
48954895
codemirror_mime_type: text/x-nginx-conf
48964896
language_id: 248
4897+
Nickel:
4898+
type: programming
4899+
color: "#E0C3FC"
4900+
extensions:
4901+
- ".ncl"
4902+
tm_scope: source.nickel
4903+
ace_mode: text
4904+
language_id: 1067292664
48974905
Nim:
48984906
type: programming
48994907
color: "#ffc200"

samples/NCL/cosmolib_1.ncl

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
;----------------------------------------------------------------------
2+
; cosmolib_1.ncl
3+
;
4+
; Concepts illustrated:
5+
; - Plotting COSMO model data from MeteoSwiss
6+
; - Plotting data from a rotated lat-lon grid
7+
; - Using functions from COSMOlib
8+
;----------------------------------------------------------------------
9+
; To learn more about COSMOlib, visit:
10+
; https://wiki.c2sm.ethz.ch/Wiki/VisNCLCosmoLibrary
11+
;----------------------------------------------------------------------
12+
13+
begin
14+
15+
; open file
16+
cname = "lfff00000000c"
17+
ftype = "grb"
18+
cfile = addfile(cname+"."+ftype,"r")
19+
20+
; read topography and land-fraction
21+
topo = jmb_getvar(cfile, "HSURF", False)
22+
frland = jmb_getvar(cfile, "FR_LAND", False)
23+
24+
; geo-reference
25+
jmb_getgrid(cfile, cfile, topo, False)
26+
27+
; close file
28+
delete(cfile)
29+
30+
; set water points to -1.0 elevation
31+
topo = where(topo .lt. 0.0, 0.0, topo)
32+
topo = where(frland .gt. 0.5, topo, -1.0)
33+
34+
; rename topography (for correct plot title)
35+
topo@long_name = "Topography"
36+
37+
; open graphic port
38+
ptype = "png" ; send graphics to PNG file
39+
wks = gsn_open_wks(ptype,"cosmolib")
40+
41+
; set color table
42+
rc = jmb_set_ct(wks, "topo_15lev", False)
43+
44+
; plot map
45+
res = True
46+
res@gsnMaximize = True ; maxmize plot in frame
47+
mp = jmb_map(wks, topo, res)
48+
delete(res)
49+
50+
; plot contour plot
51+
res = rc
52+
cn = jmb_contour(wks, topo, res)
53+
delete(res)
54+
55+
; draw plot
56+
pl = jmb_overlays(wks, (/mp,cn/), False)
57+
58+
; cleanup
59+
delete(wks)
60+
61+
end
62+

samples/NCL/primero.ncl

Lines changed: 0 additions & 3 deletions
This file was deleted.

samples/Nickel/arrays.ncl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# test = 'pass'
2+
3+
# Example array functions. This code is illustrative: prefer using the array
4+
# stdlib functions `std.array.map` and `std.array.fold_right` instead.
5+
let rec
6+
map
7+
: forall a b. (a -> b) -> Array a -> Array b
8+
= fun f arr =>
9+
if arr == [] then
10+
[]
11+
else
12+
let [head, ..tail] = arr in
13+
[f head] @ map f tail,
14+
fold
15+
: forall a b. (a -> b -> b) -> b -> Array a -> b
16+
= fun f first arr =>
17+
if arr == [] then
18+
first
19+
else
20+
let [head, ..tail] = arr in
21+
f head (fold f first tail),
22+
in
23+
# Compute `7!`
24+
[1, 2, 3, 4, 5, 6]
25+
|> map ((+) 1)
26+
|> fold (*) 1
27+

samples/Nickel/config-gcc.ncl

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# test = 'pass'
2+
3+
# Validate and normalize gcc flags. They can be either a string `-Wextra` or
4+
# a structured value `{flag = "W", arg = "extra"}`. Arguments are not checked.
5+
let
6+
GccFlag =
7+
let supported_flags = ["W", "c", "S", "e", "o"] in
8+
let is_valid_flag
9+
| doc "check if a string of length > 0 is a valid flag"
10+
= fun string =>
11+
std.array.elem (std.string.substring 0 1 string) supported_flags
12+
in
13+
14+
std.contract.custom (fun label =>
15+
match {
16+
value if std.is_string value && is_valid_flag value => 'Ok value,
17+
{ flag, arg } if std.array.elem flag supported_flags =>
18+
# We normalize a record representation to a string
19+
'Ok "%{flag}%{arg}",
20+
value if std.is_string value =>
21+
'Error { message = "unknown flag %{value}" },
22+
{ flag, arg = _ } =>
23+
'Error { message = "unknown flag %{flag}" },
24+
{ .. } =>
25+
'Error {
26+
message = "bad record structure: missing field `flag` or `arg`",
27+
},
28+
_ => 'Error { message = "expected record or string" },
29+
}
30+
),
31+
Path =
32+
let pattern = m%"^(.+)/([^/]+)$"% in
33+
std.contract.from_validator (fun value =>
34+
if std.is_string value then
35+
if std.string.is_match pattern value then
36+
'Ok
37+
else
38+
'Error { message = "invalid path" }
39+
else
40+
'Error { message = "not a string" }
41+
),
42+
SharedObjectFile =
43+
std.contract.from_validator (fun value =>
44+
if std.is_string value then
45+
if std.string.is_match m%"\.so$"% value then
46+
'Ok
47+
else
48+
'Error { message = "not an .so file" }
49+
else
50+
'Error { message = "not a string" }
51+
),
52+
OptLevel =
53+
std.contract.from_predicate (match {
54+
0 or 1 or 2 => true,
55+
_ => false,
56+
}
57+
),
58+
in
59+
60+
let GccConf = {
61+
path_libc
62+
| doc "Path to libc."
63+
| Path
64+
| SharedObjectFile
65+
| default
66+
= "/lib/x86_64-linux-gnu/libc.so",
67+
68+
flags
69+
| doc m%"
70+
Additional flags to pass to GCC. Either provide a string without the
71+
leading `-`, or a structured value `{flag : String, arg: String}`.
72+
"%
73+
| Array GccFlag
74+
| default
75+
= [],
76+
77+
optimization_level
78+
| doc m%"
79+
Optimization level. Possible values:
80+
81+
- *0*: unoptimized
82+
- *1*: normal
83+
- *2*: use optimizations
84+
"%
85+
| OptLevel
86+
| default
87+
= 1,
88+
}
89+
in
90+
91+
{
92+
flags = ["Wextra", { flag = "o", arg = "stuff.o" }],
93+
optimization_level = 2,
94+
} | GccConf
95+

samples/Nickel/imports.ncl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# test = 'ignore'
2+
3+
# Nickel can import plain yaml, or json files
4+
let
5+
data_users = (import "data_users.yml"),
6+
data_groups = (import "data_groups.json"),
7+
# or even toml
8+
data_machines = (import "data_machines.toml"),
9+
# And of course other nickel files
10+
data_nickel_properties = (import "data_nickel_properties.ncl"),
11+
in
12+
13+
# This is the output object
14+
{
15+
users = data_users.users,
16+
groups = data_groups.groups,
17+
machines = data_machines.machines,
18+
off_topic = {
19+
nickel_properties = data_nickel_properties,
20+
}
21+
}

test/test_heuristics.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ def test_ncl_by_heuristics
755755
"Gerber Image" => all_fixtures("Gerber Image", "*"),
756756
"XML" => all_fixtures("XML", "*.ncl"),
757757
"Text" => all_fixtures("Text", "*.ncl"),
758-
# Missing heuristic for NCL
759-
nil => all_fixtures("NCL", "*.ncl")
758+
"Nickel" => all_fixtures("Nickel", "*.ncl"),
759+
"NCL" => all_fixtures("NCL", "*.ncl")
760760
}, alt_name="test.ncl")
761761
end
762762

0 commit comments

Comments
 (0)