Skip to content

Commit ed4997c

Browse files
authored
Add syntax mapping from NSE to Lua (#2214)
1 parent 16488f3 commit ed4997c

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
## Syntaxes
1414

15+
- NSE (Nmap Scripting Engine) is mapped to Lua, see #2151 (@Cre3per)
16+
1517
## Themes
1618

1719
## `bat` as a library

src/syntax_mapping.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ impl<'a> SyntaxMapping<'a> {
6767
.insert("*.pac", MappingTarget::MapTo("JavaScript (Babel)"))
6868
.unwrap();
6969

70+
// See #2151, https://nmap.org/book/nse-language.html
71+
mapping
72+
.insert("*.nse", MappingTarget::MapTo("Lua"))
73+
.unwrap();
74+
7075
// See #1008
7176
mapping
7277
.insert("rails", MappingTarget::MapToUnknown)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--- Finds factorial of a number.
2+
-- @param value Number to find factorial.
3+
-- @return Factorial of number.
4+
local function factorial(value)
5+
 if value <= 1 then
6+
 return 1
7+
 else
8+
 return value * factorial(value - 1)
9+
 end
10+
end
11+
12+
--- Joins a table of strings into a new string.
13+
-- @param table Table of strings.
14+
-- @param separator Separator character.
15+
-- @return Joined string.
16+
local function join(table, separator)
17+
 local data = ""
18+
 
19+
 for index, value in ipairs(table) do
20+
 data = data .. value .. separator
21+
 end
22+
 
23+
 data = data:sub(1, data:len() - 1)
24+
 
25+
 return data
26+
end
27+
28+
local a = factorial(5)
29+
30+
print(a)
31+
32+
local b = join({ "l", "u", "a" }, ",")
33+
34+
print(b)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--- Finds factorial of a number.
2+
-- @param value Number to find factorial.
3+
-- @return Factorial of number.
4+
local function factorial(value)
5+
if value <= 1 then
6+
return 1
7+
else
8+
return value * factorial(value - 1)
9+
end
10+
end
11+
12+
--- Joins a table of strings into a new string.
13+
-- @param table Table of strings.
14+
-- @param separator Separator character.
15+
-- @return Joined string.
16+
local function join(table, separator)
17+
local data = ""
18+
19+
for index, value in ipairs(table) do
20+
data = data .. value .. separator
21+
end
22+
23+
data = data:sub(1, data:len() - 1)
24+
25+
return data
26+
end
27+
28+
local a = factorial(5)
29+
30+
print(a)
31+
32+
local b = join({ "l", "u", "a" }, ",")
33+
34+
print(b)

0 commit comments

Comments
 (0)