/* * JScript(ECMA-262 3rd Edition)の拡張子クラス * 参考: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoriJScript.asp?frame=true * http://www.ecma-international.org/publications/standards/Ecma-262.htm * http://www2u.biglobe.ne.jp/~oz-07ams/prog/ecma262r3/ */ function class_js() { this.name = 'jscript'; this.parent = 'srcfile'; this.ext = '\\.(js|javascript\\.txt)$'; /* this.keywords = new Array( 'break', 'case', 'catch', 'continue', 'default', 'delete', 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof', 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var', 'void', 'while', 'with' );*/ this.keywords = new Array( "XMLHttpRequest", "ActiveXObject", "abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double ", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in ", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super ", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with" ); this.futureKeywords = new Array( 'abstract', 'boolean', 'byte', 'char', 'class', 'const', 'debugger', 'double', 'enum', 'export', 'extends', 'final', 'float', 'goto', 'implements', 'import', 'int', 'interface', 'long', 'native', 'package', 'private', 'protected', 'public', 'short', 'static', 'super', 'synchronized', 'throws', 'transient', 'volatile' ); this.nativeObjs = new Array( 'Global', 'Object', 'Function', 'Array', 'String', 'Boolean', 'Number', 'Math', 'Date', 'RegExp', 'Error' ); this.htmlDoms = new Array( 'anchor', 'area', 'base', 'body', 'document', 'event', 'form', 'frame', 'frameset', 'history', 'iframe', 'image', 'input', 'link', 'location', 'meta', 'navigator', 'object', 'option', 'screen', 'select', 'table', 'tableData', 'tableHeader', 'tableRow', 'textarea', 'window', 'aLink', 'background', 'gbColor', 'id', 'link', 'scrollLeft', 'scrollTop', 'text', 'vLink', 'anchors', 'applets', 'childNodes', 'embeds', 'forms', 'images', 'links', 'stylesheets', 'body', 'cookie', 'documentElement', 'domain', 'lastModified', 'referrer', 'title', 'URL', 'close', 'createAttribute', 'createElement', 'createTextNode', 'focus', 'getElementById', 'getElementsByName', 'getElementsByTagName', 'open', 'write', 'writeln', 'onClick', 'onDblClick', 'onFocus', 'onKeyDown', 'onKeyPress', 'onKeyUp', 'onMouseDown', 'onMouseMove', 'onMouseOut', 'onMouseOver', 'onMouseUp', 'onResize' ); this.properties = new Array( 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'eval', 'Infinity', 'isFinite', 'isNaN', 'NaN', 'parseFloat', 'parseInt', 'undefined', 'escape', 'unescape' ); this.xmlWords = new Array('', 'name', 'specified', 'value', 'attributes', 'childNodes', 'firstChild', 'lastChild', 'namespaceURI', 'nextSibling', 'nodeName', 'nodeType', 'nodeValue', 'ownerDocument', 'parentNode', 'prefix', 'previousSibling', 'tagName', 'appendChild', 'cloneNode', 'getAttribute', 'getAttributeNode', 'getElementsByTagName', 'hasChildNodes', 'insertBefore', 'normalize', 'removeAttribute', 'removeAttributeNode', 'removeChild', 'replaceChild', 'setAttribute', 'setAttributeNode' ); this.arrayProp = new Array( 'index', 'input', 'length', 'concat', 'join', 'pop', 'push', 'reverse', 'shift', 'splice', 'sort', 'toSource', 'toString', 'unshift', 'valueOf', 'watch', 'unwatch' ); this.functionProp = new Array( 'arguments', 'arguments.callee', 'arguments.caller', 'arguments.length', 'arity', 'apply', 'call', 'toSource', 'toString', 'valueOf' ); this.objectProp = new Array( 'constructor', 'prototype', 'eval', 'toSource', 'toString', 'unwatch', 'watch', 'valueOf' ); this.stringProp = new Array( 'anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt', 'concat', 'fixed', 'fontcolor', 'fontsize', 'fromCharCode', 'indexOf', 'italics', 'lastIndexOf', 'length', 'link', 'match', 'replace', 'search', 'slice', 'small', 'split', 'strike', 'sub', 'substr', 'substring', 'sup', 'toLowerCase', 'toSource', 'toString', 'toUpperCase', 'watch', 'unwatch' ); } var f = class_js.prototype; f.onInitProp = function (arg, classname, methodname) { var lex = App.Lexes.Add(this.name); App.Prop(this.name, 'lex') = lex.name; var stylesOfState=['exstyle:デフォルト;','exstyle:リテラル-文字列 "~";','exstyle:コメント-複数行;'] for(var i=1;i<=7;i++){ lex.DefaultStyle( i ) = stylesOfState[0]+'exstyle:Level'+i; //default lex.DefaultStyle( i+8 ) = stylesOfState[1]+'exstyle:Level'+i; //リテラル-文字列 lex.DefaultStyle( i+16 ) = stylesOfState[2]+'exstyle:Level'+i; //コメント-複数行 } lex.DefaultStyle( 8 ) = stylesOfState[0]+'exstyle:Level8'; //default lex.DefaultStyle( 16 ) = stylesOfState[1]+'exstyle:Level8'; //リテラル-文字列 lex.Add( 'string-literal1', '1..8/"((\\\\.)|[^"\\\\]+|)*"/', 'exstyle:リテラル-文字列 "~";state:+8'); lex.Add( 'string-literal1', "1..8/'((\\\\.)|[^'\\\\]+)*'/", "exstyle:リテラル-文字列 '~';state:+8"); lex.Add( 'hexa-literal', '1..8/0x[0-9a-f]+/i', 'exstyle:リテラル-16進数値'); lex.Add( 'decimal-literal', '1..8/((0|[1-9][0-9]*)\\.([0-9]+)?(e[-+]?[0-9]+)?|\\.[0-9]+(e[-+]?[0-9]+)?|(0|[1-9][0-9]*)(e[-+]?[0-9]+)?)/i', 'exstyle:リテラル-10進数値'); lex.Add( 'other-literal', '1..8/\\<(null|true|false)\\>/', 'exstyle:リテラル-特殊'); lex.Add( 'i-comment', '1..7/\\/\\/.*$/', 'exstyle:コメント-単数行;exstyle:Level1;state:+23'); lex.Add( 'b-comment', '1..7/\\/\\*/', 'exstyle:コメント-複数行; state:+16'); // lex.DefaultStyle("7..12") = 'exstyle:コメント-複数行'; lex.Add( '', '17..23/\\*\\//', 'exstyle:コメント-複数行; state:-16'); lex.Add( 'regexp', '1..8/\\/([^\\/]|\\\\/)*\\/[gi]?[gi]?/', 'exstyle:リテラル-正規表現'); /* lex.AddKeywords( 'keyword', '1..8/' + this.keywords.join(' ') + '/', 'exstyle:キーワード'); lex.AddKeywords( 'future-keyword', '1..8/' + this.futureKeywords.join(' ') + '/', 'exstyle:キーワード-予約済み'); lex.AddKeywords( 'native-objects', '1..8/' + this.nativeObjs.join(' ') + '/', 'exstyle:組込済みオブジェクト');*/ lex.AddKeywords( 'keyword', '1..8/' + this.keywords.join(' ') + '/', 'exstyle:キーワード'); lex.AddKeywords( 'future-keyword','1..8/' + this.futureKeywords.join(' ') + '/','exstyle:キーワード-予約済み'); lex.AddKeywords( 'htmlDom', '1..8/' + this.htmlDoms.join(' ') + '/', 'exstyle:DOM'); lex.AddKeywords( 'XMLWord', '1..8/' + this.xmlWords.join(' ') + '/', 'exstyle:XMLキーワード'); lex.AddKeywords( 'native-objects', '1..8/' + this.nativeObjs.join(' ') + '/', 'exstyle:組込済みオブジェクト'); lex.AddKeywords( 'properties', '1..8/' + this.properties.join(' ') + '/', 'exstyle:デフォルトプロパティ'); lex.AddKeywords( 'Array', '1..8/' + this.arrayProp.join(' ') + '/', 'exstyle:キーワード-Array'); lex.AddKeywords( 'Object', '1..8/' + this.objectProp.join(' ') + '/', 'exstyle:キーワード-Object'); lex.AddKeywords( 'Function', '1..8/' + this.functionProp.join(' ') + '/', 'exstyle:キーワード-Function'); lex.AddKeywords( 'String', '1..8/' + this.stringProp.join(' ') + '/', 'exstyle:キーワード-String'); lex.Add( 'identifier', '1..8/[a-zA-Z_$][a-zA-Z0-9_]*/', 'exstyle:識別子'); lex.Add( 'open', '1..7/\\(/', 'font:bold;state:+1'); for(i=2;i<=8;i++){ lex.Add( 'close', i+'/\\)/', 'exstyle:Level'+(i-1)+';font:bold;state:-1'); } lex.Add( 'tohtml', '1/<\\/script/i', 'transit:*return*'); lex.Add( 'parens', '1..8/[][()<>{}]/', 'font:bold') lex.Add( '', '24..30/$/', 'state:-23'); lex.Add( 'stringEnd', '9..16/()/', 'state:-8'); addURIRule(lex, '9..30'); }; f.onMenuRequest = function (arg, classname, methodname) { invoke(arg, this.parent, methodname); function opentmplfunc() { App.View.LinkedBufferIndex = App.Buffers.Add(App.Path + 'macro\\template.javascript.txt').Index; } var m = arg('menuitem'); switch (arg('category1')) { case 'file': switch(arg('category2')) { case 'new': m.Add( 'テンプレートを開く(&T)', '', getFunctionBody(opentmplfunc)); break; } break; } }; f.onCompleteRequest = function (arg, classname, methodname) { App.CompletionList.Clear(); if (!getLeftParagraph().match(/\.([_a-zA-Z][_a-zA-Z0-9]*)?$/)) { App.CompletionList.Add( 'keyword', this.keywords.join('\n')); App.CompletionList.Add( 'std-object', this.nativeObjs.join('\n')); App.CompletionList.Add( 'properties', this.properties.join('\n')); } App.CompletionList.Add( 'html-word', this.htmlDoms.join('\n')); App.CompletionList.Add( 'XML-word', this.xmlWords.join('\n')); App.CompletionList.Add( 'Array-word', this.arrayProp.join('\n')); App.CompletionList.Add( 'Object-word', this.objectProp.join('\n')); App.CompletionList.Add( 'Function-word', this.functionProp.join('\n')); App.CompletionList.Add( 'String-word', this.stringProp.join('\n')); App.CompletionList.Add( 'identifier', getDynCompletionCandidates( /'([^']|\\')*'|"([^"]|\\")*"/g, /[_a-zA-Z][_a-zA-Z0-9]*/g).join('\n')); App.CompletionList.Popup( App.Prop(this.name, 'completion-case-sensitive')); }; f.onKeyPrintable = function (arg, classname, methodname) { invoke(arg, this.parent, methodname); if (!App.CompletionList.Active) { var needcompletion = false; var delaychars; if (arg.match(/[_a-zA-Z0-9]/) && (delaychars = App.Prop(classname, 'auto-completion-delay-count') - 0) >= 0 && getLeftParagraph().match(/([_a-zA-Z][_a-zA-Z0-9]*)$/) && RegExp.$1.length >= delaychars) { needcompletion = true; } else if (arg.match(/[.]/) && App.Prop(classname, 'member-completion-enabled')) { needcompletion = true; } if (needcompletion) { var ls = App.Caret.LexState(App.Caret.Col - 1); if ( ls.Name == this.name && ( (ls.State>=1) && (ls.State<=8) ) ) invoke(arg, classname, 'onCompleteRequest'); } } }; f.onKeySpace = function (arg, classname, methodname) { switch (arg & KEYMASK) { case KEYMASK_CTRL: invoke(arg, classname, 'onCompleteRequest'); break; default: invoke(arg, this.parent, methodname); break; } }; addClass(new class_js()); /* RegExpリテラルに対するルール追加 文字列リテラルのstateを統合 ネストレベルに応じた背景色分け追加。 lex:1..8 default lex:9..16:/**/ lex:17..23:// lex:24..30:"-" / '-' */