<commit_before>-------------------------------------------------------------------------------
-- @release $Id: standard.lua,v 1.39 2007/12/21 17:50:48 tomas Exp $
-------------------------------------------------------------------------------

local assert, pairs, tostring, type = assert, pairs, tostring, type
local io = require "io"
local lfs = require "lfs"
local luadoc = require "luadoc"
local util = require "luadoc.util"
local tags = require "taglet_sf_tags"
local string = require "string"
local table = require "table"

local print = print

module 'taglet_sf'

-- LuaDoc doesn't like ../ in pathnames when specifying where to look for lua files.
-- This trims out the '../lua/starfall/" that will pretty much always be there.
local function fix_filepath(fname)
	return fname:match("^..[/\\]lua[/\\]starfall[/\\]?(.*)$") or fname
end

local function printTable(tbl, tabs, printed)
	tabs = tabs or 0
	printed = printed or {}
	local indention = string.rep("\t",tabs)
	for k,v in pairs(tbl) do
		local dont_print = false
		if type(v) == "table" then
			if not printed[v] then
				print(indention..tostring(k))
				print(indention.."{")
				printed[v] = k
				printTable(v,tabs+1,printed)
				printed[v] = nil
				print(indention.."}")
			else
				print(indentation..tostring(k),"=","[table:"..printed[v].."]")
			end
		else
			print(indention..tostring(k),"=",v)
		end
	end
end


-------------------------------------------------------------------------------
-- Creates an iterator for an array base on a class type.
-- @param t array to iterate over
-- @param class name of the class to iterate over

function class_iterator (t, class)
	return function ()
		local i = 1
		return function ()
			while t[i] and t[i].class ~= class do
				i = i + 1
			end
			local v = t[i]
			i = i + 1
			return v
		end
	end
end

-- Patterns for function recognition
local identifiers_list_pattern = "%s*(.-)%s*"
local identifier_pattern = "[^%(%s]+"
local function_patterns = {
	"^()%s*function%s*("..identifier_pattern..")%s*%("..identifiers_list_pattern.."%)",
	"^%s*(local%s)%s*function%s*("..identifier_pattern..")%s*%("..identifiers_list_pattern.."%)",
	"^()%s*("..identifier_pattern..")%s*%=%s*function%s*%("..identifiers_list_pattern.."%)",
}

-------------------------------------------------------------------------------
-- Checks if the line contains a function definition
-- @param line string with line text
-- @return function information or nil if no function definition found

local function check_function (line)
	line = util.trim(line)

	local info = table.foreachi(function_patterns, function (_, pattern)
		local r, _, l, id, param = string.find(line, pattern)
		if r ~= nil then
			return {
				name = id,
				private = (l == "local"),
				param = util.split("%s*,%s*", param),
			}
		end
	end)

	-- TODO: remove these assert's?
	if info ~= nil then
		assert(info.name, "function name undefined")
		assert(info.param, string.format("undefined parameter list for function `%s'", info.name))
	end

	return info
end

--- Checks if the line contains a library registration
-- (call to SF.Libraries.Register or SF.Libraries.RegisterLocal)
-- @param line string with line text
-- @return the library name or nil if not found
-- @return the table name used to store the library
local function check_library(line)
	line = util.trim(line)

	-- Global library
	local tblref, name = line:match("^%s*local%s+([%w_]+).-=%s*SF%.Libraries%.Register%(\"([^\"]+)\".-%)$")
	if tblref then
		return name, tblref
	end

	-- Local library
	local name, tblref = line:match("^%s*local%s+([%w_]+).-=%s*SF%.Libraries%.RegisterLocal%(\"([^\"]+)\".-%)$")
	return name, tblref
end

--- Checks if the line contains a class creation
local function check_class(line)
	line = util.trim(line)

	local name, tblref = line:match("^SF.Typedef%(%s*[\"']([^\"']+)[\"'],%s*([%w_]+)%s*%)$")
	return name, tblref
end

