#include #define HL_HIGHLIGHT_NUMBERS (1<<0) #define HL_HIGHLIGHT_STRINGS (1<<1) struct editorSyntax { char *filetype; char **filematch; char *singleline_comment_start; char *multiline_comment_start; char *multiline_comment_end; char **keywords; int flags; }; // // filetypes // --------- // To create highlighting for a language do the following: // 1. Create a list of file extensions this will apply to. // Name the variable after the language: (ex. *LUA_HL_Extensions) // The list MUST end in NULL (see examples below) char *C_HL_extensions[] = {".c", ".h", ".cpp", NULL}; char *PY_HL_extensions[] = {".py", ".pyc", NULL}; char *GO_HL_extensions[] = {".go", NULL}; char *SH_HL_extensions[] = {".sh", NULL}; char *HTML_HL_extensions[] = {".html", ".html", NULL}; char *PHP_HL_extensions[] = {".php", NULL}; char *LUA_HL_extensions[] = {".lua", NULL}; char *MAN_HL_extensions[] = {".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".man", ".mdoc", ".1b", ".mandoc", NULL}; char *NIMF_HL_extensions[] = {".nh", ".nimf", ".nf", NULL}; // 2. Create a list of keywords. Keywords that end in "|" will be given // a secondary highlight color and words without them will be given the // primary highlight color. Like in step 1, the list MUST end in NULL // C char *C_HL_keywords[] = { "switch", "if", "while", "for", "break", "return", "else", "continue", "struct|", "union", "typedef", "static", "enum|", "class", "case|", "int|", "long|", "double|", "float|", "char|", "unsigned|", "signed|", "void|", "NULL", NULL }; // Python char *PY_HL_keywords[] = { "if", "elif", "for", "break", "return", "else", "def", "", "static", "enum", "class", "with", "assert", "except", "continue", "while", "finally", "try", "global", "False|", "True|", "None|", "not|", "and|", "as|", "yield|", "void|", "or|", "import|", "is|", "in|", "lambda|", "pass|", "raise|", "del|", NULL }; // Go char *GO_HL_keywords[] = { "break", "switch", "continue", "func", "interface", "select", "case", "defer", "go", "map|", "struct", "chan|", "else", "goto", "package", "const", "fallthrough|", "if", "range|", "type", "for", "import", "return", "var", "uint8|", "uint16|", "uint32|", "uint64", "int|", "uint|", "int8|", "int16|", "int32|", "int64|", "float32|", "float|", "float64|", "complex64|", "complex128|", "byte|", "rune|", "uintptr|", "string|", "bool|", "error|", NULL }; // Shell char *SH_HL_keywords[] = { "echo|", "readonly|", "if", "fi", "read", "set", "unset", "shift", "export", "else", "while", "do|", "done|", "for", "until", "case", "esac", "break|", "continue|", "exit", "return", "trap|", "wait|", "eval|", "exec|", "ulimit|", "umask|", NULL }; // HTML char *HTML_HL_keywords[] = { "html", "body", "br", "hr", "p", "blockquote", "title", "head", "header", "nav", "a", "div", "section", "footer", "main", "button", "ul", "li", "form", "input", "class|", "id|", "href|", "img", "src|", "target|", "style|", "meta", "h1", "h2", "h3", "h4", "h5", "role|", "!DOCTYPE|", "script", "type|", "link", "rel|", NULL }; // PHP char *PHP_HL_keywords[] = { "abstract|", "and|", "array|", "as|", "break|", "callable|", "case|", "catch", "class", "clone|", "const|", "continue|", "declare|", "default|", "die", "do|", "echo|", "else", "elseif", "empty|", "enddeclare|", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval|", "exit|", "extends|", "final|", "finally", "for", "foreach", "function", "global", "goto", "if", "implements|", "include", "include_once", "instanceof|", "insteadof|", "interface", "isset|", "list|", "namespace", "new|", "or|", "print|", "private|", "protected|", "public|", "require", "require_once", "return", "static|", "switch", "throw", "trait|", "try", "unset|", "use|", "var|", "while", "xor|", "yield", NULL }; // Lua char *LUA_HL_keywords[] = { "function", "return", "for", "while", "do", "if", "else", "elseif", "and|", "or|", "false|", "true|", "nil|", "until", "then|", "repeat|", "local|", "not|", "in|", "break|", NULL }; // Man pages (covers some basic macros) char *MAN_HL_keywords[] = { ".cc", ".SH", ".B", ".RB", ".RI", ".IR", ".P", ".nr", ".br", "\\P|", ".RS", ".RE", ".TA", ".DS", ".LD", ".DE", ".ID", ".De", ".CD", ".BE", ".KS", ".KE", ".KF", ".B1", ".B2", ".FS", ".FE", ".OH", ".EH", ".OF", ".EF", ".PT", ".HD", ".BT", ".TH", ".nf", ".fam", ".fi", ".TP", NULL }; // Nimf char *NIMF_HL_keywords[] = { "do", "loop", ":", ";", "if", "then", "else", "error", "exit", "halt", ". |", "and|", "or|", "drop|", "|", "@|", "!|", "var", "svar", "over|", "dup|", NULL }; static struct editorSyntax HLDB[] = { // 3. Add an entry to the editorSyndax db (this var). // See the C example comments for what each array member // does... { "c", // The name of the language, this will be displayed in the status bar C_HL_extensions, // the variable name created in step 1 "//", // Text representing the beginning of a single line comment, NULL if not wanted "/*", // Text representing the start of a multiline comment, NULL if not wanted "*/", // Text representing the end of a multiline comment, NULL if not wanted C_HL_keywords, // the variable name created in step 2 HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS // This controls whether or not to highlight numbers and strings // can be NULL, both (as seen here) or just one of them (without the pipe) }, { "python", PY_HL_extensions, "#", "'''", "'''", PY_HL_keywords, HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS }, { "go", GO_HL_extensions, "//", "/*", "*/", GO_HL_keywords, HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS }, { "shell", SH_HL_extensions, "#", "", "", SH_HL_keywords, HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS }, { "html", HTML_HL_extensions, "", "", HTML_HL_keywords, HL_HIGHLIGHT_NUMBERS }, { "php", PHP_HL_extensions, "//", "/*", "*/", PHP_HL_keywords, HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS }, { "lua", LUA_HL_extensions, "--", "--[[", "]]", LUA_HL_keywords, HL_HIGHLIGHT_NUMBERS | HL_HIGHLIGHT_STRINGS }, { "man/*roff", MAN_HL_extensions, "\\#", ".ig", ".end", MAN_HL_keywords, HL_HIGHLIGHT_STRINGS }, { "nimf", NIMF_HL_extensions, NULL, "( ", " )", NIMF_HL_keywords, HL_HIGHLIGHT_STRINGS }, }; #define HLDB_ENTRIES (sizeof(HLDB) / sizeof(HLDB[0]))