hermes/syntaxhl.h

210 lines
6.5 KiB
C
Raw Permalink Normal View History

2020-01-02 06:51:00 +00:00
#include <stdlib.h>
#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)
2020-01-02 06:51:00 +00:00
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};
2020-01-06 22:03:56 +00:00
char *MAN_HL_extensions[] = {".1", ".2", ".3", ".4", ".5", ".6", ".7", ".8", ".man", ".mdoc", ".1b", ".mandoc", NULL};
2020-08-01 22:12:17 +00:00
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
2020-01-02 06:51:00 +00:00
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
2020-01-02 06:51:00 +00:00
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
2020-01-02 06:51:00 +00:00
char *GO_HL_keywords[] = {
"break", "switch", "continue", "func", "interface", "select",
2020-02-09 17:56:42 +00:00
"case", "defer", "go", "map|", "struct", "chan|", "else", "goto",
2020-01-02 06:51:00 +00:00
"package", "const", "fallthrough|", "if", "range|", "type",
"for", "import", "return", "var", "uint8|", "uint16|", "uint32|",
"uint64", "int|", "uint|", "int8|", "int16|", "int32|", "int64|",
2020-02-09 17:56:42 +00:00
"float32|", "float|", "float64|", "complex64|", "complex128|",
"byte|", "rune|", "uintptr|", "string|", "bool|", "error|", NULL
2020-01-02 06:51:00 +00:00
};
// 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
};
2020-01-06 22:03:56 +00:00
// 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
};
2020-08-01 22:12:17 +00:00
// Nimf
char *NIMF_HL_keywords[] = {
"do", "loop", ":", ";", "if", "then", "else", "error", "exit", "halt",
". |", "and|", "or|", "drop|", "<r|", "r>|", "@|", "!|", "var", "svar",
"over|", "dup|", NULL
};
2020-01-02 06:51:00 +00:00
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...
2020-01-02 06:51:00 +00:00
{
"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)
2020-01-02 06:51:00 +00:00
},
{
"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
2020-01-06 22:03:56 +00:00
},
{
"man/*roff",
MAN_HL_extensions,
"\\#",
".ig",
".end",
MAN_HL_keywords,
HL_HIGHLIGHT_STRINGS
2020-08-01 22:12:17 +00:00
},
{
"nimf",
NIMF_HL_extensions,
NULL,
"( ",
" )",
NIMF_HL_keywords,
HL_HIGHLIGHT_STRINGS
},
2020-01-02 06:51:00 +00:00
};
#define HLDB_ENTRIES (sizeof(HLDB) / sizeof(HLDB[0]))