From: Jean Privat Date: Mon, 7 May 2018 23:57:31 +0000 (-0400) Subject: Merge: pnacl: remove target and related projects X-Git-Url: http://nitlanguage.org?hp=eb719a7ca33447b04f917198712f2a91a222a500 Merge: pnacl: remove target and related projects Since PNaCl is now deprecated for all targets, and since nobody use the platform or the contributed online_ide, we remove the packages from the repo. Signed-off-by: Lucas Bajolet Pull-Request: #2651 --- diff --git a/contrib/online_ide/.gitignore b/contrib/online_ide/.gitignore deleted file mode 100644 index 99a1b95..0000000 --- a/contrib/online_ide/.gitignore +++ /dev/null @@ -1 +0,0 @@ -pnacl_nit.pexe diff --git a/contrib/online_ide/Makefile b/contrib/online_ide/Makefile deleted file mode 100644 index efc07ba..0000000 --- a/contrib/online_ide/Makefile +++ /dev/null @@ -1,20 +0,0 @@ - -ACE_BUILDS ?= ../../../ace-builds/ - -default: - nitc --semi-global sources/nit/pnacl_nit.nit - cp pnacl_nit/pnacl_nit.pexe www/pnacl/ -f - rm -rf pnacl_nit/ - -build-www: - rm -rf www/src - cp -r $(ACE_BUILDS)/src www/ - cp setup/mode-nit.js www/src/ - cp setup/nit.js www/src/snippets/ - -HTTPD_PY := python $(NACL_SDK_ROOT)/tools/httpd.py -serve: - cd www/; \ - $(HTTPD_PY) -C . --no-dir-check - -.PHONY: serve diff --git a/contrib/online_ide/README.md b/contrib/online_ide/README.md deleted file mode 100644 index 5294e6e..0000000 --- a/contrib/online_ide/README.md +++ /dev/null @@ -1,61 +0,0 @@ -This file contains all the informations about the Nit online IDE. - -I. SETUP - -0.a. Install the native client SDK if needed(https://developer.chrome.com/native-client/sdk/download). - -0.b. Declare the environment variable NACL_SDK_ROOT as the root of the target platform within the SDK (ex: ~/nacl_sdk/pepper_34/) : - $ export NACL_SDK_ROOT=/path/to/nacl_sdk/pepper_[your_version] - -1. Run the Makefile with 'make' (this will compile the pnacl module for the interpreter and place it in the right folder). - -2. Search for the Ace sources, go to 'https://github.com/ajaxorg/ace-builds/' and get the 'src' folder, -put it in 'www/'. - -NOTE: The application has been developped with a package from 03.02.2014, -in case of any problem, you can find it here : -'https://github.com/Djomanix/ace-build-for-nit'. --> If you get this one, you can skip 3. and 4. - -3. Copy 'mode-nit.js' from folder 'setup' to folder 'www/src'. - -4. Copy 'nit.js' from folder 'setup' to folder 'www/src/snippets'. - - -II. GETTING STARTED - -1. Run 'make serve', this will host the application on 'http://localhost:5103/'. - -NOTE: -1. The application only works in Google Chrome or Chromium. -2. It is recommended to open the Chrome console while using the application -(to see what's going on). -3. The application is ready when the terminal appears in the page -and when the message : -'Nit library loaded (... files), ready to go.' is displayed in the Chrome console. -4. Loading may take some time when the browser loads a pnacl module for the first time. - - -III. FEATURES - - CTRL+E: this shortcut launches the interpretation of the code written in the editor. - - CTRL+S: this shortcut enables you to download the file you have been writting. - - By clicking on the file name you can change it. - - The editor has some auto-completion and research features. - - -IV. HOW TO EDIT - -1. The folder 'sources/nit' contains the file 'pnacl_nit.nit' which is the source -of the pnacl module. You can edit the module directly here, and run 'make' to compile it (it will be placed automatically where needed). - -2. The folder 'sources/nit_mode_for_ace' contains the source files necessary to -generate the Ace mode for Nit. -You can also edit them if you need to improve the Nit support, see : -- 'http://ace.c9.io/#nav=higlighter' - - -V. HOSTING - -1. To host the application, just copy the 'www' folder where you want. - -NOTE: The application has been successfully tested on a python server and an apache server. diff --git a/contrib/online_ide/package.ini b/contrib/online_ide/package.ini deleted file mode 100644 index 841f552..0000000 --- a/contrib/online_ide/package.ini +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name=online_ide -tags=devel,web -maintainer=Johan Kayser -license=Apache-2.0 -[upstream] -browse=https://github.com/nitlang/nit/tree/master/contrib/online_ide/ -git=https://github.com/nitlang/nit.git -git.directory=contrib/online_ide/ -homepage=http://nitlanguage.org -issues=https://github.com/nitlang/nit/issues -tryit=http://nitlanguage.org/online_ide/ diff --git a/contrib/online_ide/setup/mode-nit.js b/contrib/online_ide/setup/mode-nit.js deleted file mode 100644 index f9cb1ab..0000000 --- a/contrib/online_ide/setup/mode-nit.js +++ /dev/null @@ -1,554 +0,0 @@ -define('ace/mode/nit', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/matching_brace_outdent', 'ace/mode/behaviour/cstyle', 'ace/mode/nit_highlight_rules'], function(require, exports, module) { - - -var oop = require("../lib/oop"); -var TextMode = require("./text").Mode; -var Tokenizer = require("../tokenizer").Tokenizer; -var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; -var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; -var NitHighlightRules = require("./nit_highlight_rules").NitHighlightRules; - -var Mode = function() { - this.HighlightRules = NitHighlightRules; - this.$outdent = new MatchingBraceOutdent(); - this.$behaviour = new CstyleBehaviour(); -}; -oop.inherits(Mode, TextMode); - -(function() { - this.lineCommentStart = "#"; - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - - var tokenizedLine = this.getTokenizer().getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "start") { - var match = line.match(/(^class| class | if | else | else|do$)/); - if (match) { - indent += tab + tab; - } - } - return indent; - }; - this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); - }; - this.autoOutdent = function(state, doc, row) { - this.$outdent.autoOutdent(doc, row); - }; - this.createWorker = function(session) { - return null; - }; - - this.$id = "ace/mode/nit"; -}).call(Mode.prototype); - -exports.Mode = Mode; -}); - -define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) { - - -var Range = require("../range").Range; - -var MatchingBraceOutdent = function() {}; - -(function() { - - this.checkOutdent = function(line, input) { - if (! /^\s+$/.test(line)) - return false; - - return /^\s*\}/.test(input); - }; - - this.autoOutdent = function(doc, row) { - var line = doc.getLine(row); - var match = line.match(/^(\s*\})/); - - if (!match) return 0; - - var column = match[1].length; - var openBracePos = doc.findMatchingBracket({row: row, column: column}); - - if (!openBracePos || openBracePos.row == row) return 0; - - var indent = this.$getIndent(doc.getLine(openBracePos.row)); - doc.replace(new Range(row, 0, row, column-1), indent); - }; - - this.$getIndent = function(line) { - return line.match(/^\s*/)[0]; - }; - -}).call(MatchingBraceOutdent.prototype); - -exports.MatchingBraceOutdent = MatchingBraceOutdent; -}); - -define('ace/mode/behaviour/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator', 'ace/lib/lang'], function(require, exports, module) { - - -var oop = require("../../lib/oop"); -var Behaviour = require("../behaviour").Behaviour; -var TokenIterator = require("../../token_iterator").TokenIterator; -var lang = require("../../lib/lang"); - -var SAFE_INSERT_IN_TOKENS = - ["text", "paren.rparen", "punctuation.operator"]; -var SAFE_INSERT_BEFORE_TOKENS = - ["text", "paren.rparen", "punctuation.operator", "comment"]; - - -var autoInsertedBrackets = 0; -var autoInsertedRow = -1; -var autoInsertedLineEnd = ""; -var maybeInsertedBrackets = 0; -var maybeInsertedRow = -1; -var maybeInsertedLineStart = ""; -var maybeInsertedLineEnd = ""; - -var CstyleBehaviour = function () { - - CstyleBehaviour.isSaneInsertion = function(editor, session) { - var cursor = editor.getCursorPosition(); - var iterator = new TokenIterator(session, cursor.row, cursor.column); - if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) { - var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1); - if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) - return false; - } - iterator.stepForward(); - return iterator.getCurrentTokenRow() !== cursor.row || - this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS); - }; - - CstyleBehaviour.$matchTokenType = function(token, types) { - return types.indexOf(token.type || token) > -1; - }; - - CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - if (!this.isAutoInsertedClosing(cursor, line, autoInsertedLineEnd[0])) - autoInsertedBrackets = 0; - autoInsertedRow = cursor.row; - autoInsertedLineEnd = bracket + line.substr(cursor.column); - autoInsertedBrackets++; - }; - - CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - if (!this.isMaybeInsertedClosing(cursor, line)) - maybeInsertedBrackets = 0; - maybeInsertedRow = cursor.row; - maybeInsertedLineStart = line.substr(0, cursor.column) + bracket; - maybeInsertedLineEnd = line.substr(cursor.column); - maybeInsertedBrackets++; - }; - - CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) { - return autoInsertedBrackets > 0 && - cursor.row === autoInsertedRow && - bracket === autoInsertedLineEnd[0] && - line.substr(cursor.column) === autoInsertedLineEnd; - }; - - CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) { - return maybeInsertedBrackets > 0 && - cursor.row === maybeInsertedRow && - line.substr(cursor.column) === maybeInsertedLineEnd && - line.substr(0, cursor.column) == maybeInsertedLineStart; - }; - - CstyleBehaviour.popAutoInsertedClosing = function() { - autoInsertedLineEnd = autoInsertedLineEnd.substr(1); - autoInsertedBrackets--; - }; - - CstyleBehaviour.clearMaybeInsertedClosing = function() { - maybeInsertedBrackets = 0; - maybeInsertedRow = -1; - }; - - this.add("braces", "insertion", function (state, action, editor, session, text) { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - if (text == '{') { - var selection = editor.getSelectionRange(); - var selected = session.doc.getTextRange(selection); - if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) { - return { - text: '{' + selected + '}', - selection: false - }; - } else if (CstyleBehaviour.isSaneInsertion(editor, session)) { - if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) { - CstyleBehaviour.recordAutoInsert(editor, session, "}"); - return { - text: '{}', - selection: [1, 1] - }; - } else { - CstyleBehaviour.recordMaybeInsert(editor, session, "{"); - return { - text: '{', - selection: [1, 1] - }; - } - } - } else if (text == '}') { - var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == '}') { - var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row}); - if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { - CstyleBehaviour.popAutoInsertedClosing(); - return { - text: '', - selection: [1, 1] - }; - } - } - } else if (text == "\n" || text == "\r\n") { - var closing = ""; - if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) { - closing = lang.stringRepeat("}", maybeInsertedBrackets); - CstyleBehaviour.clearMaybeInsertedClosing(); - } - var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar === '}') { - var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}'); - if (!openBracePos) - return null; - var next_indent = this.$getIndent(session.getLine(openBracePos.row)); - } else if (closing) { - var next_indent = this.$getIndent(line); - } else { - return; - } - var indent = next_indent + session.getTabString(); - - return { - text: '\n' + indent + '\n' + next_indent + closing, - selection: [1, indent.length, 1, indent.length] - }; - } else { - CstyleBehaviour.clearMaybeInsertedClosing(); - } - }); - - this.add("braces", "deletion", function (state, action, editor, session, range) { - var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '{') { - var line = session.doc.getLine(range.start.row); - var rightChar = line.substring(range.end.column, range.end.column + 1); - if (rightChar == '}') { - range.end.column++; - return range; - } else { - maybeInsertedBrackets--; - } - } - }); - - this.add("parens", "insertion", function (state, action, editor, session, text) { - if (text == '(') { - var selection = editor.getSelectionRange(); - var selected = session.doc.getTextRange(selection); - if (selected !== "" && editor.getWrapBehavioursEnabled()) { - return { - text: '(' + selected + ')', - selection: false - }; - } else if (CstyleBehaviour.isSaneInsertion(editor, session)) { - CstyleBehaviour.recordAutoInsert(editor, session, ")"); - return { - text: '()', - selection: [1, 1] - }; - } - } else if (text == ')') { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == ')') { - var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row}); - if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { - CstyleBehaviour.popAutoInsertedClosing(); - return { - text: '', - selection: [1, 1] - }; - } - } - } - }); - - this.add("parens", "deletion", function (state, action, editor, session, range) { - var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '(') { - var line = session.doc.getLine(range.start.row); - var rightChar = line.substring(range.start.column + 1, range.start.column + 2); - if (rightChar == ')') { - range.end.column++; - return range; - } - } - }); - - this.add("brackets", "insertion", function (state, action, editor, session, text) { - if (text == '[') { - var selection = editor.getSelectionRange(); - var selected = session.doc.getTextRange(selection); - if (selected !== "" && editor.getWrapBehavioursEnabled()) { - return { - text: '[' + selected + ']', - selection: false - }; - } else if (CstyleBehaviour.isSaneInsertion(editor, session)) { - CstyleBehaviour.recordAutoInsert(editor, session, "]"); - return { - text: '[]', - selection: [1, 1] - }; - } - } else if (text == ']') { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == ']') { - var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row}); - if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) { - CstyleBehaviour.popAutoInsertedClosing(); - return { - text: '', - selection: [1, 1] - }; - } - } - } - }); - - this.add("brackets", "deletion", function (state, action, editor, session, range) { - var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && selected == '[') { - var line = session.doc.getLine(range.start.row); - var rightChar = line.substring(range.start.column + 1, range.start.column + 2); - if (rightChar == ']') { - range.end.column++; - return range; - } - } - }); - - this.add("string_dquotes", "insertion", function (state, action, editor, session, text) { - if (text == '"' || text == "'") { - var quote = text; - var selection = editor.getSelectionRange(); - var selected = session.doc.getTextRange(selection); - if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) { - return { - text: quote + selected + quote, - selection: false - }; - } else { - var cursor = editor.getCursorPosition(); - var line = session.doc.getLine(cursor.row); - var leftChar = line.substring(cursor.column-1, cursor.column); - if (leftChar == '\\') { - return null; - } - var tokens = session.getTokens(selection.start.row); - var col = 0, token; - var quotepos = -1; // Track whether we're inside an open quote. - - for (var x = 0; x < tokens.length; x++) { - token = tokens[x]; - if (token.type == "string") { - quotepos = -1; - } else if (quotepos < 0) { - quotepos = token.value.indexOf(quote); - } - if ((token.value.length + col) > selection.start.column) { - break; - } - col += tokens[x].value.length; - } - if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) { - if (!CstyleBehaviour.isSaneInsertion(editor, session)) - return; - return { - text: quote + quote, - selection: [1,1] - }; - } else if (token && token.type === "string") { - var rightChar = line.substring(cursor.column, cursor.column + 1); - if (rightChar == quote) { - return { - text: '', - selection: [1, 1] - }; - } - } - } - } - }); - - this.add("string_dquotes", "deletion", function (state, action, editor, session, range) { - var selected = session.doc.getTextRange(range); - if (!range.isMultiLine() && (selected == '"' || selected == "'")) { - var line = session.doc.getLine(range.start.row); - var rightChar = line.substring(range.start.column + 1, range.start.column + 2); - if (rightChar == selected) { - range.end.column++; - return range; - } - } - }); - -}; - -oop.inherits(CstyleBehaviour, Behaviour); - -exports.CstyleBehaviour = CstyleBehaviour; -}); -define('ace/mode/nit_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/doc_comment_highlight_rules', 'ace/mode/text_highlight_rules'], function(require, exports, module) { - - -var oop = require("../lib/oop"); -var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; -var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; - -var NitHighlightRules = function() { - - var keywords = ( - "package|module|import|class|abstract|interface|universal|enum|end|fun|" + - "type|init|redef|is|do|readable|writable|var|intern|extern|protected|private|" + - "intrude|if|then|else|while|loop|for|in|and|or|not|implies|return|continue|" + - "break|abort|assert|new|isa|once|super|self|true|false|null|as|nullable|isset|label|__debug__" - ); - - var keywordMapper = this.createKeywordMapper({ - "keyword": keywords, - "variable.language": "self", - "constant.language": "null|true|false" - }, "identifier"); - this.$rules = { - "start" : [ - { - token : "comment", - regex : "#.*$" - }, - { - token : "support.class", - regex : /[A-Z]{1}[a-z]+/ - }, - DocCommentHighlightRules.getStartRule("doc-start"), - { - token : "string.regexp", - regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" - }, { - token : "string", // character - regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/ - }, { - token : "string", start : '"', end : '"|$', next: [ - {token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/}, - {token: "invalid", regex: /\\./} - ] - }, { - token : "string", start : '@"', end : '"', next:[ - {token: "constant.language.escape", regex: '""'} - ] - }, { - token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" - }, { - token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : "constant.language.boolean", - regex : "(?:true|false)\\b" - }, { - token : keywordMapper, - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - }, { - token : "keyword.operator", - regex : "@|!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\::|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" - }, { - token : "keyword", - regex : "^\\s*#(if|else|elif|endif|define|undef|warning|error|line|region|endregion|pragma)" - }, { - token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\." - }, { - token : "paren.lparen", - regex : "[[({]" - }, { - token : "paren.rparen", - regex : "[\\])}]" - }, { - token : "text", - regex : "\\s+" - } - ] - }; - this.embedRules(DocCommentHighlightRules, "doc-", - [ DocCommentHighlightRules.getEndRule("start") ]); - this.normalizeRules(); -}; - -oop.inherits(NitHighlightRules, TextHighlightRules); - -exports.NitHighlightRules = NitHighlightRules; - -}); - -define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) { - - -var oop = require("../lib/oop"); -var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; - -var DocCommentHighlightRules = function() { - - this.$rules = { - "start" : [ { - token : "comment.doc.tag", - regex : "@[\\w\\d_]+" // TODO: fix email addresses - }, { - token : "comment.doc.tag", - regex : "\\bTODO\\b" - }, { - defaultToken : "comment.doc" - }] - }; -}; - -oop.inherits(DocCommentHighlightRules, TextHighlightRules); - -DocCommentHighlightRules.getStartRule = function(start) { - return { - token : "comment.doc", // doc comment - regex : "\\/\\*(?=\\*)", - next : start - }; -}; - -DocCommentHighlightRules.getEndRule = function (start) { - return { - token : "comment.doc", // closing comment - regex : "\\*\\/", - next : start - }; -}; - - -exports.DocCommentHighlightRules = DocCommentHighlightRules; - -}); diff --git a/contrib/online_ide/setup/nit.js b/contrib/online_ide/setup/nit.js deleted file mode 100644 index ee8952b..0000000 --- a/contrib/online_ide/setup/nit.js +++ /dev/null @@ -1,7 +0,0 @@ -define('ace/snippets/nit', ['require', 'exports', 'module' ], function(require, exports, module) { - - -exports.snippetText = ""; -exports.scope = "nit"; - -}); diff --git a/contrib/online_ide/sources/nit/pnacl_nit.nit b/contrib/online_ide/sources/nit/pnacl_nit.nit deleted file mode 100644 index 4062c78..0000000 --- a/contrib/online_ide/sources/nit/pnacl_nit.nit +++ /dev/null @@ -1,193 +0,0 @@ -# This file is part of NIT ( http://www.nitlanguage.org ). -# -# Copyright 2014 Johan Kayser -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# A version of the naive Nit interpreter for PNaCl. -module pnacl_nit - -import nitc::naive_interpreter -import pnacl -intrude import nitc::toolcontext -intrude import nitc::loader -intrude import core::file - -# We redefine exit to start a new thread before killing the one that called exit. -redef fun exit(exit_value: Int) -do - var dictionary = new PepperDictionary - dictionary["exit"] = exit_value - dictionary["exit_thread"] = "A new thread has been made available for Nit." - create_thread - app.post_dictionary dictionary - exit_thread exit_value -end - -#hack realpath. -redef class String - redef fun realpath do return self - - # file_exists looks in the 'files' HashMap. - redef fun file_exists: Bool - do - if sys.files.has_key(self) then return true - return false - end -end - -redef class Sys - # We add two HashMap for temporary file storage. - # 'lib' stores the lib files. - var lib = new HashMap[String, String] - # 'files' stores the "file(s)" you want to interpret + the lib files. - var files = new HashMap[String, String] -end - -redef class ToolContext - # We don't need 'the locate_nit_dir'. - redef fun locate_nit_dir - do - return "/pnacl" - end -end - -# We have to redef some FileReader methods because we don't use NativeFiles anymore. -redef class FileReader - - # Looks in the 'files' HashMap. - redef init open(path: String) - do - self.path = path - var file = sys.files[path] - prepare_buffer(file.length) - path.copy_to_native(_buffer, file.length, 0, 0) - end - - redef fun close - do - end_reached = true - end - - redef fun fill_buffer - do - buffer_reset - end_reached = true - end - - redef fun reopen - do - _buffer_pos = 0 - end -end - -redef class ModelBuilder - # We don't use paths as the interpreter, so just return the argument. - redef fun module_absolute_path(path: String): String do return path - - # We don't use paths as the interpreter, so we don't use location or lookpaths args (see the default implementation). - redef fun search_module_in_paths(location: nullable Location, name: String, lookpaths: Collection[String]): nullable MModule - do - var candidate: nullable String = null - var try_file = "{name}.nit" - if try_file.file_exists then - if candidate == null then - candidate = try_file - else if candidate != try_file then - # try to disambiguate conflicting modules - var abs_candidate = module_absolute_path(candidate) - var abs_try_file = module_absolute_path(try_file) - if abs_candidate != abs_try_file then - toolcontext.error(location, "Error: conflicting module file for {name}: {candidate} {try_file}") - end - end - end - if candidate == null then return null - return identify_module(candidate) - end -end - -class Pnacl_nit - super PnaclApp - - # In handle_dictionary we search for the 'operation' key in dictionaries, - # 'load' means that we are loading the Nit library, - # 'interpret' launches the interpreter code. - redef fun handle_dictionary(dictionary: PepperDictionary) - do - var d = dictionary.copy - var operation = d["operation"] - - # If operation = 'intepret' we want to interpret some Nit code, so we execute the same code as in nit.nit. - if operation == "interpret" then - var args = d["args"].to_s.split(' ') - # Create a tool context to handle options and paths - var toolcontext = new ToolContext - toolcontext.tooldescription = "Usage: nit [OPTION]... ...\nInterprets and debbugs Nit programs." - # Add an option "-o" to enable compatibilit with the tests.sh script - var opt = new OptionString("compatibility (does noting)", "-o") - toolcontext.option_context.add_option(opt) - var opt_mixins = new OptionArray("Additionals module to min-in", "-m") - toolcontext.option_context.add_option(opt_mixins) - # We do not add other options, so process them now! - toolcontext.process_options(args) - - # We need a model to collect stufs - var model = new Model - # An a model builder to parse files - var modelbuilder = new ModelBuilder(model, toolcontext) - - var arguments = toolcontext.option_context.rest - var progname = arguments.first - sys.files[progname] = d["content"].to_s - - # Here we load an process all modules passed on the command line - var mmodules = modelbuilder.parse([progname]) - mmodules.add_all modelbuilder.parse(opt_mixins.value) - modelbuilder.run_phases - - if toolcontext.opt_only_metamodel.value then exit(0) - - var mainmodule: nullable MModule - - # Here we launch the interpreter on the main module - if mmodules.length == 1 then - mainmodule = mmodules.first - else - mainmodule = new MModule(model, null, mmodules.first.name, mmodules.first.location) - mainmodule.set_imported_mmodules(mmodules) - end - - var self_mm = mainmodule - var self_args = arguments - - modelbuilder.run_naive_interpreter(self_mm, self_args) - # If operation = 'load', we are loading lib files, so we store them into HashMaps and send a response to JS. - else if operation == "load" then - var filename = d["filename"] - var content = d["content"] - if filename isa String and content isa String then - sys.lib[filename] = content - sys.files[filename] = content - end - var response = new PepperDictionary - response["operation"] = "load_response" - response["files_number"] = sys.lib.length.to_s - post_dictionary response - end - end -end - -redef fun app do return once new Pnacl_nit -app.initialize # Needed to correctly set up Nit control over the Pepper API. -app.run # Wait for dictionaries. diff --git a/contrib/online_ide/sources/nit_mode_for_ace/lib_ace_mode/nit.js b/contrib/online_ide/sources/nit_mode_for_ace/lib_ace_mode/nit.js deleted file mode 100644 index fb1e3dc..0000000 --- a/contrib/online_ide/sources/nit_mode_for_ace/lib_ace_mode/nit.js +++ /dev/null @@ -1,72 +0,0 @@ -define(function(require, exports, module) { -"use strict"; - -var oop = require("../lib/oop"); -// defines the parent mode -var TextMode = require("./text").Mode; -var Tokenizer = require("../tokenizer").Tokenizer; -var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; -var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour; - -// defines the language specific highlighters and folding rules -var NitHighlightRules = require("./nit_highlight_rules").NitHighlightRules; -//var NitFoldMode = require("./folding/nit").NitFoldMode; - -var Mode = function() { - // set everything up - this.HighlightRules = NitHighlightRules; - this.$outdent = new MatchingBraceOutdent(); - this.$behaviour = new CstyleBehaviour(); - //this.foldingRules = new NitFoldMode(); -}; -oop.inherits(Mode, TextMode); - -(function() { - // configure comment start/end characters - this.lineCommentStart = "#"; - //this.blockComment = {start: "/*", end: "*/"}; - - // special logic for indent/outdent. - // By default ace keeps indentation of previous line - this.getNextLineIndent = function(state, line, tab) { - var indent = this.$getIndent(line); - - var tokenizedLine = this.getTokenizer().getLineTokens(line, state); - var tokens = tokenizedLine.tokens; - - if (tokens.length && tokens[tokens.length-1].type == "comment") { - return indent; - } - - if (state == "start") { - //var match = line.match(/^.*[\{\(\[]\s*$/); - var match = line.match(/(^class| class | if | else | else|do$)/); - if (match) { - indent += tab + tab; - } - } - return indent; - }; - this.checkOutdent = function(state, line, input) { - return this.$outdent.checkOutdent(line, input); - }; - this.autoOutdent = function(state, doc, row) { - this.$outdent.autoOutdent(doc, row); - }; - - // create worker for live syntax checking - this.createWorker = function(session) { - /*var worker = new WorkerClient(["ace"], "ace/mode/nit_worker", "NitWorker"); - worker.attachToDocument(session.getDocument()); - worker.on("errors", function(e) { - session.setAnnotations(e.data); - }); - return worker;*/ - return null; - }; - - this.$id = "ace/mode/nit"; -}).call(Mode.prototype); - -exports.Mode = Mode; -}); diff --git a/contrib/online_ide/sources/nit_mode_for_ace/lib_ace_mode/nit_highlight_rules.js b/contrib/online_ide/sources/nit_mode_for_ace/lib_ace_mode/nit_highlight_rules.js deleted file mode 100644 index 32d9a04..0000000 --- a/contrib/online_ide/sources/nit_mode_for_ace/lib_ace_mode/nit_highlight_rules.js +++ /dev/null @@ -1,93 +0,0 @@ -define(function(require, exports, module) { -"use strict"; - -var oop = require("../lib/oop"); -var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; -var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; - -var NitHighlightRules = function() { - - var keywords = ( - "package|module|import|class|abstract|interface|universal|enum|end|fun|" + - "type|init|redef|is|do|readable|writable|var|intern|extern|protected|private|" + - "intrude|if|then|else|while|loop|for|in|and|or|not|implies|return|continue|" + - "break|abort|assert|new|isa|once|super|self|true|false|null|as|nullable|isset|label|__debug__" - ); - - var keywordMapper = this.createKeywordMapper({ - "keyword": keywords, - "variable.language": "self", - "constant.language": "null|true|false" - }, "identifier"); - - // regexp must not have capturing parentheses. Use (?:) instead. - // regexps are ordered -> the first match is used - this.$rules = { - "start" : [ - { - token : "comment", - regex : "#.*$" - }, - { - token : "support.class", - regex : /[A-Z]{1}[a-z]+/ - }, - DocCommentHighlightRules.getStartRule("doc-start"), - { - token : "string.regexp", - regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)" - }, { - token : "string", // character - regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/ - }, { - token : "string", start : '"', end : '"|$', next: [ - {token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/}, - {token: "invalid", regex: /\\./} - ] - }, { - token : "string", start : '@"', end : '"', next:[ - {token: "constant.language.escape", regex: '""'} - ] - }, { - token : "constant.numeric", // hex - regex : "0[xX][0-9a-fA-F]+\\b" - }, { - token : "constant.numeric", // float - regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" - }, { - token : "constant.language.boolean", - regex : "(?:true|false)\\b" - }, { - token : keywordMapper, - regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - }, { - token : "keyword.operator", - regex : "@|!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\::|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)" - }, { - token : "keyword", - regex : "^\\s*#(if|else|elif|endif|define|undef|warning|error|line|region|endregion|pragma)" - }, { - token : "punctuation.operator", - regex : "\\?|\\:|\\,|\\;|\\." - }, { - token : "paren.lparen", - regex : "[[({]" - }, { - token : "paren.rparen", - regex : "[\\])}]" - }, { - token : "text", - regex : "\\s+" - } - ] - }; - this.embedRules(DocCommentHighlightRules, "doc-", - [ DocCommentHighlightRules.getEndRule("start") ]); - this.normalizeRules(); -}; - -oop.inherits(NitHighlightRules, TextHighlightRules); - -exports.NitHighlightRules = NitHighlightRules; - -}); diff --git a/contrib/online_ide/www/css/jquery.terminal.css b/contrib/online_ide/www/css/jquery.terminal.css deleted file mode 100644 index 6db2df5..0000000 --- a/contrib/online_ide/www/css/jquery.terminal.css +++ /dev/null @@ -1,189 +0,0 @@ -/* - * __ _____ ________ __ - * / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / / - * __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / - * / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ - * \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ - * \/ /____/ - * http://terminal.jcubic.pl - * - * Copyright (c) 2011-2014 Jakub Jankiewicz - * - * This file is part of jQuery Terminal. - * - * jQuery Terminal is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * jQuery Terminal is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Foobar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ -.terminal .terminal-output .format, .cmd .format, -.cmd .prompt, .cmd .prompt div, .terminal .terminal-output div div{ - display: inline-block; -} -.cmd .clipboard { - position: absolute; - bottom: 0; - left: 0; - /*clip: rect(0,0,0,0);*/ - /* - opacity: 0.01; - filter: alpha(opacity = 0.01); - filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.01); - */ - width: 5px; - /* - outline: none; - border: none; - background-color: black; - */ -} -/* -.cmd > .clipboard { - position: fixed; -} -*/ -.cmd input { - height: 1.3em; - width: 0.5em; - padding: 0; - border: none; -} -.terminal { - padding: 10px; - position: relative; - overflow: hidden; -} -.cmd { - padding: 0; - margin: 0; - height: 1.3em; - /*margin-top: 3px; */ -} -.cmd .cursor.blink { - -webkit-animation: blink 1s infinite steps(1, start); - -moz-animation: blink 1s infinite steps(1, start); - -ms-animation: blink 1s infinite steps(1, start); - animation: blink 1s infinite steps(1, start); -} -@keyframes blink { - 0%, 100% { - background-color: #000; - color: #aaa; - } - 50% { - background-color: #bbb; /* not #aaa because it's seem there is Google Chrome bug */ - color: #000; - } -} -@-webkit-keyframes blink { - 0%, 100% { - background-color: #000; - color: #aaa; - } - 50% { - background-color: #bbb; - color: #000; - } -} -@-ms-keyframes blink { - 0%, 100% { - background-color: #000; - color: #aaa; - } - 50% { - background-color: #bbb; - color: #000; - } -} -@-moz-keyframes blink { - 0%, 100% { - background-color: #000; - color: #aaa; - } - 50% { - background-color: #bbb; - color: #000; - } -} -.terminal .terminal-output div div, .cmd .prompt { - display: block; - line-height: 14px; - height: auto; -} -.cmd .prompt { - float: left; -} -.terminal, .cmd { - font-family: FreeMono, monospace; - color: white; - background-color: #000; - font-size: 12px; - line-height: 14px; -} -/* Android hack */ -@media screen and (max-device-width: 480px) { - .terminal, .cmd { - font-family: monospace; - } -} -.terminal-output > div { - /*padding-top: 3px;*/ - min-height: 14px; -} -.terminal .terminal-output div span { - display: inline-block; -} -.cmd span { - float: left; - /*display: inline-block; */ -} -.terminal .inverted, .cmd .inverted, .cmd .cursor.blink { - background-color: #aaa; - color: #000; -} -.terminal .terminal-output div div::-moz-selection, -.terminal .terminal-output div span::-moz-selection, -.terminal .terminal-output div div a::-moz-selection { - background-color: #aaa; - color: #000; -} -.terminal .terminal-output div div::selection, -.terminal .terminal-output div div a::selection, -.terminal .terminal-output div span::selection, -.cmd > span::selection, -.cmd .prompt span::selection { - background-color: #aaa; - color: #000; -} -.terminal .terminal-output div.error, .terminal .terminal-output div.error div { - color: red; -} -.tilda { - position: fixed; - top: 0; - left: 0; - width: 100%; - z-index: 1100; -} -.clear { - clear: both; -} -.terminal a { - color: #0F60FF; -} -.terminal a:hover { - color: red; -} -textarea.clipboard { - visibility: hidden; -} diff --git a/contrib/online_ide/www/css/style.css b/contrib/online_ide/www/css/style.css deleted file mode 100644 index 0716f53..0000000 --- a/contrib/online_ide/www/css/style.css +++ /dev/null @@ -1,73 +0,0 @@ -body { - margin: 0; - margin-top: 0px; - padding: 0; - background-color: #f8f8f8; - font-size: 14px; - font-family: "Helvetica Neue", Helvetica, Tahoma, sans-serif; -} -#pageheader { - position: relative; - background-color: #292929; - color: #6c6c6c; - overflow: hidden; -} -#pageheader_title { - position: relative; - width: 125px; - height: 19px; - background-color: #f8f8f8; - padding: 2px; - text-align: center; - float: left; -} -#pageheader_title h1 { - margin: 0; - font-size: 14px; -} -#pageheader_title h1 span { - color:#0D8921; -} -#navigation { - margin: 0 ; - padding: 0 ; - list-style: none ; -} -#navigation li { - display: inline; - float: left ; - width: 125px; - height: 19px; - padding: 2px; - background-color: #f8f8f8; - color: #0D8921; - font-size: 12px; - text-align: center; - border: 1px #0D8921; - border-style: none none none dashed; -} -#navigation li button{ - margin-top: -1px; -} -#filename { - color:#6c6c6c; -} -#editor { - position: relative; - left: 0; - width: 100%; - height: 460px; -} -#terminal -{ - position: relative; - left: 0; - width: 100%; - height: 230px; - overflow: auto; - padding: 0; -} -#listener -{ - height: 0; -} diff --git a/contrib/online_ide/www/favicon.ico b/contrib/online_ide/www/favicon.ico deleted file mode 100644 index 0f66f25..0000000 Binary files a/contrib/online_ide/www/favicon.ico and /dev/null differ diff --git a/contrib/online_ide/www/index.html b/contrib/online_ide/www/index.html deleted file mode 100644 index e46b0e9..0000000 --- a/contrib/online_ide/www/index.html +++ /dev/null @@ -1,50 +0,0 @@ - - - - - Nit - IDE - - - - - - - - - - -
-
print "Hello World !"
-
-
- - - - -
- - - - - diff --git a/contrib/online_ide/www/js/FileSaver.js b/contrib/online_ide/www/js/FileSaver.js deleted file mode 100644 index 6095017..0000000 --- a/contrib/online_ide/www/js/FileSaver.js +++ /dev/null @@ -1,241 +0,0 @@ -/* FileSaver.js - * A saveAs() FileSaver implementation. - * 2014-05-27 - * - * By Eli Grey, http://eligrey.com - * License: X11/MIT - * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md - */ - -/*global self */ -/*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */ - -/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ - -var saveAs = saveAs - // IE 10+ (native saveAs) - || (typeof navigator !== "undefined" && - navigator.msSaveOrOpenBlob && navigator.msSaveOrOpenBlob.bind(navigator)) - // Everyone else - || (function(view) { - "use strict"; - // IE <10 is explicitly unsupported - if (typeof navigator !== "undefined" && - /MSIE [1-9]\./.test(navigator.userAgent)) { - return; - } - var - doc = view.document - // only get URL when necessary in case Blob.js hasn't overridden it yet - , get_URL = function() { - return view.URL || view.webkitURL || view; - } - , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a") - , can_use_save_link = !view.externalHost && "download" in save_link - , click = function(node) { - var event = doc.createEvent("MouseEvents"); - event.initMouseEvent( - "click", true, false, view, 0, 0, 0, 0, 0 - , false, false, false, false, 0, null - ); - node.dispatchEvent(event); - } - , webkit_req_fs = view.webkitRequestFileSystem - , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem - , throw_outside = function(ex) { - (view.setImmediate || view.setTimeout)(function() { - throw ex; - }, 0); - } - , force_saveable_type = "application/octet-stream" - , fs_min_size = 0 - , deletion_queue = [] - , process_deletion_queue = function() { - var i = deletion_queue.length; - while (i--) { - var file = deletion_queue[i]; - if (typeof file === "string") { // file is an object URL - get_URL().revokeObjectURL(file); - } else { // file is a File - file.remove(); - } - } - deletion_queue.length = 0; // clear queue - } - , dispatch = function(filesaver, event_types, event) { - event_types = [].concat(event_types); - var i = event_types.length; - while (i--) { - var listener = filesaver["on" + event_types[i]]; - if (typeof listener === "function") { - try { - listener.call(filesaver, event || filesaver); - } catch (ex) { - throw_outside(ex); - } - } - } - } - , FileSaver = function(blob, name) { - // First try a.download, then web filesystem, then object URLs - var - filesaver = this - , type = blob.type - , blob_changed = false - , object_url - , target_view - , get_object_url = function() { - var object_url = get_URL().createObjectURL(blob); - deletion_queue.push(object_url); - return object_url; - } - , dispatch_all = function() { - dispatch(filesaver, "writestart progress write writeend".split(" ")); - } - // on any filesys errors revert to saving with object URLs - , fs_error = function() { - // don't create more object URLs than needed - if (blob_changed || !object_url) { - object_url = get_object_url(blob); - } - if (target_view) { - target_view.location.href = object_url; - } else { - window.open(object_url, "_blank"); - } - filesaver.readyState = filesaver.DONE; - dispatch_all(); - } - , abortable = function(func) { - return function() { - if (filesaver.readyState !== filesaver.DONE) { - return func.apply(this, arguments); - } - }; - } - , create_if_not_found = {create: true, exclusive: false} - , slice - ; - filesaver.readyState = filesaver.INIT; - if (!name) { - name = "download"; - } - if (can_use_save_link) { - object_url = get_object_url(blob); - save_link.href = object_url; - save_link.download = name; - click(save_link); - filesaver.readyState = filesaver.DONE; - dispatch_all(); - return; - } - // Object and web filesystem URLs have a problem saving in Google Chrome when - // viewed in a tab, so I force save with application/octet-stream - // http://code.google.com/p/chromium/issues/detail?id=91158 - if (view.chrome && type && type !== force_saveable_type) { - slice = blob.slice || blob.webkitSlice; - blob = slice.call(blob, 0, blob.size, force_saveable_type); - blob_changed = true; - } - // Since I can't be sure that the guessed media type will trigger a download - // in WebKit, I append .download to the filename. - // https://bugs.webkit.org/show_bug.cgi?id=65440 - if (webkit_req_fs && name !== "download") { - name += ".download"; - } - if (type === force_saveable_type || webkit_req_fs) { - target_view = view; - } - if (!req_fs) { - fs_error(); - return; - } - fs_min_size += blob.size; - req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) { - fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) { - var save = function() { - dir.getFile(name, create_if_not_found, abortable(function(file) { - file.createWriter(abortable(function(writer) { - writer.onwriteend = function(event) { - target_view.location.href = file.toURL(); - deletion_queue.push(file); - filesaver.readyState = filesaver.DONE; - dispatch(filesaver, "writeend", event); - }; - writer.onerror = function() { - var error = writer.error; - if (error.code !== error.ABORT_ERR) { - fs_error(); - } - }; - "writestart progress write abort".split(" ").forEach(function(event) { - writer["on" + event] = filesaver["on" + event]; - }); - writer.write(blob); - filesaver.abort = function() { - writer.abort(); - filesaver.readyState = filesaver.DONE; - }; - filesaver.readyState = filesaver.WRITING; - }), fs_error); - }), fs_error); - }; - dir.getFile(name, {create: false}, abortable(function(file) { - // delete file if it already exists - file.remove(); - save(); - }), abortable(function(ex) { - if (ex.code === ex.NOT_FOUND_ERR) { - save(); - } else { - fs_error(); - } - })); - }), fs_error); - }), fs_error); - } - , FS_proto = FileSaver.prototype - , saveAs = function(blob, name) { - return new FileSaver(blob, name); - } - ; - FS_proto.abort = function() { - var filesaver = this; - filesaver.readyState = filesaver.DONE; - dispatch(filesaver, "abort"); - }; - FS_proto.readyState = FS_proto.INIT = 0; - FS_proto.WRITING = 1; - FS_proto.DONE = 2; - - FS_proto.error = - FS_proto.onwritestart = - FS_proto.onprogress = - FS_proto.onwrite = - FS_proto.onabort = - FS_proto.onerror = - FS_proto.onwriteend = - null; - - view.addEventListener("unload", process_deletion_queue, false); - saveAs.unload = function() { - process_deletion_queue(); - view.removeEventListener("unload", process_deletion_queue, false); - }; - return saveAs; -}( - typeof self !== "undefined" && self - || typeof window !== "undefined" && window - || this.content -)); -// `self` is undefined in Firefox for Android content script context -// while `this` is nsIContentFrameMessageManager -// with an attribute `content` that corresponds to the window - -if (typeof module !== "undefined" && module !== null) { - module.exports = saveAs; -} else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) { - define([], function() { - return saveAs; - }); -} diff --git a/contrib/online_ide/www/js/editor_configuration.js b/contrib/online_ide/www/js/editor_configuration.js deleted file mode 100644 index 0d67ad5..0000000 --- a/contrib/online_ide/www/js/editor_configuration.js +++ /dev/null @@ -1,46 +0,0 @@ -// This file is part of NIT ( http://www.nitlanguage.org ) -// -// Copyright 2014 Johan Kayser -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Sets up the editor. - -ace.require("ace/ext/language_tools"); -var editor = ace.edit("editor"); -editor.setTheme("ace/theme/chrome"); -editor.getSession().setMode("ace/mode/nit"); -editor.setOptions({ - enableBasicAutocompletion: true -}); -// Custom commands - -// We launch the interpreter on CTRL+E shortcut. -editor.commands.addCommand({ - name: 'interpret', - bindKey: {win: 'Ctrl-E', mac: 'Command-E'}, - exec: function(editor) { - interpret(); - }, - readOnly: true // false if this command should not apply in readOnly mode -}); - -// We download the current file in editor on CTRL+S shortcut. -editor.commands.addCommand({ - name: 'save', - bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, - exec: function(editor) { - save(); - }, - readOnly: true // false if this command should not apply in readOnly mode -}); diff --git a/contrib/online_ide/www/js/functions.js b/contrib/online_ide/www/js/functions.js deleted file mode 100644 index 688da9b..0000000 --- a/contrib/online_ide/www/js/functions.js +++ /dev/null @@ -1,192 +0,0 @@ -// This file is part of NIT ( http://www.nitlanguage.org ) -// -// Copyright 2014 Johan Kayser -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Initializes the terminal, set it to send messages to PNaCl. -function init_terminal() { - terminal = $('#terminal').terminal(function(command, term) { - pnacl_nitModule.postMessage(command + '\n'); - }, { greetings: false, name: 'terminal' }); -} - -// Edit current file name. -$('#filename').bind('click', function() { - $(this).attr('contentEditable', true); -}).blur( - function() { - $(this).attr('contentEditable', false); - }); - -// To launch the interpret process. -function interpret() { - var dictionary = { - operation: 'interpret', - args: /*"-v -v " + */document.getElementById('filename').innerText + ".nit", - content: editor.getValue() - } - pnacl_nitModule.postMessage(dictionary); -} - -// To save the current editor lines in a file. -function save() { - var blob = new Blob([editor.getValue()], {type: "text/plain;charset=utf-8"}); - saveAs(blob, document.getElementById('filename').innerText + ".nit"); -} - -// To load nit lib -function load_nit_lib() { - if (!lib_files_loaded) - { - // We get the 'nit' folder content on github. - $.get("https://api.github.com/repos/nitlang/nit/contents/?access_token=" + github_acces_token, function(data) { - for (var i = 0; i < data.length; i++) { - if (data[i].name == "lib") { - // We get the list of all files in the 'lib' folder. - $.get("https://api.github.com/repos/nitlang/nit/git/trees/" + data[i].sha + "?recursive=1&access_token=" + github_acces_token, function(data) { - for (var i = 0; i < data.tree.length; i++) { - if (data.tree[i].type == "blob") { - lib_files_number++; - sha_filename_map[data.tree[i].sha] = data.tree[i].path.split("/").pop(); - - // We get the content of each file and send it to PNaCl. - $.get(data.tree[i].url + "?access_token=" + github_acces_token, function(data) { - var dictionary = { - operation: 'load', - filename: sha_filename_map[data.sha], - content: Base64.decode(data.content), - } - pnacl_nitModule.postMessage(dictionary); - lib_files.push(dictionary); - }); - } - } - }); - } - } - }); - } - else { - // If we already have the files stored in JS, we just send them. - for (var i = 0; i < lib_files.length; i++) { - pnacl_nitModule.postMessage(lib_files[i]); - } - } -} - -// To code/decode base64 -var Base64 = { - _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", - - encode: function(input) { - var output = ""; - var chr1, chr2, chr3, enc1, enc2, enc3, enc4; - var i = 0; - - input = Base64._utf8_encode(input); - while (i < input.length) { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - if (isNaN(chr2)) { - enc3 = enc4 = 64; - } else if (isNaN(chr3)) { - enc4 = 64; - } - output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); - } - return output; - }, - - - decode: function(input) { - var output = ""; - var chr1, chr2, chr3; - var enc1, enc2, enc3, enc4; - var i = 0; - - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - while (i < input.length) { - enc1 = this._keyStr.indexOf(input.charAt(i++)); - enc2 = this._keyStr.indexOf(input.charAt(i++)); - enc3 = this._keyStr.indexOf(input.charAt(i++)); - enc4 = this._keyStr.indexOf(input.charAt(i++)); - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - output = output + String.fromCharCode(chr1); - if (enc3 != 64) { - output = output + String.fromCharCode(chr2); - } - if (enc4 != 64) { - output = output + String.fromCharCode(chr3); - } - } - output = Base64._utf8_decode(output); - return output; - }, - - _utf8_encode: function(string) { - string = string.replace(/\r\n/g, "\n"); - var utftext = ""; - - for (var n = 0; n < string.length; n++) { - var c = string.charCodeAt(n); - - if (c < 128) { - utftext += String.fromCharCode(c); - } - else if ((c > 127) && (c < 2048)) { - utftext += String.fromCharCode((c >> 6) | 192); - utftext += String.fromCharCode((c & 63) | 128); - } - else { - utftext += String.fromCharCode((c >> 12) | 224); - utftext += String.fromCharCode(((c >> 6) & 63) | 128); - utftext += String.fromCharCode((c & 63) | 128); - } - } - return utftext; - }, - - _utf8_decode: function(utftext) { - var string = ""; - var i = 0; - var c = c1 = c2 = 0; - - while (i < utftext.length) { - c = utftext.charCodeAt(i); - if (c < 128) { - string += String.fromCharCode(c); - i++; - } - else if ((c > 191) && (c < 224)) { - c2 = utftext.charCodeAt(i + 1); - string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); - i += 2; - } - else { - c2 = utftext.charCodeAt(i + 1); - c3 = utftext.charCodeAt(i + 2); - string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); - i += 3; - } - } - return string; - } -} diff --git a/contrib/online_ide/www/js/jquery.terminal-0.8.7.js b/contrib/online_ide/www/js/jquery.terminal-0.8.7.js deleted file mode 100644 index 5d145f3..0000000 --- a/contrib/online_ide/www/js/jquery.terminal-0.8.7.js +++ /dev/null @@ -1,4328 +0,0 @@ -/**@license - * __ _____ ________ __ - * / // _ /__ __ _____ ___ __ _/__ ___/__ ___ ______ __ __ __ ___ / / - * __ / // // // // // _ // _// // / / // _ // _// // // \/ // _ \/ / - * / / // // // // // ___// / / // / / // ___// / / / / // // /\ // // / /__ - * \___//____ \\___//____//_/ _\_ / /_//____//_/ /_/ /_//_//_/ /_/ \__\_\___/ - * \/ /____/ version 0.8.7 - * http://terminal.jcubic.pl - * - * Licensed under GNU LGPL Version 3 license - * Copyright (c) 2011-2013 Jakub Jankiewicz - * - * Includes: - * - * Storage plugin Distributed under the MIT License - * Copyright (c) 2010 Dave Schindler - * - * jQuery Timers licenced with the WTFPL - * - * - * Cross-Browser Split 1.1.1 - * Copyright 2007-2012 Steven Levithan - * Available under the MIT License - * - * sprintf.js - * Copyright (c) 2007-2013 Alexandru Marasteanu - * licensed under 3 clause BSD license - * - * Date: Sat, 22 Mar 2014 13:32:26 +0000 - * - */ - -(function(ctx) { - var sprintf = function() { - if (!sprintf.cache.hasOwnProperty(arguments[0])) { - sprintf.cache[arguments[0]] = sprintf.parse(arguments[0]); - } - return sprintf.format.call(null, sprintf.cache[arguments[0]], arguments); - }; - - sprintf.format = function(parse_tree, argv) { - var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length; - for (i = 0; i < tree_length; i++) { - node_type = get_type(parse_tree[i]); - if (node_type === 'string') { - output.push(parse_tree[i]); - } - else if (node_type === 'array') { - match = parse_tree[i]; // convenience purposes only - if (match[2]) { // keyword argument - arg = argv[cursor]; - for (k = 0; k < match[2].length; k++) { - if (!arg.hasOwnProperty(match[2][k])) { - throw(sprintf('[sprintf] property "%s" does not exist', match[2][k])); - } - arg = arg[match[2][k]]; - } - } - else if (match[1]) { // positional argument (explicit) - arg = argv[match[1]]; - } - else { // positional argument (implicit) - arg = argv[cursor++]; - } - - if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) { - throw(sprintf('[sprintf] expecting number but found %s', get_type(arg))); - } - switch (match[8]) { - case 'b': arg = arg.toString(2); break; - case 'c': arg = String.fromCharCode(arg); break; - case 'd': arg = parseInt(arg, 10); break; - case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break; - case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break; - case 'o': arg = arg.toString(8); break; - case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break; - case 'u': arg = arg >>> 0; break; - case 'x': arg = arg.toString(16); break; - case 'X': arg = arg.toString(16).toUpperCase(); break; - } - arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg); - pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' '; - pad_length = match[6] - String(arg).length; - pad = match[6] ? str_repeat(pad_character, pad_length) : ''; - output.push(match[5] ? arg + pad : pad + arg); - } - } - return output.join(''); - }; - - sprintf.cache = {}; - - sprintf.parse = function(fmt) { - var _fmt = fmt, match = [], parse_tree = [], arg_names = 0; - while (_fmt) { - if ((match = /^[^\x25]+/.exec(_fmt)) !== null) { - parse_tree.push(match[0]); - } - else if ((match = /^\x25{2}/.exec(_fmt)) !== null) { - parse_tree.push('%'); - } - else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) { - if (match[2]) { - arg_names |= 1; - var field_list = [], replacement_field = match[2], field_match = []; - if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') { - if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - } - else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) { - field_list.push(field_match[1]); - } - else { - throw('[sprintf] huh?'); - } - } - } - else { - throw('[sprintf] huh?'); - } - match[2] = field_list; - } - else { - arg_names |= 2; - } - if (arg_names === 3) { - throw('[sprintf] mixing positional and named placeholders is not (yet) supported'); - } - parse_tree.push(match); - } - else { - throw('[sprintf] huh?'); - } - _fmt = _fmt.substring(match[0].length); - } - return parse_tree; - }; - - var vsprintf = function(fmt, argv, _argv) { - _argv = argv.slice(0); - _argv.splice(0, 0, fmt); - return sprintf.apply(null, _argv); - }; - - /** - * helpers - */ - function get_type(variable) { - return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase(); - } - - function str_repeat(input, multiplier) { - for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */} - return output.join(''); - } - - /** - * export to either browser or node.js - */ - ctx.sprintf = sprintf; - ctx.vsprintf = vsprintf; -})(typeof exports != "undefined" ? exports : window); - -(function($, undefined) { - "use strict"; - // ----------------------------------------------------------------------- - // :: map object to object - // ----------------------------------------------------------------------- - $.omap = function(o, fn) { - var result = {}; - $.each(o, function(k, v) { - result[k] = fn.call(o, k, v); - }); - return result; - }; - // ----------------------------------------------------------------------- - // :: Storage plugin - // ----------------------------------------------------------------------- - // Private data - var isLS = typeof window.localStorage !== 'undefined'; - // Private functions - function wls(n, v) { - var c; - if (typeof n === 'string' && typeof v === 'string') { - localStorage[n] = v; - return true; - } else if (typeof n === 'object' && typeof v === 'undefined') { - for (c in n) { - if (n.hasOwnProperty(c)) { - localStorage[c] = n[c]; - } - } - return true; - } - return false; - } - function wc(n, v) { - var dt, e, c; - dt = new Date(); - dt.setTime(dt.getTime() + 31536000000); - e = '; expires=' + dt.toGMTString(); - if (typeof n === 'string' && typeof v === 'string') { - document.cookie = n + '=' + v + e + '; path=/'; - return true; - } else if (typeof n === 'object' && typeof v === 'undefined') { - for (c in n) { - if (n.hasOwnProperty(c)) { - document.cookie = c + '=' + n[c] + e + '; path=/'; - } - } - return true; - } - return false; - } - function rls(n) { - return localStorage[n]; - } - function rc(n) { - var nn, ca, i, c; - nn = n + '='; - ca = document.cookie.split(';'); - for (i = 0; i < ca.length; i++) { - c = ca[i]; - while (c.charAt(0) === ' ') { - c = c.substring(1, c.length); - } - if (c.indexOf(nn) === 0) { - return c.substring(nn.length, c.length); - } - } - return null; - } - function dls(n) { - return delete localStorage[n]; - } - function dc(n) { - return wc(n, '', -1); - } - /** - * Public API - * $.Storage.set("name", "value") - * $.Storage.set({"name1":"value1", "name2":"value2", etc}) - * $.Storage.get("name") - * $.Storage.remove("name") - */ - $.extend({ - Storage: { - set: isLS ? wls : wc, - get: isLS ? rls : rc, - remove: isLS ? dls : dc - } - }); - // ----------------------------------------------------------------------- - // :: jQuery Timers - // ----------------------------------------------------------------------- - jQuery.fn.extend({ - everyTime: function(interval, label, fn, times, belay) { - return this.each(function() { - jQuery.timer.add(this, interval, label, fn, times, belay); - }); - }, - oneTime: function(interval, label, fn) { - return this.each(function() { - jQuery.timer.add(this, interval, label, fn, 1); - }); - }, - stopTime: function(label, fn) { - return this.each(function() { - jQuery.timer.remove(this, label, fn); - }); - } - }); - - jQuery.extend({ - timer: { - guid: 1, - global: {}, - regex: /^([0-9]+)\s*(.*s)?$/, - powers: { - // Yeah this is major overkill... - 'ms': 1, - 'cs': 10, - 'ds': 100, - 's': 1000, - 'das': 10000, - 'hs': 100000, - 'ks': 1000000 - }, - timeParse: function(value) { - if (value === undefined || value === null) { - return null; - } - var result = this.regex.exec(jQuery.trim(value.toString())); - if (result[2]) { - var num = parseInt(result[1], 10); - var mult = this.powers[result[2]] || 1; - return num * mult; - } else { - return value; - } - }, - add: function(element, interval, label, fn, times, belay) { - var counter = 0; - - if (jQuery.isFunction(label)) { - if (!times) { - times = fn; - } - fn = label; - label = interval; - } - - interval = jQuery.timer.timeParse(interval); - - if (typeof interval !== 'number' || - isNaN(interval) || - interval <= 0) { - return; - } - if (times && times.constructor !== Number) { - belay = !!times; - times = 0; - } - - times = times || 0; - belay = belay || false; - - if (!element.$timers) { - element.$timers = {}; - } - if (!element.$timers[label]) { - element.$timers[label] = {}; - } - fn.$timerID = fn.$timerID || this.guid++; - - var handler = function() { - if (belay && handler.inProgress) { - return; - } - handler.inProgress = true; - if ((++counter > times && times !== 0) || - fn.call(element, counter) === false) { - jQuery.timer.remove(element, label, fn); - } - handler.inProgress = false; - }; - - handler.$timerID = fn.$timerID; - - if (!element.$timers[label][fn.$timerID]) { - element.$timers[label][fn.$timerID] = window.setInterval(handler, interval); - } - - if (!this.global[label]) { - this.global[label] = []; - } - this.global[label].push(element); - - }, - remove: function(element, label, fn) { - var timers = element.$timers, ret; - - if (timers) { - - if (!label) { - for (var lab in timers) { - if (timers.hasOwnProperty(lab)) { - this.remove(element, lab, fn); - } - } - } else if (timers[label]) { - if (fn) { - if (fn.$timerID) { - window.clearInterval(timers[label][fn.$timerID]); - delete timers[label][fn.$timerID]; - } - } else { - for (var _fn in timers[label]) { - if (timers[label].hasOwnProperty(_fn)) { - window.clearInterval(timers[label][_fn]); - delete timers[label][_fn]; - } - } - } - - for (ret in timers[label]) { - if (timers[label].hasOwnProperty(ret)) { - break; - } - } - if (!ret) { - ret = null; - delete timers[label]; - } - } - - for (ret in timers) { - if (timers.hasOwnProperty(ret)) { - break; - } - } - if (!ret) { - element.$timers = null; - } - } - } - } - }); - - if (/(msie) ([\w.]+)/.exec(navigator.userAgent.toLowerCase())) { - jQuery(window).one('unload', function() { - var global = jQuery.timer.global; - for (var label in global) { - if (global.hasOwnProperty(label)) { - var els = global[label], i = els.length; - while (--i) { - jQuery.timer.remove(els[i], label); - } - } - } - }); - } - // ----------------------------------------------------------------------- - // :: CROSS BROWSER SPLIT - // ----------------------------------------------------------------------- - - (function(undef) { - - // prevent double include - - if (!String.prototype.split.toString().match(/\[native/)) { - return; - } - - var nativeSplit = String.prototype.split, - compliantExecNpcg = /()??/.exec("")[1] === undef, // NPCG: nonparticipating capturing group - self; - - self = function (str, separator, limit) { - // If `separator` is not a regex, use `nativeSplit` - if (Object.prototype.toString.call(separator) !== "[object RegExp]") { - return nativeSplit.call(str, separator, limit); - } - var output = [], - flags = (separator.ignoreCase ? "i" : "") + - (separator.multiline ? "m" : "") + - (separator.extended ? "x" : "") + // Proposed for ES6 - (separator.sticky ? "y" : ""), // Firefox 3+ - lastLastIndex = 0, - // Make `global` and avoid `lastIndex` issues by working with a copy - separator2, match, lastIndex, lastLength; - separator = new RegExp(separator.source, flags + "g"); - str += ""; // Type-convert - if (!compliantExecNpcg) { - // Doesn't need flags gy, but they don't hurt - separator2 = new RegExp("^" + separator.source + "$(?!\\s)", flags); - } - /* Values for `limit`, per the spec: - * If undefined: 4294967295 // Math.pow(2, 32) - 1 - * If 0, Infinity, or NaN: 0 - * If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296; - * If negative number: 4294967296 - Math.floor(Math.abs(limit)) - * If other: Type-convert, then use the above rules - */ - // ? Math.pow(2, 32) - 1 : ToUint32(limit) - limit = limit === undef ? -1 >>> 0 : limit >>> 0; - while (match = separator.exec(str)) { - // `separator.lastIndex` is not reliable cross-browser - lastIndex = match.index + match[0].length; - if (lastIndex > lastLastIndex) { - output.push(str.slice(lastLastIndex, match.index)); - // Fix browsers whose `exec` methods don't consistently return `undefined` for - // nonparticipating capturing groups - if (!compliantExecNpcg && match.length > 1) { - match[0].replace(separator2, function () { - for (var i = 1; i < arguments.length - 2; i++) { - if (arguments[i] === undef) { - match[i] = undef; - } - } - }); - } - if (match.length > 1 && match.index < str.length) { - Array.prototype.push.apply(output, match.slice(1)); - } - lastLength = match[0].length; - lastLastIndex = lastIndex; - if (output.length >= limit) { - break; - } - } - if (separator.lastIndex === match.index) { - separator.lastIndex++; // Avoid an infinite loop - } - } - if (lastLastIndex === str.length) { - if (lastLength || !separator.test("")) { - output.push(""); - } - } else { - output.push(str.slice(lastLastIndex)); - } - return output.length > limit ? output.slice(0, limit) : output; - }; - - // For convenience - String.prototype.split = function (separator, limit) { - return self(this, separator, limit); - }; - - return self; - - })(); - // ----------------------------------------------------------------------- - // :: Split string to array of strings with the same length - // ----------------------------------------------------------------------- - function str_parts(str, length) { - var result = []; - var len = str.length; - if (len < length) { - return [str]; - } - for (var i = 0; i < len; i += length) { - result.push(str.substring(i, i + length)); - } - return result; - } - // ----------------------------------------------------------------------- - // :: CYCLE DATA STRUCTURE - // ----------------------------------------------------------------------- - function Cycle(init) { - var data = init ? [init] : []; - var pos = 0; - $.extend(this, { - get: function() { - return data; - }, - rotate: function() { - if (data.length === 1) { - return data[0]; - } else { - if (pos === data.length - 1) { - pos = 0; - } else { - ++pos; - } - return data[pos]; - } - }, - length: function() { - return data.length; - }, - set: function(item) { - for (var i = data.length; i--;) { - if (data[i] === item) { - pos = i; - return; - } - } - this.append(item); - }, - front: function() { - return data[pos]; - }, - append: function(item) { - data.push(item); - } - }); - } - // ----------------------------------------------------------------------- - // :: STACK DATA STRUCTURE - // ----------------------------------------------------------------------- - function Stack(init) { - var data = init ? [init] : []; - $.extend(this, { - map: function(fn) { - return $.map(data, fn); - }, - size: function() { - return data.length; - }, - pop: function() { - if (data.length === 0) { - return null; - } else { - var value = data[data.length - 1]; - data = data.slice(0, data.length - 1); - return value; - } - }, - push: function(value) { - data = data.concat([value]); - return value; - }, - top: function() { - return data.length > 0 ? data[data.length - 1] : null; - } - }); - } - // ----------------------------------------------------------------------- - // :: Serialize object myself (biwascheme or prototype library do something - // :: wicked with JSON serialization for Arrays) - // ----------------------------------------------------------------------- - $.json_stringify = function(object, level) { - var result = '', i; - level = level === undefined ? 1 : level; - var type = typeof object; - switch (type) { - case 'function': - result += object; - break; - case 'boolean': - result += object ? 'true' : 'false'; - break; - case 'object': - if (object === null) { - result += 'null'; - } else if (object instanceof Array) { - result += '['; - var len = object.length; - for (i = 0; i < len - 1; ++i) { - result += $.json_stringify(object[i], level + 1); - } - result += $.json_stringify(object[len - 1], level + 1) + ']'; - } else { - result += '{'; - for (var property in object) { - if (object.hasOwnProperty(property)) { - result += '"' + property + '":' + - $.json_stringify(object[property], level + 1); - } - } - result += '}'; - } - break; - case 'string': - var str = object; - var repl = { - '\\\\': '\\\\', - '"': '\\"', - '/': '\\/', - '\\n': '\\n', - '\\r': '\\r', - '\\t': '\\t'}; - for (i in repl) { - if (repl.hasOwnProperty(i)) { - str = str.replace(new RegExp(i, 'g'), repl[i]); - } - } - result += '"' + str + '"'; - break; - case 'number': - result += String(object); - break; - } - result += (level > 1 ? ',' : ''); - // quick hacks below - if (level === 1) { - // fix last comma - result = result.replace(/,([\]}])/g, '$1'); - } - // fix comma before array or object - return result.replace(/([\[{]),/g, '$1'); - }; - // ----------------------------------------------------------------------- - // :: HISTORY CLASS - // ----------------------------------------------------------------------- - function History(name, size) { - var enabled = true; - var storage_key = ''; - if (typeof name === 'string' && name !== '') { - storage_key = name + '_'; - } - storage_key += 'commands'; - var data = $.Storage.get(storage_key); - data = data ? $.parseJSON(data) : []; - var pos = data.length-1; - $.extend(this, { - append: function(item) { - if (enabled) { - if (data[data.length-1] !== item) { - data.push(item); - if (size && data.length > size) { - data = data.slice(-size); - } - pos = data.length-1; - $.Storage.set(storage_key, $.json_stringify(data)); - } - } - }, - data: function() { - return data; - }, - reset: function() { - pos = data.length-1; - }, - last: function() { - return data[length-1]; - }, - end: function() { - return pos === data.length-1; - }, - position: function() { - return pos; - }, - current: function() { - return data[pos]; - }, - next: function() { - if (pos < data.length-1) { - ++pos; - } - if (pos !== -1) { - return data[pos]; - } - }, - previous: function() { - var old = pos; - if (pos > 0) { - --pos; - } - if (old !== -1) { - return data[pos]; - } - }, - clear: function() { - data = []; - this.purge(); - }, - enabled: function() { - return enabled; - }, - enable: function() { - enabled = true; - }, - purge: function() { - $.Storage.remove(storage_key); - }, - disable: function() { - enabled = false; - } - }); - } - // ----------------------------------------------------------------------- - // :: COMMAND LINE PLUGIN - // ----------------------------------------------------------------------- - $.fn.cmd = function(options) { - var self = this; - var maybe_data = self.data('cmd'); - if (maybe_data) { - return maybe_data; - } - self.addClass('cmd'); - self.append('' + - ' '); - var clip = $('