## Syntax highlighting for nano for MMBasic (c) Thomas Hugo Williams 2021
## Bit of a "dogs dinner" at the moment because derived from syntax for X11-Basic

syntax "MMBasic" "\.(bas|BAS|inc|INC)$"

comment "' "

# Variable names

icolor white "\<[A-Z_][A-Za-z0-9_]*(|\$|\%|\||\(\))\>"

# system vars
icolor cyan "\<(CCSAPLID|CCSERR|CRSCOL|CRSLIN|CTIMER|FALSE)\>"
icolor cyan "\<(GPS_ALT|GPS_LAT|GPS_LON|MOUSEK|MOUSES|MOUSEX|MOUSEY)\>"
icolor cyan "\<(PI|STIMER|TIMER|TRUE)\>"

# system string vars
icolor cyan "\<(DATE|FILEEVENT|INKEY|MM.CMDLINE|TERMINALNAME|TIME|TRACE)\$"

#special system vars
icolor cyan "\<(ANDROID|GPIO|GPS|SENSOR|WIN32|UNIX)\?"

# system array vars

# regular functions

icolor cyan "\<(ABS|ACOS|ACOSH|ADD|AND|ARG|ARRPTR|ASC|ASIN|ASINH|ATAN|ATANH|ATN)\("
icolor cyan "\<(BCHG|BCLR|BSET|BTST|BYTE)\("
icolor cyan "\<(CALL|CALLD|CARD|CBRT|CEIL|COMBIN|CONJ|COS|COSH|CRC|CVD|CVF|CVI|CVL|CVS)\("
icolor cyan "\<(EOF|EVAL|EVEN|EXEC|EXIST|EXP|EXPM1)\("
icolor cyan "\<(FACT|FIX|FLOOR|FORK|FORM_ALERT|FORM_CENTER|FORM_DIAL|FORM_DO|FRAC|FREEFILE)\("
icolor cyan "\<(GAMMA|GASDEV|GCD|GLOB|GPIO)\("
icolor cyan "\<(HYPOT)\("
icolor cyan "\<(IMAG|INODE|INP|INSTR|INT|INVERT|IOCTL)\("
icolor cyan "\<(JULIAN)\("
icolor cyan "\<(LCM|LEN|LGAMMA|LISTSELECT|LN|LOC|LOF|LOG|LOG10|LOG1P|LOGB|LPEEK|LTEXTLEN)\("
icolor cyan "\<(MALLOC|MAX|MIN|MOD|MODE|MSHRINK|MUL)\("
icolor cyan "\<(NEXTPRIME|NLINK|NOT)\("
icolor cyan "\<(OBJC_DRAW|OBJC_FIND|OBJC_OFFSET|ODD|OR)\("
icolor cyan "\<(PEEK|POINT|POWM|PRED|PTST)\("
icolor cyan "\<(RAD|RAND|RANDOM|REAL|REALLOC|RINSTR|ROL|ROOT|ROR|ROUND|RSRC_GADDR)\("
icolor cyan "\<(SENSOR|SGN|SHL|SHM_ATTACH|SHM_MALLOC|SHR|SIN|SINH|SIZE|SQR|SQRT|SRAND|SUB|SUCC|SWAP|SYM_ADR)\("
icolor cyan "\<(TALLY|TAN|TANH|TRUNC)\("
icolor cyan "\<(UBOUND)\("
icolor cyan "\<(VAL|VARIAT|VARPTR|VRFY)\("
icolor cyan "\<(WORD|WORT_SEP)\("
icolor cyan "\<(XOR)\("

# question functions
icolor cyan "\<(EVENT|INP|TYP|VAL)\?\("

# special functions

icolor cyan "\<(INP)\%\("
icolor cyan "\<(INP)\&\("

# string functions
icolor cyan "\<(ARID|ARIE)\$\("
icolor cyan "\<(BIN|BWTD|BWTE)\$\("
icolor cyan "\<(CALL|CHR|COMPRESS)\$\("
icolor cyan "\<(DECLOSE|DECRYPT|DIR)\$\("
icolor cyan "\<(ENCLOSE|ENCRYPT|ENV|ERR)\$\("
icolor cyan "\<(FSFIRST|FSNEXT)\$\("
icolor cyan "\<(HASH|HEX)\$\("
icolor cyan "\<(INLINE|INPUT)\$\("
icolor cyan "\<(JULDATE)\$\("
icolor cyan "\<(LEFT|LEFTOF|LINEINPUT|LOWER)\$\("
icolor cyan "\<(MID|MKA|MKD|MKF|MKI|MKL|MKS|MTFD|MTFE)\$\("
icolor cyan "\<(OCT)\$\("
icolor cyan "\<(PARAM|PNGDECODE|PNGENCODE|PRG)\$\("
icolor cyan "\<(REVERSE|RADIX|RIGHT|RIGHTOF|RLD|RLE)\$\("
icolor cyan "\<(SIGN|SPACE|STR|STRING|SYSTEM)\$\("
icolor cyan "\<(TERMINALNAME)\$\("
icolor cyan "\<(UCASE|UNCOMPRESS|UNIXDATE|UNIXTIME|UPPER|USING)\$\("
icolor cyan "\<(WORD)\$\("
icolor cyan "\<(XTRIM)\$\("

