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

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

SyntaxDefinition& addM4() {

	return SyntaxDefinitionManager::instance()
		->add(

			{ "M4",
			  { "%.m4$", "%.ac$", "%.at$", "^configure%.ac$", "^configure%.in$" },
			  {
				  { { "\\b(m4_)?dnl\\b.*" }, "comment", "", SyntaxPatternMatchType::RegEx },
				  { { "#.*" }, "comment" },
				  { { "`", "`" }, "string" },
				  { { "%$%d+" }, "type" },
				  { { "%$[@*#]" }, "type" },
				  { { "([%u_][%u%d_]*)%s*(%()", "%)" },
					{ "normal", "keyword", "operator" },
					{ "operator" },
					"",
					SyntaxPatternMatchType::LuaPattern,
					{
						{ { "include", "$self" },
						  "normal",
						  "",
						  SyntaxPatternMatchType::LuaPattern },

					} },
				  { { "([%a_][%w_]*)%s*(%()", "%)" },
					{ "normal", "symbol", "operator" },
					{ "operator" },
					"",
					SyntaxPatternMatchType::LuaPattern,
					{
						{ { "include", "$self" },
						  "normal",
						  "",
						  SyntaxPatternMatchType::LuaPattern },

					} },
				  { { "%(", "%)" },
					{ "operator" },
					{ "operator" },
					"",
					SyntaxPatternMatchType::LuaPattern,
					{
						{ { "include", "$self" },
						  "normal",
						  "",
						  SyntaxPatternMatchType::LuaPattern },

					} },
				  { { "[%a_][%w_]*" }, "symbol" },

			  },
			  {
				  { "m4___line__", "literal" },
				  { "__file__", "literal" },
				  { "m4_undefine", "type" },
				  { "undefine", "type" },
				  { "m4_undivert", "keyword" },
				  { "m4_divnum", "literal" },
				  { "m4_divert", "keyword" },
				  { "sysval", "literal" },
				  { "divert", "keyword" },
				  { "m4_popdef", "type" },
				  { "m4_debugfile", "keyword" },
				  { "__line__", "literal" },
				  { "m4wrap", "keyword" },
				  { "m4_changeword", "keyword" },
				  { "changeword", "keyword" },
				  { "m4_changequote", "keyword" },
				  { "m4_changecom", "keyword" },
				  { "m4_m4exit", "keyword" },
				  { "errprint", "keyword" },
				  { "m4_shift", "keyword" },
				  { "shift", "keyword" },
				  { "debugfile", "keyword" },
				  { "m4_builtin", "keyword" },
				  { "maketemp", "function" },
				  { "len", "function" },
				  { "m4exit", "keyword" },
				  { "m4_eval", "function" },
				  { "m4_defun", "function" },
				  { "m4_maketemp", "function" },
				  { "m4_include", "keyword" },
				  { "m4_fatal", "keyword" },
				  { "m4_errprint", "keyword" },
				  { "define", "function" },
				  { "decr", "function" },
				  { "divnum", "literal" },
				  { "substr", "function" },
				  { "m4_decr", "function" },
				  { "patsubst", "function" },
				  { "m4_translit", "function" },
				  { "eval", "function" },
				  { "incr", "function" },
				  { "defn", "function" },
				  { "m4_ifelse", "keyword" },
				  { "m4_sysval", "literal" },
				  { "m4_regexp", "function" },
				  { "format", "function" },
				  { "m4_format", "function" },
				  { "m4_if", "keyword" },
				  { "m4_pushdef", "function" },
				  { "m4_patsubst", "function" },
				  { "m4_provide_if", "function" },
				  { "m4_define", "function" },
				  { "m4_ifval", "keyword" },
				  { "index", "function" },
				  { "translit", "function" },
				  { "include", "keyword" },
				  { "changecom", "keyword" },
				  { "m4_incr", "function" },
				  { "m4_warning", "keyword" },
				  { "builtin", "keyword" },
				  { "m4_index", "function" },
				  { "regexp", "function" },
				  { "sinclude", "keyword" },
				  { "m4_sinclude", "keyword" },
				  { "m4___file__", "literal" },
				  { "m4_syscmd", "keyword" },
				  { "m4_m4wrap", "keyword" },
				  { "m4_defn", "function" },
				  { "esyscmd", "keyword" },
				  { "m4_len", "function" },
				  { "m4_esyscmd", "keyword" },
				  { "m4_ifset", "keyword" },
				  { "popdef", "type" },
				  { "m4_foreach", "keyword" },
				  { "m4_split", "function" },
				  { "changequote", "keyword" },
				  { "m4_substr", "function" },
				  { "syscmd", "keyword" },
				  { "m4_pattern_allow", "function" },
				  { "m4_foreach_w", "keyword" },
				  { "m4_normalize", "function" },
				  { "m4_case", "keyword" },
				  { "ifdef", "keyword" },
				  { "m4_version_compare", "function" },
				  { "m4_ifdef", "keyword" },
				  { "m4_ifndef", "keyword" },
				  { "undivert", "keyword" },
				  { "ifelse", "keyword" },
				  { "m4_copy", "function" },
				  { "indir", "keyword" },
				  { "pushdef", "function" },
				  { "m4_indir", "keyword" },

			  },
			  "#",
			  {}

			} )
		.setFoldRangeType( FoldRangeType::Markdown )
		.setFoldBraces( {
			{ '(', ')' },
			{ '[', ']' },
			{ '{', '}' },
		} );
}

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