|
|
|
@ -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';
|
|
|
|
|
|
|
|
|
|
function wordRegexp(words) {
|
|
|
|
|
return new RegExp("^((" + words.join(")|(") + "))\\b");
|
|
|
|
|
return new RegExp('^((' + words.join(')|(') + '))\\b');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var operators = new RegExp("\\=\\+\\-\\*\\/\\<\\>\\@\\$\\~\\&\\%\\|\\!\\?\\^\\:\\\\");
|
|
|
|
|
var identifiers = new RegExp("^[_A-Za-z][_A-Za-z0-9]*");
|
|
|
|
|
|
|
|
|
|
var commonkeywords = ['addr', 'asm', 'atomic',
|
|
|
|
|
'bind', 'block', 'break', 'case', 'cast',
|
|
|
|
|
'const', 'continue', 'converter',
|
|
|
|
|
'discard', 'distinct', 'do',
|
|
|
|
|
'elif', 'else', 'end', 'enum', 'except', 'export',
|
|
|
|
|
'finally', 'for', 'from',
|
|
|
|
|
'generic',
|
|
|
|
|
'if', 'import', 'include', 'interface', 'iterator',
|
|
|
|
|
'lambda', 'let',
|
|
|
|
|
'macro', 'method', 'mixin', 'nil',
|
|
|
|
|
'object', 'out',
|
|
|
|
|
'proc', 'ptr',
|
|
|
|
|
'raise', 'ref', 'return',
|
|
|
|
|
'shared', 'static',
|
|
|
|
|
'template', 'try', 'tuple', 'type',
|
|
|
|
|
'using',
|
|
|
|
|
'var',
|
|
|
|
|
'when', 'while', 'with', 'without',
|
|
|
|
|
'yield',
|
|
|
|
|
|
|
|
|
|
// keyword operators
|
|
|
|
|
'shl', 'shr', 'and', 'or', '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)
|
|
|
|
|
var operators = new RegExp('\\=\\+\\-\\*\\/\\<\\>\\@\\$\\~\\&\\%\\|\\!\\?\\^\\:\\\\');
|
|
|
|
|
var identifiers = new RegExp('^[_A-Za-z][_A-Za-z0-9]*');
|
|
|
|
|
|
|
|
|
|
var commonkeywords = [
|
|
|
|
|
'addr',
|
|
|
|
|
'asm',
|
|
|
|
|
'atomic',
|
|
|
|
|
'bind',
|
|
|
|
|
'block',
|
|
|
|
|
'break',
|
|
|
|
|
'case',
|
|
|
|
|
'cast',
|
|
|
|
|
'const',
|
|
|
|
|
'continue',
|
|
|
|
|
'converter',
|
|
|
|
|
'discard',
|
|
|
|
|
'distinct',
|
|
|
|
|
'do',
|
|
|
|
|
'elif',
|
|
|
|
|
'else',
|
|
|
|
|
'end',
|
|
|
|
|
'enum',
|
|
|
|
|
'except',
|
|
|
|
|
'export',
|
|
|
|
|
'finally',
|
|
|
|
|
'for',
|
|
|
|
|
'from',
|
|
|
|
|
'generic',
|
|
|
|
|
'if',
|
|
|
|
|
'import',
|
|
|
|
|
'include',
|
|
|
|
|
'interface',
|
|
|
|
|
'iterator',
|
|
|
|
|
'lambda',
|
|
|
|
|
'let',
|
|
|
|
|
'macro',
|
|
|
|
|
'method',
|
|
|
|
|
'mixin',
|
|
|
|
|
'nil',
|
|
|
|
|
'object',
|
|
|
|
|
'out',
|
|
|
|
|
'proc',
|
|
|
|
|
'ptr',
|
|
|
|
|
'raise',
|
|
|
|
|
'ref',
|
|
|
|
|
'return',
|
|
|
|
|
'shared',
|
|
|
|
|
'static',
|
|
|
|
|
'template',
|
|
|
|
|
'try',
|
|
|
|
|
'tuple',
|
|
|
|
|
'type',
|
|
|
|
|
'using',
|
|
|
|
|
'var',
|
|
|
|
|
'when',
|
|
|
|
|
'while',
|
|
|
|
|
'with',
|
|
|
|
|
'without',
|
|
|
|
|
'yield',
|
|
|
|
|
|
|
|
|
|
// keyword operators
|
|
|
|
|
'shl',
|
|
|
|
|
'shr',
|
|
|
|
|
'and',
|
|
|
|
|
'or',
|
|
|
|
|
'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);
|
|
|
|
|
|
|
|
|
|
if(parserConf.extra_builtins != undefined)
|
|
|
|
|
if (parserConf.extra_builtins != undefined)
|
|
|
|
|
commonBuiltins = commonBuiltins.concat(parserConf.extra_builtins);
|
|
|
|
|
|
|
|
|
|
var keywords = wordRegexp(commonkeywords);
|
|
|
|
@ -84,7 +307,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
|
|
|
|
|
var indentInfo = null;
|
|
|
|
|
|
|
|
|
|
var stringPrefixes = new RegExp("^(('{3}|\"{3}|['\"]))", "i");
|
|
|
|
|
var stringPrefixes = new RegExp('^((\'{3}|"{3}|[\'"]))', 'i');
|
|
|
|
|
|
|
|
|
|
// tokenizers
|
|
|
|
|
function tokenBase(stream, state) {
|
|
|
|
@ -106,8 +329,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.eatSpace())
|
|
|
|
|
return null;
|
|
|
|
|
if (stream.eatSpace()) return null;
|
|
|
|
|
|
|
|
|
|
var ch = stream.peek();
|
|
|
|
|
|
|
|
|
@ -121,22 +343,34 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
if (stream.match(/^[0-9\.]/, false)) {
|
|
|
|
|
var floatLiteral = false;
|
|
|
|
|
// Floats
|
|
|
|
|
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) { floatLiteral = true; }
|
|
|
|
|
if (stream.match(/^\d+\.\d*/)) { floatLiteral = true; }
|
|
|
|
|
if (stream.match(/^\.\d+/)) { floatLiteral = true; }
|
|
|
|
|
if (stream.match(/^\d*\.\d+(e[\+\-]?\d+)?/i)) {
|
|
|
|
|
floatLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
if (stream.match(/^\d+\.\d*/)) {
|
|
|
|
|
floatLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
if (stream.match(/^\.\d+/)) {
|
|
|
|
|
floatLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
if (floatLiteral) {
|
|
|
|
|
// Float literals may be "imaginary"
|
|
|
|
|
stream.eat(/J/i);
|
|
|
|
|
return 'number';
|
|
|
|
|
// Float literals may be "imaginary"
|
|
|
|
|
stream.eat(/J/i);
|
|
|
|
|
return 'number';
|
|
|
|
|
}
|
|
|
|
|
// Integers
|
|
|
|
|
var intLiteral = false;
|
|
|
|
|
// Hex
|
|
|
|
|
if (stream.match(/^0x[0-9a-f]+/i)) { intLiteral = true; }
|
|
|
|
|
if (stream.match(/^0x[0-9a-f]+/i)) {
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
// Binary
|
|
|
|
|
if (stream.match(/^0b[01]+/i)) { intLiteral = true; }
|
|
|
|
|
if (stream.match(/^0b[01]+/i)) {
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
// Octal
|
|
|
|
|
if (stream.match(/^0o[0-7]+/i)) { intLiteral = true; }
|
|
|
|
|
if (stream.match(/^0o[0-7]+/i)) {
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
// Decimal
|
|
|
|
|
if (stream.match(/^[1-9]\d*(e[\+\-]?\d+)?/)) {
|
|
|
|
|
// Decimal literals may be "imaginary"
|
|
|
|
@ -145,7 +379,9 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
intLiteral = true;
|
|
|
|
|
}
|
|
|
|
|
// 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) {
|
|
|
|
|
// Integer literals may be "long"
|
|
|
|
|
stream.eat(/L/i);
|
|
|
|
@ -159,18 +395,17 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
return state.tokenize(stream, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stream.match(operators))
|
|
|
|
|
return 'operator';
|
|
|
|
|
if (stream.match(operators)) return 'operator';
|
|
|
|
|
|
|
|
|
|
if (stream.match(keywords))
|
|
|
|
|
return 'keyword';
|
|
|
|
|
if (stream.match(keywords)) return 'keyword';
|
|
|
|
|
|
|
|
|
|
if (stream.match(builtins))
|
|
|
|
|
return 'builtin';
|
|
|
|
|
if (stream.match(builtins)) return 'builtin';
|
|
|
|
|
|
|
|
|
|
if (stream.match(identifiers)) {
|
|
|
|
|
if (state.lastToken != null &&
|
|
|
|
|
state.lastToken.match(/proc|iterator|macro|template|class|converter/)) {
|
|
|
|
|
if (
|
|
|
|
|
state.lastToken != null &&
|
|
|
|
|
state.lastToken.match(/proc|iterator|macro|template|class|converter/)
|
|
|
|
|
) {
|
|
|
|
|
return 'def';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -192,7 +427,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
if (stream.eat('\\')) {
|
|
|
|
|
stream.next();
|
|
|
|
|
if (singleline && stream.eol()) {
|
|
|
|
|
return OUTCLASS;
|
|
|
|
|
return OUTCLASS;
|
|
|
|
|
}
|
|
|
|
|
} else if (stream.match(delimiter)) {
|
|
|
|
|
state.tokenize = tokenBase;
|
|
|
|
@ -240,36 +475,36 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function dedent(stream, state, type) {
|
|
|
|
|
type = type || 'nim';
|
|
|
|
|
if (state.scopes.length == 1) return;
|
|
|
|
|
if (state.scopes[0].type === 'nim') {
|
|
|
|
|
var _indent = stream.indentation();
|
|
|
|
|
var _indent_index = -1;
|
|
|
|
|
for (var i = 0; i < state.scopes.length; ++i) {
|
|
|
|
|
if (_indent === state.scopes[i].offset) {
|
|
|
|
|
_indent_index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (_indent_index === -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
while (state.scopes[0].offset !== _indent) {
|
|
|
|
|
state.scopes.shift();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
type = type || 'nim';
|
|
|
|
|
if (state.scopes.length == 1) return;
|
|
|
|
|
if (state.scopes[0].type === 'nim') {
|
|
|
|
|
var _indent = stream.indentation();
|
|
|
|
|
var _indent_index = -1;
|
|
|
|
|
for (var i = 0; i < state.scopes.length; ++i) {
|
|
|
|
|
if (_indent === state.scopes[i].offset) {
|
|
|
|
|
_indent_index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (_indent_index === -1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
while (state.scopes[0].offset !== _indent) {
|
|
|
|
|
state.scopes.shift();
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
if (type === 'nim') {
|
|
|
|
|
state.scopes[0].offset = stream.indentation();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
if (type === 'nim') {
|
|
|
|
|
state.scopes[0].offset = stream.indentation();
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
if (state.scopes[0].type != type) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
state.scopes.shift();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (state.scopes[0].type != type) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
state.scopes.shift();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tokenLexer(stream, state) {
|
|
|
|
@ -288,25 +523,21 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
return style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((style === 'variable' || style === 'builtin')
|
|
|
|
|
&& state.lastStyle === 'meta') {
|
|
|
|
|
if ((style === 'variable' || style === 'builtin') && state.lastStyle === 'meta') {
|
|
|
|
|
style = 'meta';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle scope changes.
|
|
|
|
|
if (current.match(/return|break|continue|raise/) ||
|
|
|
|
|
(current === 'discard' && stream.eol()))
|
|
|
|
|
if (current.match(/return|break|continue|raise/) || (current === 'discard' && stream.eol()))
|
|
|
|
|
state.dedent += 1;
|
|
|
|
|
|
|
|
|
|
if (current === 'lambda' || current === 'proc')
|
|
|
|
|
state.lambda = true;
|
|
|
|
|
if (current === 'lambda' || current === 'proc') state.lambda = true;
|
|
|
|
|
|
|
|
|
|
var delimiter_index = '[({'.indexOf(current);
|
|
|
|
|
|
|
|
|
|
if (delimiter_index !== -1) {
|
|
|
|
|
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index+1));
|
|
|
|
|
}
|
|
|
|
|
else if(stream.eol() && current.match(/\=|\:|import|include|type|const|var|let/)) {
|
|
|
|
|
indent(stream, state, '])}'.slice(delimiter_index, delimiter_index + 1));
|
|
|
|
|
} else if (stream.eol() && current.match(/\=|\:|import|include|type|const|var|let/)) {
|
|
|
|
|
indent(stream, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -335,7 +566,7 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
startState: function(basecolumn) {
|
|
|
|
|
return {
|
|
|
|
|
tokenize: tokenBase,
|
|
|
|
|
scopes: [{offset:basecolumn || 0, type:'nim'}],
|
|
|
|
|
scopes: [{ offset: basecolumn || 0, type: 'nim' }],
|
|
|
|
|
lastStyle: null,
|
|
|
|
|
lastToken: null,
|
|
|
|
|
lambda: false,
|
|
|
|
@ -349,28 +580,24 @@ CodeMirror.defineMode("nimrod", function(conf, parserConf) {
|
|
|
|
|
state.lastStyle = style;
|
|
|
|
|
|
|
|
|
|
var current = stream.current();
|
|
|
|
|
if (current && style)
|
|
|
|
|
state.lastToken = current;
|
|
|
|
|
if (current && style) state.lastToken = current;
|
|
|
|
|
|
|
|
|
|
if (stream.eol() && state.lambda)
|
|
|
|
|
state.lambda = false;
|
|
|
|
|
if (stream.eol() && state.lambda) state.lambda = false;
|
|
|
|
|
|
|
|
|
|
return style;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
indent: function(state) {
|
|
|
|
|
if (state.tokenize != tokenBase)
|
|
|
|
|
return state.tokenize.isString ? CodeMirror.Pass : 0;
|
|
|
|
|
if (state.tokenize != tokenBase) return state.tokenize.isString ? CodeMirror.Pass : 0;
|
|
|
|
|
|
|
|
|
|
return state.scopes[0].offset;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
lineComment: "#",
|
|
|
|
|
fold: "indent"
|
|
|
|
|
lineComment: '#',
|
|
|
|
|
fold: 'indent'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return external;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CodeMirror.defineMIME("text/x-nimrod", "nimrod");
|
|
|
|
|
|
|
|
|
|
CodeMirror.defineMIME('text/x-nimrod', 'nimrod');
|
|
|
|
|