Add syntax mapping from NSE to Lua (#2214)

This commit is contained in:
Cre3per 2022-06-04 14:12:42 +02:00 committed by GitHub
parent 16488f3d82
commit ed4997c77c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 0 deletions

View File

@ -12,6 +12,8 @@
## Syntaxes
- NSE (Nmap Scripting Engine) is mapped to Lua, see #2151 (@Cre3per)
## Themes
## `bat` as a library

View File

@ -67,6 +67,11 @@ impl<'a> SyntaxMapping<'a> {
.insert("*.pac", MappingTarget::MapTo("JavaScript (Babel)"))
.unwrap();
// See #2151, https://nmap.org/book/nse-language.html
mapping
.insert("*.nse", MappingTarget::MapTo("Lua"))
.unwrap();
// See #1008
mapping
.insert("rails", MappingTarget::MapToUnknown)

View File

@ -0,0 +1,34 @@
--- Finds factorial of a number.
-- @param value Number to find factorial.
-- @return Factorial of number.
local function factorial(value)
 if value <= 1 then
 return 1
 else
 return value * factorial(value - 1)
 end
end
--- Joins a table of strings into a new string.
-- @param table Table of strings.
-- @param separator Separator character.
-- @return Joined string.
local function join(table, separator)
 local data = ""
 
 for index, value in ipairs(table) do
 data = data .. value .. separator
 end
 
 data = data:sub(1, data:len() - 1)
 
 return data
end
local a = factorial(5)
print(a)
local b = join({ "l", "u", "a" }, ",")
print(b)

34
tests/syntax-tests/source/NSE/test.nse vendored Normal file
View File

@ -0,0 +1,34 @@
--- Finds factorial of a number.
-- @param value Number to find factorial.
-- @return Factorial of number.
local function factorial(value)
if value <= 1 then
return 1
else
return value * factorial(value - 1)
end
end
--- Joins a table of strings into a new string.
-- @param table Table of strings.
-- @param separator Separator character.
-- @return Joined string.
local function join(table, separator)
local data = ""
for index, value in ipairs(table) do
data = data .. value .. separator
end
data = data:sub(1, data:len() - 1)
return data
end
local a = factorial(5)
print(a)
local b = join({ "l", "u", "a" }, ",")
print(b)