--- Build strict file-reference rules for C# source and script files
-- @module formats.csharp.references

local csharp_references = {}

local load_prefix = "^%s*#%s*load%s*"
local assembly_prefix = "^%s*#%s*r%s*"
local line_prefix = "^%s*#%s*line%s+%d+%s+"
local checksum_prefix = "^%s*#%s*pragma%s+checksum%s+"

--- Return whether one directive target can name a local file
-- @param reference table parsed file reference
-- @return boolean accepted
local function is_local_target(reference)
	local path = reference.path

	return path:match("^%a:[/\\]") ~= nil or path:match("^%a[%w+%.%-]*:") == nil
end

--- Return direct local-file references from C# directives
-- @return table rules
function csharp_references.new()
	return {
		{ prefix = load_prefix, open = "\"", close = "\"", validate = is_local_target },
		{ prefix = assembly_prefix, open = "\"", close = "\"", validate = is_local_target },
		{ prefix = line_prefix, open = "\"", close = "\"", validate = is_local_target },
		{ prefix = checksum_prefix, open = "\"", close = "\"", validate = is_local_target },
	}
end

return csharp_references
