#include <eepp/ui/doc/languages/fortran.hpp>
#include <eepp/ui/doc/syntaxdefinitionmanager.hpp>

namespace EE { namespace UI { namespace Doc { namespace Language {

SyntaxDefinition& addFortran() {
	// Based in Lite-XL Rohan Vashisht implementation
	// https://github.com/RohanVashisht1234/fortran_syntax_highlighter_lite-xl
	auto& sd = SyntaxDefinitionManager::instance()->add(

		{ "Fortran",
		  { "%.f$", "%.f90$", "%.f95$" },
		  {
			  { { "'", "'", "\\" }, "string" },
			  { { "\"", "\"", "\\" }, "string" },
			  { { "!.*" }, "comment" },
			  { { "%.[%a_][%w_]+%." }, "normal" },
			  { { "[!%-/*?:=><+]" }, "operator" },
			  { { "[%a_][%w_]*%f[(]" }, "function" },
			  { { "(program)(%s+)([%a_][%w_]*)" }, { "normal", "keyword", "normal", "literal" } },
			  { { "(module)(%s+)([%a_][%w_]*)" }, { "normal", "keyword", "normal", "literal" } },
			  { { "(use)(%s+)([%a_][%w_]*)" }, { "normal", "keyword", "normal", "literal" } },
			  { { "(struct)(%s+)([%a_][%w_]*)" }, { "normal", "keyword", "normal", "literal" } },
			  { { "-?%d+[%d%.eE_]*" }, "number" },
			  { { "-?%.?%d+" }, "number" },
			  { { "[%a_][%w_]*" }, "symbol" },

		  },
		  { { "then", "keyword" },
			{ "public", "keyword" },
			{ "allocatable", "keyword" },
			{ "private", "keyword" },
			{ "concurrent", "keyword" },
			{ "only", "keyword" },
			{ "none", "type" },
			{ ".or.", "type" },
			{ "cycle", "keyword" },
			{ "len", "type" },
			{ ".le.", "type" },
			{ ".not.", "type" },
			{ "sequence", "keyword" },
			{ ".false.", "type" },
			{ ".eq.", "type" },
			{ ".lt.", "type" },
			{ "end", "keyword" },
			{ "subroutine", "keyword" },
			{ "extends", "keyword" },
			{ ".neqv.", "type" },
			{ "complex", "keyword" },
			{ "module", "keyword" },
			{ "result", "keyword" },
			{ "call", "keyword" },
			{ ".true.", "type" },
			{ "function", "keyword" },
			{ "logical", "keyword" },
			{ "else", "keyword" },
			{ ".ge", "type" },
			{ "parameter", "keyword" },
			{ "contains", "keyword" },
			{ "print", "keyword" },
			{ "write", "keyword" },
			{ ".eqv.", "type" },
			{ ".and.", "type" },
			{ "struct", "keyword" },
			{ "character", "keyword" },
			{ "integer", "keyword" },
			{ ".ne.", "type" },
			{ "real", "keyword" },
			{ "use", "keyword" },
			{ "if", "keyword" },
			{ "protected", "keyword" },
			{ "do", "keyword" },
			{ ".gt.", "type" },
			{ "program", "keyword" },
			{ "implicit", "keyword" },
			{ "stop", "keyword" },
			{ "type", "keyword" },
			{ "endif", "keyword" },
			{ "enddo", "keyword" }

		  },
		  "!",
		  {}

		} );
	sd.setCaseInsensitive( true );
	sd.setFoldRangeType( FoldRangeType::Indentation );
	return sd;
}

}}}} // namespace EE::UI::Doc::Language