# array functions

icolor cyan "\<(0|1|CONVOLUT|CVA|FFT|INV|SMUL|SOLVE|TRANS)\("

# special commands

icolor cyan "(^|^[[:space:]]*)(LOCAL)\>"
icolor cyan "(^|^[[:space:]]*)DATA.*$"

icolor cyan "(^|^[[:space:]]*)ENDFUNCTION\>"
icolor cyan "(^|^[[:space:]]*)(BREAK|CONTINUE|EXIT\ IF)\>"
icolor cyan "(^|^[[:space:]]*)(FUNCTION|PROCEDURE|DEFFN)\>"

icolor cyan "(^|^[[:space:]]*)(endselect|select|default|endif|else\ if|else|case|do|loop|next|while|wend|repeat|until|spawn|void)\>"
icolor cyan "(^|^[[:space:]]*)(QUIT|STOP|TRON|TROFF|ECHO|EDIT|NEW|RUN)\>"

# regular commands

icolor cyan "(^|^[[:space:]]*)(ABSOLUTE|ADD|AFTER|ALERT|ARRAYCOPY|ARRAYFILL)\>"
icolor cyan "(^|^[[:space:]]*)(BEEP|BELL|BGET|BLOAD|BMOVE|BOTTOMW|BOUNDARY|BOX|BPUT|BSAVE)\>"
icolor cyan "(^|^[[:space:]]*)(CALL|CHAIN|CHMOD|CIRCLE|CLEAR|CLEARW|CLIP|CLOSEW|CLR|CLS|CONNECT|COPYAREA|CURVE)\>"
icolor cyan "(^|^[[:space:]]*)(DEC|DEFFILL|DEFLINE|DEFMARK|DEFMOUSE|DEFTEXT|DELAY|DIV|DPOKE|DRAW|DUMP)\>"
icolor cyan "(^|^[[:space:]]*)(ELLIPSE|ERASE|ERROR|EVAL|EVENT|EVERY|EXEC)\>"
icolor cyan "(^|^[[:space:]]*)(FFT|FILESELECT|FILL|FIT|FIT_LINEAR|FIT_POLY|FLUSH|FREE|FULLW)\>"
icolor cyan "(^|^[[:space:]]*)(GET|GET_GEOMETRY|GET_LOCATION|GET_SCREENSIZE|GPIO|GPRINT|GPS|GRAPHMODE)\>"
icolor cyan "(^|^[[:space:]]*)(HELP|HIDEK|HIDEM|HOME)\>"
icolor cyan "(^|^[[:space:]]*)(INC|INFOW|INPUT)\>"
icolor cyan "(^|^[[:space:]]*)(KEYEVENT|KILL)\>"
icolor cyan "(^|^[[:space:]]*)(LINE|LINEINPUT|LINK|LIST|LOAD|LOCATE|LPOKE|LTEXT)\>"
icolor cyan "(^|^[[:space:]]*)(MEMDUMP|MENU|MENUDEF|MENUKILL|MENUSET|MERGE|MFREE|MKDIR|MOUSE|MOUSEEVENT|MOTIONEVENT|MOVEW|MSYNC|MUL)\>"
icolor cyan "(^|^[[:space:]]*)(NOOP|NOP|NOROOTWINDOW)\>"
icolor cyan "(^|^[[:space:]]*)(OBJC_ADD|OBJC_DELETE|ON|OPEN|OPENW|OUT)\>"
icolor cyan "(^|^[[:space:]]*)(PAUSE|PBOX|PCIRCLE|PELLIPSE|PIPE|PLAYSOUND|PLAYSOUNDFILE|PLIST|PLOT|POKE|POLYFILL|POLYLINE|POLYMARK|PRBOX|PUT|PUTBACK|PUT_BITMAP)\>"
icolor cyan "(^|^[[:space:]]*)(RBOX|RECEIVE|RELSEEK|RENAME|RESTORE|RMDIR|ROOTWINDOW|RSRC_FREE|RSRC_LOAD)\>"
icolor cyan "(^|^[[:space:]]*)(SAVE|SAVESCREEN|SAVEWINDOW|SCOPE|SCREEN|SEEK|SEND|SENSOR|SETFONT|SETMOUSE|SGET|SHELL|SHM_DETACH|SHM_FREE|SHOWK|SHOWM|SHOEPAGE|SIZEW|SORT|SOUND|SPEAK|SPLIT|SPUT|SUB|SWAP|SYSTEM)\>"
icolor cyan "(^|^[[:space:]]*)(TITLEW|TOPW|TOUCH)\>"
icolor cyan "(^|^[[:space:]]*)(UNLINK|UNMAP|USEWINDOW)\>"
icolor cyan "(^|^[[:space:]]*)(VERSION|VSYNC)\>"
icolor cyan "(^|^[[:space:]]*)(WATCH|WAVE|WORT_SEP)\>"
icolor cyan "(^|^[[:space:]]*)(XLOAD|XRUN)\>"

