|
|
@ -1,82 +1,305 @@
|
|
|
|
const CodeMirror = require('codemirror')
|
|
|
|
const CodeMirror = require('codemirror');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CodeMirror.defineMode('nimrod', function(conf, parserConf) {
|
|
|
|
CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
|
|
|
var ERRORCLASS = 'error';
|
|
|
|
var ERRORCLASS = 'error';
|
|
|
|
|
|
|
|
|
|
|
|
function wordRegexp(words) {
|
|
|
|
function wordRegexp(words) {
|
|
|
|
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
|
|
|
return new RegExp('^((' + words.join(')|(') + '))\\b');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var operators = new RegExp("\\=\\+\\-\\*\\/\\<\\>\\@\\$\\~\\&\\%\\|\\!\\?\\^\\:\\\\");
|
|
|
|
var operators = new RegExp('\\=\\+\\-\\*\\/\\<\\>\\@\\$\\~\\&\\%\\|\\!\\?\\^\\:\\\\');
|
|
|
|
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
|
|
|
var identifiers = new RegExp('^[_A-Za-z][_A-Za-z0-9]*');
|
|
|
|
|
|
|
|
|
|
|
|
var commonkeywords = ['addr', 'asm', 'atomic',
|
|
|
|
var commonkeywords = [
|
|
|
|
'bind', 'block', 'break', 'case', 'cast',
|
|
|
|
'addr',
|
|
|
|
'const', 'continue', 'converter',
|
|
|
|
'asm',
|
|
|
|
'discard', 'distinct', 'do',
|
|
|
|
'atomic',
|
|
|
|
'elif', 'else', 'end', 'enum', 'except', 'export',
|
|
|
|
'bind',
|
|
|
|
'finally', 'for', 'from',
|
|
|
|
'block',
|
|
|
|
'generic',
|
|
|
|
'break',
|
|
|
|
'if', 'import', 'include', 'interface', 'iterator',
|
|
|
|
'case',
|
|
|
|
'lambda', 'let',
|
|
|
|
'cast',
|
|
|
|
'macro', 'method', 'mixin', 'nil',
|
|
|
|
'const',
|
|
|
|
'object', 'out',
|
|
|
|
'continue',
|
|
|
|
'proc', 'ptr',
|
|
|
|
'converter',
|
|
|
|
'raise', 'ref', 'return',
|
|
|
|
'discard',
|
|
|
|
'shared', 'static',
|
|
|
|
'distinct',
|
|
|
|
'template', 'try', 'tuple', 'type',
|
|
|
|
'do',
|
|
|
|
'using',
|
|
|
|
'elif',
|
|
|
|
'var',
|
|
|
|
'else',
|
|
|
|
'when', 'while', 'with', 'without',
|
|
|
|
'end',
|
|
|
|
'yield',
|
|
|
|
'enum',
|
|
|
|
|
|
|
|
'except',
|
|
|
|
// keyword operators
|
|
|
|
'export',
|
|
|
|
'shl', 'shr', 'and', 'or', 'xor', 'not',
|
|
|
|
'finally',
|
|
|
|
'div', 'mod', 'is', 'isnot', 'in', 'as', 'of'];
|
|
|
|
'for',
|
|
|
|
|
|
|
|
'from',
|
|
|
|
var commonBuiltins = ["int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16",
|
|
|
|
'generic',
|
|
|
|
"uint32", "uint64", "float", "float32", "float64", "bool", "char",
|
|
|
|
'if',
|
|
|
|
"string", "cstring", "pointer", "range", "array", "openarray",
|
|
|
|
'import',
|
|
|
|
"seq", "set", "Byte", "Natural", "Positive", "TObject", "PObject",
|
|
|
|
'include',
|
|
|
|
"Conversion", "TResult", "TAddress", "BiggestInt", "BiggestFloat",
|
|
|
|
'interface',
|
|
|
|
"cchar", "cschar", "cshort", "cint", "csize", "cuchar", "cushort",
|
|
|
|
'iterator',
|
|
|
|
"clong", "clonglong", "cfloat", "cdouble", "clongdouble", "cuint",
|
|
|
|
'lambda',
|
|
|
|
"culong", "culonglong", "cchar", "cstringArray", "TEndian", "PFloat32",
|
|
|
|
'let',
|
|
|
|
"PFloat64", "PInt64", "PInt32", "TGC_Strategy", "TFile", "TFileMode",
|
|
|
|
'macro',
|
|
|
|
"TFileHandle", "isMainModule", "CompileDate", "CompileTime", "NimrodVersion",
|
|
|
|
'method',
|
|
|
|
"NimrodMajor", "NimrodMinor", "NimrodPatch", "cpuEndian", "hostOS", "hostCPU",
|
|
|
|
'mixin',
|
|
|
|
"inf", "neginf", "nan", "QuitSuccess", "QuitFailure", "dbgLineHook", "stdin",
|
|
|
|
'nil',
|
|
|
|
"stdout", "stderr", "defined", "new", "high", "low", "sizeof", "succ", "pred",
|
|
|
|
'object',
|
|
|
|
"inc", "dec", "newSeq", "len", "incl", "excl", "card", "ord", "chr", "ze",
|
|
|
|
'out',
|
|
|
|
"ze64", "toU8", "toU16", "toU32", "abs", "min", "max", "add", "repr", "contains",
|
|
|
|
'proc',
|
|
|
|
"toFloat", "toBiggestFloat", "toInt", "toBiggestInt", "addQuitProc", "copy",
|
|
|
|
'ptr',
|
|
|
|
"setLen", "newString", "zeroMem", "copyMem", "moveMem", "equalMem", "alloc",
|
|
|
|
'raise',
|
|
|
|
"alloc0", "realloc", "dealloc", "setLen", "assert", "swap", "getRefcount",
|
|
|
|
'ref',
|
|
|
|
"getCurrentException", "Msg", "getOccupiedMem", "getFreeMem", "getTotalMem",
|
|
|
|
'return',
|
|
|
|
"isNil", "seqToPtr", "find", "pop", "GC_disable", "GC_enable", "GC_fullCollect",
|
|
|
|
'shared',
|
|
|
|
"GC_setStrategy", "GC_enableMarkAnd", "Sweep", "GC_disableMarkAnd", "Sweep",
|
|
|
|
'static',
|
|
|
|
"GC_getStatistics", "GC_ref", "GC_ref", "GC_ref", "GC_unref", "GC_unref",
|
|
|
|
'template',
|
|
|
|
"GC_unref", "quit", "OpenFile", "OpenFile", "CloseFile", "EndOfFile",
|
|
|
|
'try',
|
|
|
|
"readChar", "FlushFile", "readFile", "write", "readLine", "writeln",
|
|
|
|
'tuple',
|
|
|
|
"writeln", "getFileSize", "ReadBytes", "ReadChars", "readBuffer",
|
|
|
|
'type',
|
|
|
|
"writeBytes", "writeChars", "writeBuffer", "setFilePos", "getFilePos",
|
|
|
|
'using',
|
|
|
|
"fileHandle", "countdown", "countup", "items", "lines",
|
|
|
|
'var',
|
|
|
|
"true", "false",
|
|
|
|
'when',
|
|
|
|
|
|
|
|
'while',
|
|
|
|
// exceptions
|
|
|
|
'with',
|
|
|
|
"E_Base", "EAsynch", "ESynch", "ESystem", "EIO", "EOS", "ERessourceExhausted",
|
|
|
|
'without',
|
|
|
|
"EArithmetic", "EDivByZero", "EOverflow", "EAccessViolation", "EAssertionFailed",
|
|
|
|
'yield',
|
|
|
|
"EControlC", "EInvalidValue", "EOutOfMemory", "EInvalidIndex", "EInvalidField",
|
|
|
|
|
|
|
|
"EOutOfRange", "EStackOverflow", "ENoExceptionToReraise", "EInvalidObjectAssignment",
|
|
|
|
// keyword operators
|
|
|
|
"EInvalidObject", "EInvalidLibrary", "EInvalidKey", "EInvalidObjectConversion",
|
|
|
|
'shl',
|
|
|
|
"EFloatingPoint", "EFloatInvalidOp", "EFloatDivByZero", "EFloatOverflow",
|
|
|
|
'shr',
|
|
|
|
"EFloatInexact", "EDeadThrea"];
|
|
|
|
'and',
|
|
|
|
|
|
|
|
'or',
|
|
|
|
if(parserConf.extra_keywords != undefined)
|
|
|
|
'xor',
|
|
|
|
|
|
|
|
'not',
|
|
|
|
|
|
|
|
'div',
|
|
|
|
|
|
|
|
'mod',
|
|
|
|
|
|
|
|
'is',
|
|
|
|
|
|
|
|
'isnot',
|
|
|
|
|
|
|
|
'in',
|
|
|
|
|
|
|
|
'as',
|
|
|
|
|
|
|
|
'of'
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var commonBuiltins = [
|
|
|
|
|
|
|
|
'int',
|
|
|
|
|
|
|
|
'int8',
|
|
|
|
|
|
|
|
'int16',
|
|
|
|
|
|
|
|
'int32',
|
|
|
|
|
|
|
|
'int64',
|
|
|
|
|
|
|
|
'uint',
|
|
|
|
|
|
|
|
'uint8',
|
|
|
|
|
|
|
|
'uint16',
|
|
|
|
|
|
|
|
'uint32',
|
|
|
|
|
|
|
|
'uint64',
|
|
|
|
|
|
|
|
'float',
|
|
|
|
|
|
|
|
'float32',
|
|
|
|
|
|
|
|
'float64',
|
|
|
|
|
|
|
|
'bool',
|
|
|
|
|
|
|
|
'char',
|
|
|
|
|
|
|
|
'string',
|
|
|
|
|
|
|
|
'cstring',
|
|
|
|
|
|
|
|
'pointer',
|
|
|
|
|
|
|
|
'range',
|
|
|
|
|
|
|
|
'array',
|
|
|
|
|
|
|
|
'openarray',
|
|
|
|
|
|
|
|
'seq',
|
|
|
|
|
|
|
|
'set',
|
|
|
|
|
|
|
|
'Byte',
|
|
|
|
|
|
|
|
'Natural',
|
|
|
|
|
|
|
|
'Positive',
|
|
|
|
|
|
|
|
'TObject',
|
|
|
|
|
|
|
|
'PObject',
|
|
|
|
|
|
|
|
'Conversion',
|
|
|
|
|
|
|
|
'TResult',
|
|
|
|
|
|
|
|
'TAddress',
|
|
|
|
|
|
|
|
'BiggestInt',
|
|
|
|
|
|
|
|
'BiggestFloat',
|
|
|
|
|
|
|
|
'cchar',
|
|
|
|
|
|
|
|
'cschar',
|
|
|
|
|
|
|
|
'cshort',
|
|
|
|
|
|
|
|
'cint',
|
|
|
|
|
|
|
|
'csize',
|
|
|
|
|
|
|
|
'cuchar',
|
|
|
|
|
|
|
|
'cushort',
|
|
|
|
|
|
|
|
'clong',
|
|
|
|
|
|
|
|
'clonglong',
|
|
|
|
|
|
|
|
'cfloat',
|
|
|
|
|
|
|
|
'cdouble',
|
|
|
|
|
|
|
|
'clongdouble',
|
|
|
|
|
|
|
|
'cuint',
|
|
|
|
|
|
|
|
'culong',
|
|
|
|
|
|
|
|
'culonglong',
|
|
|
|
|
|
|
|
'cchar',
|
|
|
|
|
|
|
|
'cstringArray',
|
|
|
|
|
|
|
|
'TEndian',
|
|
|
|
|
|
|
|
'PFloat32',
|
|
|
|
|
|
|
|
'PFloat64',
|
|
|
|
|
|
|
|
'PInt64',
|
|
|
|
|
|
|
|
'PInt32',
|
|
|
|
|
|
|
|
'TGC_Strategy',
|
|
|
|
|
|
|
|
'TFile',
|
|
|
|
|
|
|
|
'TFileMode',
|
|
|
|
|
|
|
|
'TFileHandle',
|
|
|
|
|
|
|
|
'isMainModule',
|
|
|
|
|
|
|
|
'CompileDate',
|
|
|
|
|
|
|
|
'CompileTime',
|
|
|
|
|
|
|
|
'NimrodVersion',
|
|
|
|
|
|
|
|
'NimrodMajor',
|
|
|
|
|
|
|
|
'NimrodMinor',
|
|
|
|
|
|
|
|
'NimrodPatch',
|
|
|
|
|
|
|
|
'cpuEndian',
|
|
|
|
|
|
|
|
'hostOS',
|
|
|
|
|
|
|
|
'hostCPU',
|
|
|
|
|
|
|
|
'inf',
|
|
|
|
|
|
|
|
'neginf',
|
|
|
|
|
|
|
|
'nan',
|
|
|
|
|
|
|
|
'QuitSuccess',
|
|
|
|
|
|
|
|
'QuitFailure',
|
|
|
|
|
|
|
|
'dbgLineHook',
|
|
|
|
|
|
|
|
'stdin',
|
|
|
|
|
|
|
|
'stdout',
|
|
|
|
|
|
|
|
'stderr',
|
|
|
|
|
|
|
|
'defined',
|
|
|
|
|
|
|
|
'new',
|
|
|
|
|
|
|
|
'high',
|
|
|
|
|
|
|
|
'low',
|
|
|
|
|
|
|
|
'sizeof',
|
|
|
|
|
|
|
|
'succ',
|
|
|
|
|
|
|
|
'pred',
|
|
|
|
|
|
|
|
'inc',
|
|
|
|
|
|
|
|
'dec',
|
|
|
|
|
|
|
|
'newSeq',
|
|
|
|
|
|
|
|
'len',
|
|
|
|
|
|
|
|
'incl',
|
|
|
|
|
|
|
|
'excl',
|
|
|
|
|
|
|
|
'card',
|
|
|
|
|
|
|
|
'ord',
|
|
|
|
|
|
|
|
'chr',
|
|
|
|
|
|
|
|
'ze',
|
|
|
|
|
|
|
|
'ze64',
|
|
|
|
|
|
|
|
'toU8',
|
|
|
|
|
|
|
|
'toU16',
|
|
|
|
|
|
|
|
'toU32',
|
|
|
|
|
|
|
|
'abs',
|
|
|
|
|
|
|
|
'min',
|
|
|
|
|
|
|
|
'max',
|
|
|
|
|
|
|
|
'add',
|
|
|
|
|
|
|
|
'repr',
|
|
|
|
|
|
|
|
'contains',
|
|
|
|
|
|
|
|
'toFloat',
|
|
|
|
|
|
|
|
'toBiggestFloat',
|
|
|
|
|
|
|
|
'toInt',
|
|
|
|
|
|
|
|
'toBiggestInt',
|
|
|
|
|
|
|
|
'addQuitProc',
|
|
|
|
|
|
|
|
'copy',
|
|
|
|
|
|
|
|
'setLen',
|
|
|
|
|
|
|
|
'newString',
|
|
|
|
|
|
|
|
'zeroMem',
|
|
|
|
|
|
|
|
'copyMem',
|
|
|
|
|
|
|
|
'moveMem',
|
|
|
|
|
|
|
|
'equalMem',
|
|
|
|
|
|
|
|
'alloc',
|
|
|
|
|
|
|
|
'alloc0',
|
|
|
|
|
|
|
|
'realloc',
|
|
|
|
|
|
|
|
'dealloc',
|
|
|
|
|
|
|
|
'setLen',
|
|
|
|
|
|
|
|
'assert',
|
|
|
|
|
|
|
|
'swap',
|
|
|
|
|
|
|
|
'getRefcount',
|
|
|
|
|
|
|
|
'getCurrentException',
|
|
|
|
|
|
|
|
'Msg',
|
|
|
|
|
|
|
|
'getOccupiedMem',
|
|
|
|
|
|
|
|
'getFreeMem',
|
|
|
|
|
|
|
|
'getTotalMem',
|
|
|
|
|
|
|
|
'isNil',
|
|
|
|
|
|
|
|
'seqToPtr',
|
|
|
|
|
|
|
|
'find',
|
|
|
|
|
|
|
|
'pop',
|
|
|
|
|
|
|
|
'GC_disable',
|
|
|
|
|
|
|
|
'GC_enable',
|
|
|
|
|
|
|
|
'GC_fullCollect',
|
|
|
|
|
|
|
|
'GC_setStrategy',
|
|
|
|
|
|
|
|
'GC_enableMarkAnd',
|
|
|
|
|
|
|
|
'Sweep',
|
|
|
|
|
|
|
|
'GC_disableMarkAnd',
|
|
|
|
|
|
|
|
'Sweep',
|
|
|
|
|
|
|
|
'GC_getStatistics',
|
|
|
|
|
|
|
|
'GC_ref',
|
|
|
|
|
|
|
|
'GC_ref',
|
|
|
|
|
|
|
|
'GC_ref',
|
|
|
|
|
|
|
|
'GC_unref',
|
|
|
|
|
|
|
|
'GC_unref',
|
|
|
|
|
|
|
|
'GC_unref',
|
|
|
|
|
|
|
|
'quit',
|
|
|
|
|
|
|
|
'OpenFile',
|
|
|
|
|
|
|
|
'OpenFile',
|
|
|
|
|
|
|
|
'CloseFile',
|
|
|
|
|
|
|
|
'EndOfFile',
|
|
|
|
|
|
|
|
'readChar',
|
|
|
|
|
|
|
|
'FlushFile',
|
|
|
|
|
|
|
|
'readFile',
|
|
|
|
|
|
|
|
'write',
|
|
|
|
|
|
|
|
'readLine',
|
|
|
|
|
|
|
|
'writeln',
|
|
|
|
|
|
|
|
'writeln',
|
|
|
|
|
|
|
|
'getFileSize',
|
|
|
|
|
|
|
|
'ReadBytes',
|
|
|
|
|
|
|
|
'ReadChars',
|
|
|
|
|
|
|
|
'readBuffer',
|
|
|
|
|
|
|
|
'writeBytes',
|
|
|
|
|
|
|
|
'writeChars',
|
|
|
|
|
|
|
|
'writeBuffer',
|
|
|
|
|
|
|
|
'setFilePos',
|
|
|
|
|
|
|
|
'getFilePos',
|
|
|
|
|
|
|
|
'fileHandle',
|
|
|
|
|
|
|
|
'countdown',
|
|
|
|
|
|
|
|
'countup',
|
|
|
|
|
|
|
|
'items',
|
|
|
|
|
|
|
|
'lines',
|
|
|
|
|
|
|
|
'true',
|
|
|
|
|
|
|
|
'false',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// exceptions
|
|
|
|
|
|
|
|
'E_Base',
|
|
|
|
|
|
|
|
'EAsynch',
|
|
|
|
|
|
|
|
'ESynch',
|
|
|
|
|
|
|
|
'ESystem',
|
|
|
|
|
|
|
|
'EIO',
|
|
|
|
|
|
|
|
'EOS',
|
|
|
|
|
|
|
|
'ERessourceExhausted',
|
|
|
|
|
|
|
|
'EArithmetic',
|
|
|
|
|
|
|
|
'EDivByZero',
|
|
|
|
|
|
|
|
'EOverflow',
|
|
|
|
|
|
|
|
'EAccessViolation',
|
|
|
|
|
|
|
|
'EAssertionFailed',
|
|
|
|
|
|
|
|
'EControlC',
|
|
|
|
|
|
|
|
'EInvalidValue',
|
|
|
|
|
|
|
|
'EOutOfMemory',
|
|
|
|
|
|
|
|
'EInvalidIndex',
|
|
|
|
|
|
|
|
'EInvalidField',
|
|
|
|
|
|
|
|
'EOutOfRange',
|
|
|
|
|
|
|
|
'EStackOverflow',
|
|
|
|
|
|
|
|
'ENoExceptionToReraise',
|
|
|
|
|
|
|
|
'EInvalidObjectAssignment',
|
|
|
|
|
|
|
|
'EInvalidObject',
|
|
|
|
|
|
|
|
'EInvalidLibrary',
|
|
|
|
|
|
|
|
'EInvalidKey',
|
|
|
|
|
|
|
|
'EInvalidObjectConversion',
|
|
|
|
|
|
|
|
'EFloatingPoint',
|
|
|
|
|
|
|
|
'EFloatInvalidOp',
|
|
|
|
|
|
|
|
'EFloatDivByZero',
|
|
|
|
|
|
|
|
'EFloatOverflow',
|
|
|
|
|
|
|
|
'EFloatInexact',
|
|
|
|
|
|
|
|
'EDeadThrea'
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parserConf.extra_keywords != undefined)
|
|
|
|
commonkeywords = commonkeywords.concat(parserConf.extra_keywords);
|
|
|
|
commonkeywords = commonkeywords.concat(parserConf.extra_keywords);
|
|
|
|
|
|
|
|
|
|
|
|
if(parserConf.extra_builtins != undefined)
|
|
|
|
if (parserConf.extra_builtins != undefined)
|
|
|
|
commonBuiltins = commonBuiltins.concat(parserConf.extra_builtins);
|
|
|
|
commonBuiltins = commonBuiltins.concat(parserConf.extra_builtins);
|
|
|
|
|
|
|
|
|
|
|
|
var keywords = wordRegexp(commonkeywords);
|
|
|
|
var keywords = wordRegexp(commonkeywords);
|
|
|
@ -84,7 +307,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
|
|
|
|
|
|
|
var indentInfo = null;
|
|
|
|
var indentInfo = null;
|
|
|
|
|
|
|
|
|
|
|
|
var stringPrefixes = new RegExp("^(('{3}|\"{3}|['\"]))", "i");
|
|
|
|
var stringPrefixes = new RegExp('^((\'{3}|"{3}|[\'"]))', 'i');
|
|
|
|
|
|
|
|
|
|
|
|
// tokenizers
|
|
|
|
// tokenizers
|
|
|
|
function tokenBase(stream, state) {
|
|
|
|
function tokenBase(stream, state) {
|
|
|
@ -106,8 +329,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stream.eatSpace())
|
|
|
|
if (stream.eatSpace()) return null;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ch = stream.peek();
|
|
|
|
var ch = stream.peek();
|
|
|
|
|
|
|
|
|
|
|
@ -121,22 +343,34 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
if (stream.match(/^[0-9\.]/, false)) {
|
|
|
|
if (stream.match(/^[0-9\.]/, false)) {
|
|
|
|
var floatLiteral = false;
|
|
|
|
var floatLiteral = false;
|
|
|
|
// Floats
|
|
|
|
// Floats
|
|
|
|
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
|
|
|
|
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) {
|
|
|
|
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
|
|
|
|
floatLiteral = true;
|
|
|
|
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream.match(/^\d+\.\d*/)) {
|
|
|
|
|
|
|
|
floatLiteral = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream.match(/^\.\d+/)) {
|
|
|
|
|
|
|
|
floatLiteral = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (floatLiteral) {
|
|
|
|
if (floatLiteral) {
|
|
|
|
// Float literals may be "imaginary"
|
|
|
|
// Float literals may be "imaginary"
|
|
|
|
stream.eat(/J/i);
|
|
|
|
stream.eat(/J/i);
|
|
|
|
return 'number';
|
|
|
|
return 'number';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Integers
|
|
|
|
// Integers
|
|
|
|
var intLiteral = false;
|
|
|
|
var intLiteral = false;
|
|
|
|
// Hex
|
|
|
|
// Hex
|
|
|
|
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
|
|
|
|
if (stream.match(/^0x[0-9a-f]+/i)) {
|
|
|
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
// Binary
|
|
|
|
// Binary
|
|
|
|
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
|
|
|
|
if (stream.match(/^0b[01]+/i)) {
|
|
|
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
// Octal
|
|
|
|
// Octal
|
|
|
|
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
|
|
|
|
if (stream.match(/^0o[0-7]+/i)) {
|
|
|
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
// Decimal
|
|
|
|
// Decimal
|
|
|
|
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
|
|
|
|
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
|
|
|
|
// Decimal literals may be "imaginary"
|
|
|
|
// Decimal literals may be "imaginary"
|
|
|
@ -145,7 +379,9 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
intLiteral = true;
|
|
|
|
intLiteral = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Zero by itself with no other piece of number.
|
|
|
|
// Zero by itself with no other piece of number.
|
|
|
|
if (stream.match(/^0(?![\dx])/i)) { intLiteral = true; }
|
|
|
|
if (stream.match(/^0(?![\dx])/i)) {
|
|
|
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (intLiteral) {
|
|
|
|
if (intLiteral) {
|
|
|
|
// Integer literals may be "long"
|
|
|
|
// Integer literals may be "long"
|
|
|
|
stream.eat(/L/i);
|
|
|
|
stream.eat(/L/i);
|
|
|
@ -159,18 +395,17 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stream.match(operators))
|
|
|
|
if (stream.match(operators)) return 'operator';
|
|
|
|
return 'operator';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stream.match(keywords))
|
|
|
|
if (stream.match(keywords)) return 'keyword';
|
|
|
|
return 'keyword';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stream.match(builtins))
|
|
|
|
if (stream.match(builtins)) return 'builtin';
|
|
|
|
return 'builtin';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stream.match(identifiers)) {
|
|
|
|
if (stream.match(identifiers)) {
|
|
|
|
if (state.lastToken != null &&
|
|
|
|
if (
|
|
|
|
state.lastToken.match(/proc|iterator|macro|template|class|converter/)) {
|
|
|
|
state.lastToken != null &&
|
|
|
|
|
|
|
|
state.lastToken.match(/proc|iterator|macro|template|class|converter/)
|
|
|
|
|
|
|
|
) {
|
|
|
|
return 'def';
|
|
|
|
return 'def';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -192,7 +427,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
if (stream.eat('\\')) {
|
|
|
|
if (stream.eat('\\')) {
|
|
|
|
stream.next();
|
|
|
|
stream.next();
|
|
|
|
if (singleline && stream.eol()) {
|
|
|
|
if (singleline && stream.eol()) {
|
|
|
|
return OUTCLASS;
|
|
|
|
return OUTCLASS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (stream.match(delimiter)) {
|
|
|
|
} else if (stream.match(delimiter)) {
|
|
|
|
state.tokenize = tokenBase;
|
|
|
|
state.tokenize = tokenBase;
|
|
|
@ -240,36 +475,36 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dedent(stream, state, type) {
|
|
|
|
function dedent(stream, state, type) {
|
|
|
|
type = type || 'nim';
|
|
|
|
type = type || 'nim';
|
|
|
|
if (state.scopes.length == 1) return;
|
|
|
|
if (state.scopes.length == 1) return;
|
|
|
|
if (state.scopes[0].type === 'nim') {
|
|
|
|
if (state.scopes[0].type === 'nim') {
|
|
|
|
var _indent = stream.indentation();
|
|
|
|
var _indent = stream.indentation();
|
|
|
|
var _indent_index = -1;
|
|
|
|
var _indent_index = -1;
|
|
|
|
for (var i = 0; i < state.scopes.length; ++i) {
|
|
|
|
for (var i = 0; i < state.scopes.length; ++i) {
|
|
|
|
if (_indent === state.scopes[i].offset) {
|
|
|
|
if (_indent === state.scopes[i].offset) {
|
|
|
|
_indent_index = i;
|
|
|
|
_indent_index = i;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_indent_index === -1) {
|
|
|
|
if (_indent_index === -1) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (state.scopes[0].offset !== _indent) {
|
|
|
|
while (state.scopes[0].offset !== _indent) {
|
|
|
|
state.scopes.shift();
|
|
|
|
state.scopes.shift();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (type === 'nim') {
|
|
|
|
|
|
|
|
state.scopes[0].offset = stream.indentation();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (type === 'nim') {
|
|
|
|
if (state.scopes[0].type != type) {
|
|
|
|
state.scopes[0].offset = stream.indentation();
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
state.scopes.shift();
|
|
|
|
if (state.scopes[0].type != type) {
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
state.scopes.shift();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function tokenLexer(stream, state) {
|
|
|
|
function tokenLexer(stream, state) {
|
|
|
@ -288,25 +523,21 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
return style;
|
|
|
|
return style;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((style === 'variable' || style === 'builtin')
|
|
|
|
if ((style === 'variable' || style === 'builtin') && state.lastStyle === 'meta') {
|
|
|
|
&& state.lastStyle === 'meta') {
|
|
|
|
|
|
|
|
style = 'meta';
|
|
|
|
style = 'meta';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Handle scope changes.
|
|
|
|
// Handle scope changes.
|
|
|
|
if (current.match(/return|break|continue|raise/) ||
|
|
|
|
if (current.match(/return|break|continue|raise/) || (current === 'discard' && stream.eol()))
|
|
|
|
(current === 'discard' && stream.eol()))
|
|
|
|
|
|
|
|
state.dedent += 1;
|
|
|
|
state.dedent += 1;
|
|
|
|
|
|
|
|
|
|
|
|
if (current === 'lambda' || current === 'proc')
|
|
|
|
if (current === 'lambda' || current === 'proc') state.lambda = true;
|
|
|
|
state.lambda = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var delimiter_index = '[({'.indexOf(current);
|
|
|
|
var delimiter_index = '[({'.indexOf(current);
|
|
|
|
|
|
|
|
|
|
|
|
if (delimiter_index !== -1) {
|
|
|
|
if (delimiter_index !== -1) {
|
|
|
|
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
|
|
|
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index + 1));
|
|
|
|
}
|
|
|
|
} else if (stream.eol() && current.match(/\=|\:|import|include|type|const|var|let/)) {
|
|
|
|
else if(stream.eol() && current.match(/\=|\:|import|include|type|const|var|let/)) {
|
|
|
|
|
|
|
|
indent(stream, state);
|
|
|
|
indent(stream, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -335,7 +566,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
startState: function(basecolumn) {
|
|
|
|
startState: function(basecolumn) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
tokenize: tokenBase,
|
|
|
|
tokenize: tokenBase,
|
|
|
|
scopes: [{offset:basecolumn || 0, type:'nim'}],
|
|
|
|
scopes: [{ offset: basecolumn || 0, type: 'nim' }],
|
|
|
|
lastStyle: null,
|
|
|
|
lastStyle: null,
|
|
|
|
lastToken: null,
|
|
|
|
lastToken: null,
|
|
|
|
lambda: false,
|
|
|
|
lambda: false,
|
|
|
@ -349,28 +580,24 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
state.lastStyle = style;
|
|
|
|
state.lastStyle = style;
|
|
|
|
|
|
|
|
|
|
|
|
var current = stream.current();
|
|
|
|
var current = stream.current();
|
|
|
|
if (current && style)
|
|
|
|
if (current && style) state.lastToken = current;
|
|
|
|
state.lastToken = current;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (stream.eol() && state.lambda)
|
|
|
|
if (stream.eol() && state.lambda) state.lambda = false;
|
|
|
|
state.lambda = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return style;
|
|
|
|
return style;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
indent: function(state) {
|
|
|
|
indent: function(state) {
|
|
|
|
if (state.tokenize != tokenBase)
|
|
|
|
if (state.tokenize != tokenBase) return state.tokenize.isString ? CodeMirror.Pass : 0;
|
|
|
|
return state.tokenize.isString ? CodeMirror.Pass : 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return state.scopes[0].offset;
|
|
|
|
return state.scopes[0].offset;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
lineComment: "#",
|
|
|
|
lineComment: '#',
|
|
|
|
fold: "indent"
|
|
|
|
fold: 'indent'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return external;
|
|
|
|
return external;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
CodeMirror.defineMIME("text/x-nimrod", "nimrod");
|
|
|
|
CodeMirror.defineMIME('text/x-nimrod', 'nimrod');
|
|
|
|
|
|
|
|
|
|
|
|