-------------------------------------------------------------------------------
-- Extracts summary information from a description. The first sentence of each 
-- doc comment should be a summary sentence, containing a concise but complete <commit_msg>Fixed failure to generate local library docs<commit_after>-------------------------------------------------------------------------------
-- @release $Id: standard.lua,v 1.39 2007/12/21 17:50:48 tomas Exp $
-------------------------------------------------------------------------------

local assert, pairs, tostring, type = assert, pairs, tostring, type
local io = require "io"
local lfs = require "lfs"
local luadoc = require "luadoc"
local util = require "luadoc.util"
local tags = require "taglet_sf_tags"
local string = require "string"
local table = require "table"

local print = print

module 'taglet_sf'

-- LuaDoc doesn't like ../ in pathnames when specifying where to look for lua files.
-- This trims out the '../lua/starfall/" that will pretty much always be there.
local function fix_filepath(fname)
	return fname:match("^..[/\\]lua[/\\]starfall[/\\]?(.*)$") or fname
end

-------------------------------------------------------------------------------
-- Creates an iterator for an array base on a class type.
-- @param t array to iterate over
-- @param class name of the class to iterate over

function class_iterator (t, class)
	return function ()
		local i = 1
		return function ()
			while t[i] and t[i].class ~= class do
				i = i + 1
			end
			local v = t[i]
			i = i + 1
			return v
		end
	end
end

-- Patterns for function recognition
local identifiers_list_pattern = "%s*(.-)%s*"
local identifier_pattern = "[^%(%s]+"
local function_patterns = {
	"^()%s*function%s*("..identifier_pattern..")%s*%("..identifiers_list_pattern.."%)",
	"^%s*(local%s)%s*function%s*("..identifier_pattern..")%s*%("..identifiers_list_pattern.."%)",
	"^()%s*("..identifier_pattern..")%s*%=%s*function%s*%("..identifiers_list_pattern.."%)",
}

-------------------------------------------------------------------------------
-- Checks if the line contains a function definition
-- @param line string with line text
-- @return function information or nil if no function definition found

local function check_function (line)
	line = util.trim(line)

	local info = table.foreachi(function_patterns, function (_, pattern)
		local r, _, l, id, param = string.find(line, pattern)
		if r ~= nil then
			return {
				name = id,
				private = (l == "local"),
				param = util.split("%s*,%s*", param),
			}
		end
	end)

	-- TODO: remove these assert's?
	if info ~= nil then
		assert(info.name, "function name undefined")
		assert(info.param, string.format("undefined parameter list for function `%s'", info.name))
	end

	return info
end

--- Checks if the line contains a library registration
-- (call to SF.Libraries.Register or SF.Libraries.RegisterLocal)
-- @param line string with line text
-- @return the library name or nil if not found
-- @return the table name used to store the library
local function check_library(line)
	line = util.trim(line)

	-- Global library
	local tblref, name = line:match("^%s*local%s+([%w_]+).-=%s*SF%.Libraries%.Register%(\"([^\"]+)\".-%)$")
	if tblref then
		return name, tblref
	end

	-- Local library
	local tblref, name = line:match("^%s*local%s+([%w_]+).-=%s*SF%.Libraries%.RegisterLocal%(\"([^\"]+)\".-%)$")
	return name, tblref
end

--- Checks if the line contains a class creation
local function check_class(line)
	line = util.trim(line)

	local name, tblref = line:match("^SF.Typedef%(%s*[\"']([^\"']+)[\"'],%s*([%w_]+)%s*%)$")
	return name, tblref
end

-------------------------------------------------------------------------------
-- Extracts summary information from a description. The first sentence of each 
-- doc comment should be a summary sentence, containing a concise but complete 
{'fraction_non_alphanumeric': 0.24790835371347664, 'fraction_numerical': 0.00540610117132192, 'mean_word_length': 2.4984241332733004, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5132523', 'n_tokens_mistral': 2526, 'n_tokens_neox': 2331, 'n_words': 747}