## MMBasic additions
icolor cyan "(^|^[[:space:]]*)(BASE|DEFAULT|FLOAT|EXPLICIT|ON|CONSOLE|SETTITLE)\>"

## commands with a blank in it

icolor cyan "(^|^[[:space:]]*)(ON\ ERROR\ CONT)"
icolor cyan "(^|^[[:space:]]*)(ON\ BREAK\ CONT)"
icolor cyan "(^|^[[:space:]]*)(ECHO\ (ON|OFF))"
icolor cyan "(^|^[[:space:]]*)(EXIT\ DO)"

## keywords
icolor cyan "\<(and|append|arch|as)\>"
icolor cyan "\<(background|black|blue|bound|bright|byte)\>"
icolor cyan "\<(case|cat|chdir|clear|console|cfunaddr|choice|close|color|colour|const|csub|cyan)\>"
icolor cyan "\<(default|device|din|dim|directory|dout)\>"
icolor cyan "\<(else|elseif|end|envvar|errno|error|exit|exists)\>"
icolor cyan "\<(filesize|float|font|fontwidth|fontheight|for|foreground|function)\>"
icolor cyan "\<(getcursor|getsize|gosub|goto|gray|green|grey)\>"
icolor cyan "\<(hidecursor|hpos|hres)\>"
icolor cyan "\<(if|inc|input|integer)\>"
icolor cyan "\<(length|let|lgetbyte|llen|longstring|loop)\>"
icolor cyan "\<(magenta|mm.errno|mm.hres|mm.info|mm.vres|mod|mode)\>"
icolor cyan "\<(next|none|not)\>"
icolor cyan "\<(option|or)\>"
icolor cyan "\<(path|pause|peek|pin|poke|print|purple)\>"
icolor cyan "\<(randomize|read|receive|red|reset|return|rgb|rnd)\>"
icolor cyan "\<(select|send|serial|setcursor|setpin|settick|showcursor|settitle|spi|static|step|sub)\>"
icolor cyan "\<(tab|text|then|to|tron|troff)\>"
icolor cyan "\<(until|using)\>"
icolor cyan "\<(var|varaddr|version|vpos|vres)\>"
icolor cyan "\<(while|white)\>"
icolor cyan "\<(xmodem|xor)\>"
icolor cyan "\<(yellow)\>"

## options
icolor cyan "\<(option base)\>"
icolor cyan "\<(option codepage(| on| off))\>"
icolor cyan "\<(option console(| both| serial| screen))\>"
icolor cyan "\<(option explicit(| on| off))\>"
icolor cyan "\<(option resolution(| character| pixel))\>"

## mminfo sub-commands

## preprocessor keywords
icolor red "(^|^[[:space:]]*)\#include\>"

## functions returning strings
icolor cyan "\<(field|format|lcase|lgetstr|mm.info)\$\("

## system variables
icolor cyan "\<(cwd|mm.device|mm.errmsg)\$"

## keywords containing blanks
icolor cyan "\<(continue\ do)\>"
icolor cyan "\<(exists (dir|file|symlink))\>"
icolor cyan "\<(exit do|for input as|for output as|line input|memory copy)\>"
icolor cyan "\<(memory set|on error (abort|ignore|skip)|on key|trace off)\>"
icolor cyan "\<(trace on)\>"

## operators
color white "[+*=\^]" "<" ">" "/" "-"
# color brightred "[@\~]"

## number constants
#icolor green "\b(([1-9][0-9]+)|0+)\.[0-9]+j?\b" "\b([1-9][0-9]*[Lj]?)\b" "\b0o?[0-7]*L?\b" "\b0x[1-9a-f][0-9a-f]*L?\b" "\b0b[01]+\b"
icolor green "\<[-]?[1-9][0-9]*[.[0-9]*]?([Ee][+-]?[0-9]+)?\>"
icolor green "\<[-]?[0](\.[0-9]+)?\>"
icolor green "&h[0-9a-f]+\b"
icolor green "&b[0-1]+\b"
icolor green "\#[0-9]+\b"
icolor green "\.[0-9]+([Ee][+-]?[0-9]+)?\b"

## parentheses
color white "[(){}]" "\[" "\]"

# labels
icolor white "(^|^[[:space:]]*)[^\ ^=.]*:"

# Comments - 1 of 2.
color yellow "'.*"
icolor yellow "REM\ .*"

# Strings
color brightmagenta ""(\\.|[^"])*""

# Comments - 2 of 2.
color yellow "'[^']*$"

# SPTrans directives.
color red "'!.*"

#icolor brightwhite,blue "(^|^[[:space:]]*)PROGRAM.*$"

#shebang line
#icolor brightwhite,green "^\#\!.*$"

## trailing spaces
color ,red "[[:space:]]+$"

## reminders
color brightwhite,yellow "(FIXME|TODO|XXX)"
