cm-mode-kevscript
Advanced tools
Comparing version 1.0.2 to 2.0.1
{ | ||
"name": "cm-mode-kevscript", | ||
"version": "1.0.2", | ||
"version": "2.0.1", | ||
"description": "KevScript mode for CodeMirror", | ||
@@ -8,5 +8,5 @@ "main": "src/mode/kevscript.js", | ||
"scripts": { | ||
"start": "webpack-dev-server", | ||
"start": "NODE_ENV=development webpack-dev-server", | ||
"lint": "eslint src", | ||
"build": "NODE_ENV=production webpack -p" | ||
"build": "webpack -p --progress" | ||
}, | ||
@@ -29,13 +29,20 @@ "repository": { | ||
"devDependencies": { | ||
"babel-core": "^6.25.0", | ||
"babel-loader": "^7.1.1", | ||
"babel-preset-env": "^1.6.0", | ||
"codemirror": "^5.27.2", | ||
"eslint": "^4.1.1", | ||
"css-loader": "^0.28.4", | ||
"eslint": "^4.3.0", | ||
"eslint-config-kevoree": "^1.0.1", | ||
"extract-text-webpack-plugin": "^3.0.0", | ||
"html-webpack-plugin": "^2.29.0", | ||
"kevoree-kevscript": "^5.0.0-alpha.2", | ||
"kevoree-library": "^5.0.10", | ||
"kevoree-registry-client": "^1.0.0-alpha.9", | ||
"kevoree-validator": "^0.1.17", | ||
"tiny-conf": "^1.0.5", | ||
"webpack": "^3.0.0", | ||
"webpack-dev-server": "^2.5.0" | ||
"kevoree-kevscript": "^5.0.1", | ||
"kevoree-library": "^5.0.13", | ||
"kevoree-registry-client": "^3.0.1", | ||
"kevoree-validator": "^0.1.20", | ||
"style-loader": "^0.18.2", | ||
"tiny-conf": "^1.1.0", | ||
"webpack": "^3.4.1", | ||
"webpack-dev-server": "^2.5.1" | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
var CodeMirror = require('codemirror'); | ||
var api = require('kevoree-registry-client'); | ||
const CodeMirror = require('codemirror'); | ||
const api = require('kevoree-registry-client'); | ||
var HINT_TPL = '<div class="hint-primary"><div class="hint-anchor {{type}}">{{typeText}}</div><div class="hint-text">{{text}}</div></div><div class="hint-secondary">{{desc}}</div>'; | ||
const HINT_TPL = '<div class="hint-primary"><div class="hint-anchor {{type}}">{{typeText}}</div><div class="hint-text">{{text}}</div></div><div class="hint-secondary">{{desc}}</div>'; | ||
function renderTpl(tpl, data) { | ||
Object.keys(data).forEach(function (key) { | ||
Object.keys(data).forEach((key) => { | ||
tpl = tpl.replace(new RegExp('{{' + key + '}}', 'g'), data[key]); | ||
@@ -14,3 +14,3 @@ }); | ||
function renderHtml(data) { | ||
return function (elem) { | ||
return (elem) => { | ||
elem.innerHTML = renderTpl(HINT_TPL, data); | ||
@@ -35,18 +35,10 @@ }; | ||
function hint(cm, callback, options) { | ||
var cursor = cm.getCursor(); | ||
var token = cm.getTokenAt(cursor); | ||
var cur = token.string; | ||
var start = token.start; | ||
var end = token.end; | ||
var list = []; | ||
var tmp; | ||
const cursor = cm.getCursor(); | ||
const token = cm.getTokenAt(cursor); | ||
let cur = token.string; | ||
let start = token.start; | ||
let end = token.end; | ||
let list = []; | ||
let tmp; | ||
// console.log({ | ||
// state: token.state.state, | ||
// stmt: token.state.stmt, | ||
// string: token.string, | ||
// type: token.type, | ||
// instancePath: token.state.instancePath | ||
// }); | ||
function model() { | ||
@@ -67,3 +59,3 @@ return options.getModel(); | ||
return rootInstances() | ||
.find(function (i) { | ||
.find((i) => { | ||
return i.name === name; | ||
@@ -98,13 +90,13 @@ }); | ||
return api.namespace.all() | ||
.then(function (namespaces) { | ||
.then((namespaces) => { | ||
callback({ | ||
list: namespaces | ||
.filter(function (ns) { | ||
.filter((ns) => { | ||
return cur.trim() | ||
.length === 0 || ns.name.startsWith(cur); | ||
}) | ||
.sort(function (ns0, ns1) { | ||
.sort((ns0, ns1) => { | ||
return ns0.name.localeCompare(ns1.name); | ||
}) | ||
.map(function (ns) { | ||
.map((ns) => { | ||
return { | ||
@@ -117,3 +109,3 @@ type: 'namespace', | ||
}) | ||
.map(function (data) { | ||
.map((data) => { | ||
return { | ||
@@ -131,8 +123,8 @@ text: data.bufferText, | ||
start = (cur === '.') ? token.end : token.start; | ||
var ns = (cur === '.') ? token.state.namespace : 'kevoree'; | ||
const ns = (cur === '.') ? token.state.namespace : 'kevoree'; | ||
return api.tdef.getLatestsByNamespace(ns) | ||
.then(function (tdefs) { | ||
.then((tdefs) => { | ||
callback({ | ||
list: tdefs | ||
.filter(function (tdef) { | ||
.filter((tdef) => { | ||
if (cur === '.' || cur.trim().length === 0) { | ||
@@ -144,8 +136,8 @@ return true; | ||
}) | ||
.sort(function (tdef0, tdef1) { | ||
.sort((tdef0, tdef1) => { | ||
return tdef0.name.localeCompare(tdef1.name); | ||
}) | ||
.map(function (tdef) { | ||
var model = JSON.parse(tdef.model); | ||
var type = getType(model); | ||
.map((tdef) => { | ||
const model = JSON.parse(tdef.model); | ||
const type = getType(model); | ||
return { | ||
@@ -160,3 +152,3 @@ type: type, | ||
}) | ||
.map(function (data) { | ||
.map((data) => { | ||
return { | ||
@@ -183,3 +175,3 @@ text: data.bufferText, | ||
list = model().groups.array | ||
.map(function (group) { | ||
.map((group) => { | ||
return { | ||
@@ -191,3 +183,3 @@ type: 'group', | ||
}) | ||
.filter(function (item) { | ||
.filter((item) => { | ||
return cur.length === 0 || item.text.startsWith(cur); | ||
@@ -198,3 +190,3 @@ }); | ||
list = model().hubs.array | ||
.map(function (chan) { | ||
.map((chan) => { | ||
return { | ||
@@ -206,3 +198,3 @@ type: 'channel', | ||
}) | ||
.filter(function (item) { | ||
.filter((item) => { | ||
return cur.length === 0 || item.text.startsWith(cur); | ||
@@ -228,3 +220,3 @@ }); | ||
] | ||
.map(function (stmt) { | ||
.map((stmt) => { | ||
stmt.type = 'stmt'; | ||
@@ -234,6 +226,6 @@ stmt.bufferText = stmt.text + ' '; | ||
}) | ||
.filter(function (item) { | ||
.filter((item) => { | ||
return cur.length === 0 || item.text.startsWith(cur); | ||
}) | ||
.sort(function (item0, item1) { | ||
.sort((item0, item1) => { | ||
return item0.text.localeCompare(item1.text); | ||
@@ -255,3 +247,3 @@ }); | ||
list = model() | ||
.nodes.array.map(function (node) { | ||
.nodes.array.map((node) => { | ||
return { | ||
@@ -267,3 +259,3 @@ type: 'node', | ||
// there is already some text in the buffer => filter using it | ||
list = list.filter(function (item) { | ||
list = list.filter((item) => { | ||
return item.text.startsWith(cur); | ||
@@ -282,3 +274,3 @@ }); | ||
list = model().nodes.array | ||
.map(function (node) { | ||
.map((node) => { | ||
return { | ||
@@ -291,3 +283,3 @@ type: 'node', | ||
}) | ||
.filter(function (item) { | ||
.filter((item) => { | ||
return item.text.startsWith(cur); | ||
@@ -300,3 +292,3 @@ }); | ||
list = tmp.typeDefinition.dictionaryType.attributes.array | ||
.map(function (attr) { | ||
.map((attr) => { | ||
return { | ||
@@ -313,3 +305,3 @@ type: 'attr', | ||
.concat(tmp.components.array | ||
.map(function (comp) { | ||
.map((comp) => { | ||
return { | ||
@@ -325,3 +317,3 @@ type: 'component', | ||
list = list.filter(function (item) { | ||
list = list.filter((item) => { | ||
return item.text.startsWith(cur); | ||
@@ -335,3 +327,3 @@ }); | ||
list = rootInstances() | ||
.map(function (instance) { | ||
.map((instance) => { | ||
return { | ||
@@ -346,3 +338,3 @@ type: getTypeDefinitionType(instance.typeDefinition), | ||
if (cur.length > 0) { | ||
list = list.filter(function (elem) { | ||
list = list.filter((elem) => { | ||
return elem.text.startsWith(cur); | ||
@@ -364,3 +356,3 @@ }); | ||
list = model() | ||
.nodes.array.map(function (node) { | ||
.nodes.array.map((node) => { | ||
return { | ||
@@ -374,3 +366,3 @@ type: 'node', | ||
if (cur.length > 0) { | ||
list = list.filter(function (elem) { | ||
list = list.filter((elem) => { | ||
return elem.text.startsWith(cur); | ||
@@ -390,3 +382,3 @@ }); | ||
list = model() | ||
.nodes.array.map(function (node) { | ||
.nodes.array.map((node) => { | ||
return { | ||
@@ -401,3 +393,3 @@ type: 'node', | ||
if (cur.length > 0) { | ||
list = list.filter(function (elem) { | ||
list = list.filter((elem) => { | ||
return elem.text.startsWith(cur); | ||
@@ -412,3 +404,3 @@ }); | ||
start += 1; | ||
list = model().nodes.array.map(function (node) { | ||
list = model().nodes.array.map((node) => { | ||
return { | ||
@@ -436,3 +428,3 @@ type: 'node', | ||
.array | ||
.map(function (tdef) { | ||
.map((tdef) => { | ||
return { | ||
@@ -447,3 +439,3 @@ type: 'version', | ||
if (cur.length > 0) { | ||
list = list.filter(function (item) { | ||
list = list.filter((item) => { | ||
return item.text.startsWith(cur); | ||
@@ -465,8 +457,8 @@ }); | ||
) | ||
.then(function (dus) { | ||
.then((dus) => { | ||
if (dus.length > 0) { | ||
return [{ | ||
type: 'version', | ||
bufferText: '{' + dus.map(function (du, i, array) { | ||
var str = ' ' + du.platform + ': \'' + du.version + '\''; | ||
bufferText: '{' + dus.map((du, i, array) => { | ||
let str = ' ' + du.platform + ': \'' + du.version + '\''; | ||
if (i < array - 1) { | ||
@@ -477,4 +469,4 @@ str += ' '; | ||
}).join(', ') + '}', | ||
text: dus.map(function (du, i, array) { | ||
var str = du.platform + '=' + du.version; | ||
text: dus.map((du, i, array) => { | ||
let str = du.platform + '=' + du.version; | ||
if (i < array - 1) { | ||
@@ -491,6 +483,6 @@ str += ' '; | ||
}) | ||
.catch(function () { | ||
.catch(() => { | ||
return []; | ||
}) | ||
.then(function (list) { | ||
.then((list) => { | ||
return api.du.getReleases( | ||
@@ -500,8 +492,8 @@ token.state.namespace || 'kevoree', | ||
token.state.version | ||
).then(function (dus) { | ||
).then((dus) => { | ||
if (dus.length > 0) { | ||
return list.concat([{ | ||
type: 'version', | ||
bufferText: '{' + dus.map(function (du, i, array) { | ||
var str = ' ' + du.platform + ': \'' + du.version + '\''; | ||
bufferText: '{' + dus.map((du, i, array) => { | ||
let str = ' ' + du.platform + ': \'' + du.version + '\''; | ||
if (i < array - 1) { | ||
@@ -512,4 +504,4 @@ str += ' '; | ||
}).join(', ') + '}', | ||
text: dus.map(function (du, i, array) { | ||
var str = du.platform + '=' + du.version; | ||
text: dus.map((du, i, array) => { | ||
let str = du.platform + '=' + du.version; | ||
if (i < array - 1) { | ||
@@ -525,7 +517,7 @@ str += ' '; | ||
} | ||
}).catch(function () { | ||
}).catch(() => { | ||
return list; | ||
}); | ||
}) | ||
.then(function (list) { | ||
.then((list) => { | ||
return list.concat([ | ||
@@ -544,7 +536,7 @@ { | ||
}) | ||
.then(function (list) { | ||
.then((list) => { | ||
callback({ | ||
list: list.filter(function (item) { | ||
list: list.filter((item) => { | ||
return item.text.startsWith(cur); | ||
}).map(function (item) { | ||
}).map((item) => { | ||
item.typeText = item.type.substr(0, 1); | ||
@@ -567,7 +559,7 @@ return { | ||
// we need to show components + attributes | ||
var rootInstance = findRootInstance(token.state.instancePath[0]); | ||
const rootInstance = findRootInstance(token.state.instancePath[0]); | ||
if (rootInstance) { | ||
if (token.state.instancePath.length === 1) { | ||
list = rootInstance.typeDefinition.dictionaryType.attributes.array | ||
.map(function (attr) { | ||
.map((attr) => { | ||
return { | ||
@@ -585,3 +577,3 @@ type: 'attr', | ||
list = list.concat(rootInstance.components.array | ||
.map(function (comp) { | ||
.map((comp) => { | ||
return { | ||
@@ -603,3 +595,3 @@ type: 'component', | ||
// this is a group: we are fine | ||
list = rootInstance.subNodes.array.map(function (node) { | ||
list = rootInstance.subNodes.array.map((node) => { | ||
return { | ||
@@ -619,3 +611,3 @@ type: 'node', | ||
list = tmp.typeDefinition.dictionaryType.attributes.array | ||
.map(function (attr) { | ||
.map((attr) => { | ||
return { | ||
@@ -638,3 +630,3 @@ type: 'attr', | ||
list = model() | ||
.hubs.array.map(function (chan) { | ||
.hubs.array.map((chan) => { | ||
return { | ||
@@ -653,3 +645,3 @@ type: 'channel', | ||
if (tmp) { | ||
list = tmp.components.array.map(function (comp) { | ||
list = tmp.components.array.map((comp) => { | ||
return { | ||
@@ -666,3 +658,3 @@ type: 'component', | ||
list = model() | ||
.nodes.array.map(function (node) { | ||
.nodes.array.map((node) => { | ||
return { | ||
@@ -677,3 +669,3 @@ type: 'node', | ||
if (cur.length > 0) { | ||
list = list.filter(function (item) { | ||
list = list.filter((item) => { | ||
return item.text.startsWith(cur); | ||
@@ -689,6 +681,6 @@ }); | ||
if (tmp) { | ||
var comp = tmp.findComponentsByID(token.state.instancePath[1]); | ||
const comp = tmp.findComponentsByID(token.state.instancePath[1]); | ||
if (comp) { | ||
list = comp.typeDefinition.provided.array | ||
.map(function (port) { | ||
.map((port) => { | ||
return { | ||
@@ -701,3 +693,3 @@ type: 'input', | ||
.concat(comp.typeDefinition.required.array | ||
.map(function (port) { | ||
.map((port) => { | ||
return { | ||
@@ -718,3 +710,3 @@ type: 'output', | ||
.groups.array | ||
.map(function (grp) { | ||
.map((grp) => { | ||
return { | ||
@@ -733,3 +725,3 @@ type: 'group', | ||
if (tmp) { | ||
list = tmp.components.array.map(function (comp) { | ||
list = tmp.components.array.map((comp) => { | ||
return { | ||
@@ -750,3 +742,3 @@ type: 'component', | ||
list = model() | ||
.nodes.array.map(function (node) { | ||
.nodes.array.map((node) => { | ||
return { | ||
@@ -760,3 +752,3 @@ type: 'node', | ||
if (cur.length > 0) { | ||
list = list.filter(function (item) { | ||
list = list.filter((item) => { | ||
return item.text.startsWith(cur); | ||
@@ -777,5 +769,5 @@ }); | ||
list: list | ||
.map(function (data) { | ||
.map((data) => { | ||
data.bufferText = data.bufferText || data.text; | ||
data.typeText = function () { | ||
data.typeText = () => { | ||
return data.type.substr(0, 1); | ||
@@ -785,3 +777,3 @@ }; | ||
}) | ||
.map(function (data) { | ||
.map((data) => { | ||
return { | ||
@@ -788,0 +780,0 @@ text: data.bufferText, |
@@ -1,11 +0,30 @@ | ||
var CodeMirror = require('codemirror'); | ||
const CodeMirror = require('codemirror'); | ||
CodeMirror.registerHelper('lint', 'kevscript', validator); | ||
const TOKENS = [ | ||
'repoToken', | ||
'includeToken', | ||
'addToken', | ||
'removeToken', | ||
'moveToken', | ||
'setToken', | ||
'attachToken', | ||
'detachToken', | ||
'networkToken', | ||
'bindToken', | ||
'unbindToken', | ||
'namespaceToken', | ||
'startToken', | ||
'stopToken', | ||
'pauseToken', | ||
'comment' | ||
]; | ||
function validator(kevs, getModel, ctxVars) { | ||
return function (text, updateLinting, options, cm) { | ||
return (text, updateLinting, options, cm) => { | ||
CodeMirror.signal(cm, 'lintStart'); | ||
var start = 0; | ||
var lines = text.split('\n').map(function (line, i) { | ||
var obj = { | ||
let start = 0; | ||
const lines = text.split('\n').map((line, i) => { | ||
const obj = { | ||
start: start, | ||
@@ -19,14 +38,29 @@ end: start + line.length, | ||
kevs.parse(text, getModel(), ctxVars, function (err, model, warnings) { | ||
var error; | ||
var lintErrors = []; | ||
if (err) { | ||
if (err.nt) { | ||
var message = 'Unable to match \'' + err.nt + '\''; | ||
if (err.nt === 'ws') { | ||
kevs.parse(text, getModel(), ctxVars) | ||
.then(({ model, warnings }) => { | ||
const lintErrors = []; | ||
options.lintedModel = model; | ||
warnings.forEach((warning) => { | ||
const line = findLine(warning.pos, lines); | ||
lintErrors.push({ | ||
severity: 'warning', | ||
message: warning.message, | ||
from: CodeMirror.Pos(line, relativeToLine(warning.pos[0], lines)), | ||
to: CodeMirror.Pos(line, relativeToLine(warning.pos[1], lines)) | ||
}); | ||
}); | ||
return { lintErrors, model }; | ||
}) | ||
.catch((err) => { | ||
const lintErrors = []; | ||
if (err.parser) { | ||
let message = 'Unable to match \'' + err.parser.nt + '\''; | ||
if (err.parser.nt === 'ws') { | ||
message = 'Unable to match \'whitespace\''; | ||
} else if (err.nt === 'kevScript') { | ||
} else if (err.parser.nt === 'kevScript') { | ||
message = 'A line must start with a statement (add, attach, set, etc.)'; | ||
} else if (tokens.indexOf(err.nt) >= 0) { | ||
message = 'Expected statement or comment (do you mean \'' + (err.nt.split('Token').shift()) + '\'?)'; | ||
} else if (TOKENS.indexOf(err.parser.nt) >= 0) { | ||
message = 'Expected statement or comment (do you mean \'' + (err.parser.nt.split('Token').shift()) + '\'?)'; | ||
} | ||
@@ -36,8 +70,8 @@ lintErrors.push({ | ||
message: message, | ||
from: CodeMirror.Pos(err.line - 1, (err.col === 0) ? 0 : err.col - 1), | ||
to: CodeMirror.Pos(err.line - 1, (err.col === 0) ? 1 : err.col) | ||
from: CodeMirror.Pos(err.parser.line - 1, (err.parser.col === 0) ? 0 : err.parser.col - 1), | ||
to: CodeMirror.Pos(err.parser.line - 1, (err.parser.col === 0) ? 1 : err.parser.col) | ||
}); | ||
} else { | ||
if (err.pos) { | ||
var line = findLine(err.pos, lines); | ||
const line = findLine(err.pos, lines); | ||
lintErrors.push({ | ||
@@ -49,34 +83,33 @@ severity: 'error', | ||
}); | ||
} else { | ||
error = err; | ||
} | ||
} | ||
} else { | ||
options.lintedModel = model; | ||
} | ||
warnings.forEach(function (warning) { | ||
var line = findLine(warning.pos, lines); | ||
lintErrors.push({ | ||
severity: 'warning', | ||
message: warning.message, | ||
from: CodeMirror.Pos(line, relativeToLine(warning.pos[0], lines)), | ||
to: CodeMirror.Pos(line, relativeToLine(warning.pos[1], lines)) | ||
if (err.warnings) { | ||
err.warnings.forEach((warning) => { | ||
const line = findLine(warning.pos, lines); | ||
lintErrors.push({ | ||
severity: 'warning', | ||
message: warning.message, | ||
from: CodeMirror.Pos(line, relativeToLine(warning.pos[0], lines)), | ||
to: CodeMirror.Pos(line, relativeToLine(warning.pos[1], lines)) | ||
}); | ||
}); | ||
} | ||
return { error: err, lintErrors }; | ||
}) | ||
.then(({ error, lintErrors, model }) => { | ||
CodeMirror.signal(cm, 'lintDone', { | ||
error, | ||
model, | ||
warnings: lintErrors.filter((error) => error.severity === 'warning'), | ||
}); | ||
updateLinting(cm, lintErrors); | ||
}); | ||
CodeMirror.signal(cm, 'lintDone', error, lintErrors, model); | ||
updateLinting(cm, lintErrors); | ||
}); | ||
}; | ||
} | ||
var tokens = ['repoToken', 'includeToken', 'addToken', 'removeToken', 'moveToken', | ||
'setToken', 'attachToken', 'detachToken', 'networkToken', 'bindToken', | ||
'unbindToken', 'namespaceToken', 'startToken', 'stopToken', | ||
'pauseToken', 'comment']; | ||
function findLine(pos, lines) { | ||
var line = -1; | ||
for (var i = 0; i < lines.length; i++) { | ||
let line = -1; | ||
for (let i = 0; i < lines.length; i++) { | ||
if ((pos[0] >= lines[i].start) && (pos[1] <= lines[i].end)) { | ||
@@ -91,5 +124,5 @@ line = lines[i].line; | ||
function relativeToLine(ch, lines) { | ||
var val = 0; | ||
for (var i = 0; i < lines.length; i++) { | ||
var tmp = val + (lines[i].end - lines[i].start) + 1; // + 1 is for \n | ||
let val = 0; | ||
for (let i = 0; i < lines.length; i++) { | ||
const tmp = val + (lines[i].end - lines[i].start) + 1; // + 1 is for \n | ||
if (tmp > ch) { | ||
@@ -96,0 +129,0 @@ return ch - val; |
@@ -1,5 +0,5 @@ | ||
var CodeMirror = require('codemirror'); | ||
const CodeMirror = require('codemirror'); | ||
CodeMirror.defineMode('kevscript', function () { | ||
var STATES = { | ||
CodeMirror.defineMode('kevscript', () => { | ||
const STATES = { | ||
start: [ | ||
@@ -11,3 +11,3 @@ { regex: /\/\/.*/, token: 'comment' }, | ||
push: 'addStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'add'; | ||
@@ -21,3 +21,3 @@ state.instancePath = []; | ||
push: 'setStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'set'; | ||
@@ -31,3 +31,3 @@ state.instancePath = []; | ||
push: 'attachStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'attach'; | ||
@@ -41,3 +41,3 @@ state.instancePath = []; | ||
push: 'detachStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'detach'; | ||
@@ -51,3 +51,3 @@ state.instancePath = []; | ||
push: 'moveStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'move'; | ||
@@ -61,3 +61,3 @@ state.instancePath = []; | ||
push: 'startStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'start'; | ||
@@ -71,3 +71,3 @@ state.instancePath = []; | ||
push: 'stopStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'stop'; | ||
@@ -81,3 +81,3 @@ state.instancePath = []; | ||
push: 'pauseStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'pause'; | ||
@@ -91,3 +91,3 @@ state.instancePath = []; | ||
push: 'removeStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'remove'; | ||
@@ -101,3 +101,3 @@ state.instancePath = []; | ||
push: 'bindStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'bind'; | ||
@@ -111,3 +111,3 @@ state.instancePath = []; | ||
push: 'unbindStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'unbind'; | ||
@@ -121,3 +121,3 @@ state.instancePath = []; | ||
push: 'repoStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'repo'; | ||
@@ -131,3 +131,3 @@ state.instancePath = []; | ||
push: 'includeStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'include'; | ||
@@ -141,3 +141,3 @@ state.instancePath = []; | ||
push: 'networkStmt', | ||
process: function (state) { | ||
process: (state) => { | ||
state.stmt = 'network'; | ||
@@ -164,3 +164,3 @@ state.instancePath = []; | ||
push: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -174,3 +174,3 @@ } | ||
push: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -256,3 +256,3 @@ } | ||
next: 'instancepathInstancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -266,3 +266,3 @@ } | ||
next: 'instancepathInstancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -277,3 +277,3 @@ } | ||
next: 'tdefversion', | ||
process: function (state, matches) { | ||
process: (state, matches) => { | ||
state.typedef = matches[1]; | ||
@@ -290,3 +290,3 @@ } | ||
token: 'namespace', | ||
process: function (state, matches) { | ||
process: (state, matches) => { | ||
state.namespace = matches[0]; | ||
@@ -310,3 +310,3 @@ } | ||
next: 'duversion', | ||
process: function (state, matches) { | ||
process: (state, matches) => { | ||
state.version = matches[1]; | ||
@@ -518,3 +518,3 @@ } | ||
push: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -526,3 +526,3 @@ } | ||
next: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -540,3 +540,3 @@ } | ||
push: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -548,3 +548,3 @@ } | ||
next: 'instancepathInstancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -558,3 +558,3 @@ } | ||
next: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -566,3 +566,3 @@ } | ||
push: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -590,3 +590,3 @@ } | ||
token: ['identifier', 'delimiter'], | ||
process: function (state, matches) { | ||
process: (state, matches) => { | ||
state.instancePath.push(matches[1]); | ||
@@ -613,3 +613,3 @@ } | ||
token: 'identifier', | ||
process: function (state, matches) { | ||
process: (state, matches) => { | ||
state.instancePath.push(matches[0]); | ||
@@ -628,3 +628,3 @@ }, | ||
push: 'instancepath', | ||
process: function (state) { | ||
process: (state) => { | ||
state.instancePath = []; | ||
@@ -652,3 +652,3 @@ } | ||
return { | ||
startState: function () { | ||
startState: () => { | ||
return { | ||
@@ -659,5 +659,5 @@ state: 'start', | ||
}, | ||
token: function (stream, state) { | ||
token: (stream, state) => { | ||
if (state.pending) { | ||
var pend = state.pending.shift(); | ||
const pend = state.pending.shift(); | ||
if (state.pending.length === 0) { | ||
@@ -670,8 +670,8 @@ state.pending = null; | ||
var rules = STATES[state.state]; | ||
const rules = STATES[state.state]; | ||
if (rules) { | ||
for (var i = 0; i < rules.length; i++) { | ||
var rule = rules[i]; | ||
for (let i = 0; i < rules.length; i++) { | ||
const rule = rules[i]; | ||
if (rule) { | ||
var matches = stream.match(rule.regex); | ||
const matches = stream.match(rule.regex); | ||
if (matches) { | ||
@@ -681,3 +681,3 @@ if (rule.next) { | ||
} else if (rule.pop && state.stack.length > 0) { | ||
var item = state.stack.pop(); | ||
const item = state.stack.pop(); | ||
state.state = item.state; | ||
@@ -704,3 +704,3 @@ if (typeof item.onPop === 'function') { | ||
state.pending = []; | ||
for (var j = 2; j < matches.length; j++) { | ||
for (let j = 2; j < matches.length; j++) { | ||
if (matches[j]) { | ||
@@ -735,4 +735,4 @@ state.pending.push({ | ||
}, | ||
copyState: function (state) { | ||
var s = { | ||
copyState: (state) => { | ||
const s = { | ||
stmt: state.stmt, | ||
@@ -739,0 +739,0 @@ state: state.state, |
@@ -0,29 +1,17 @@ | ||
const loggerDiv = document.getElementById('logger'); | ||
let prevTime = Date.now(); | ||
const logger = { | ||
info(tag, msg) { | ||
if (!msg) { | ||
msg = tag; | ||
tag = 'CodeMirrorTest'; | ||
} | ||
console.log('[INFO] %s %s', tag, msg); | ||
info(msg) { | ||
loggerDiv.appendChild(createLine('info', msg)); | ||
}, | ||
debug(tag, msg) { | ||
if (!msg) { | ||
msg = tag; | ||
tag = 'CodeMirrorTest'; | ||
} | ||
console.log('[DEBUG] %s %s', tag, msg); | ||
debug(msg) { | ||
loggerDiv.appendChild(createLine('debug', msg)); | ||
}, | ||
warn(tag, msg) { | ||
if (!msg) { | ||
msg = tag; | ||
tag = 'CodeMirrorTest'; | ||
} | ||
console.log('[WARN] %s %s', tag, msg); | ||
warn(msg) { | ||
loggerDiv.appendChild(createLine('warn', msg)); | ||
}, | ||
error(tag, msg) { | ||
if (!msg) { | ||
msg = tag; | ||
tag = 'CodeMirrorTest'; | ||
} | ||
console.log('[ERROR] %s %s', tag, msg); | ||
error(msg) { | ||
loggerDiv.appendChild(createLine('error', msg)); | ||
}, | ||
@@ -34,2 +22,17 @@ setLevel() {}, | ||
function createLine(level, msg) { | ||
const curTime = Date.now(); | ||
const log = document.createElement('div'); | ||
log.innerText = msg; | ||
log.classList.add('line'); | ||
log.classList.add(level); | ||
const ellapsedElem = document.createElement('span'); | ||
ellapsedElem.classList.add('time'); | ||
ellapsedElem.innerText = '+' + (curTime - prevTime) + 'ms'; | ||
log.appendChild(ellapsedElem); | ||
prevTime = curTime; | ||
return log; | ||
} | ||
module.exports = logger; |
@@ -8,3 +8,3 @@ const CodeMirror = require('codemirror'); | ||
config.set('registry', { | ||
host: 'new-registry.kevoree.org', | ||
host: 'registry.kevoree.org', | ||
port: 443, | ||
@@ -14,2 +14,14 @@ ssl: true | ||
require('codemirror/lib/codemirror.css'); | ||
require('codemirror/addon/mode/simple'); | ||
require('codemirror/addon/lint/lint'); | ||
require('codemirror/addon/lint/lint.css'); | ||
require('codemirror/addon/hint/show-hint'); | ||
require('codemirror/addon/hint/show-hint.css'); | ||
require('../src/mode/kevscript'); | ||
require('../src/theme/kevscript.css'); | ||
require('../src/lint/lint'); | ||
require('../src/hint/hint'); | ||
require('../src/hint/hint.css'); | ||
const factory = new kevoree.factory.DefaultKevoreeFactory(); | ||
@@ -50,2 +62,15 @@ const kevs = new KevScript(logger); | ||
editor.on('lintDone', ({ error, warnings, model }) => { | ||
console.log('Lint done'); | ||
if (error) { | ||
console.log(' => NOK'); | ||
console.log(' - warnings:', warnings); | ||
console.log(' - error:', error); | ||
} else { | ||
console.log(' => OK'); | ||
console.log(' - warnings:', warnings); | ||
console.log(' - model:', model); | ||
} | ||
}); | ||
editor.setValue('add node0: JavascriptNode/LATEST/LATEST' + | ||
@@ -52,0 +77,0 @@ '\nadd node0.ticker: Ticker/LATEST/LATEST' + |
const webpack = require('webpack'); | ||
const { resolve } = require('path'); | ||
const ProgressPlugin = require('webpack/lib/ProgressPlugin'); | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
const ExtractTextPlugin = require("extract-text-webpack-plugin"); | ||
const { ProgressPlugin, NoEmitOnErrorsPlugin, NamedModulesPlugin } = require('webpack'); | ||
const { NoEmitOnErrorsPlugin, NamedModulesPlugin } = require('webpack'); | ||
const config = { | ||
@@ -19,2 +18,18 @@ entry: { | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: "style-loader", | ||
use: "css-loader" | ||
}) | ||
}, | ||
{ | ||
test: /\.js$/, | ||
exclude: /node_modules/, | ||
use: 'babel-loader' | ||
}, | ||
] | ||
}, | ||
externals: { | ||
@@ -28,12 +43,13 @@ 'codemirror': 'CodeMirror', | ||
plugins: [ | ||
new ProgressPlugin(), | ||
new NoEmitOnErrorsPlugin(), | ||
new ProgressPlugin(), | ||
new NamedModulesPlugin({}) | ||
new NamedModulesPlugin({}), | ||
], | ||
}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
config.entry.test = resolve('test', 'main.js'); | ||
if (process.env.NODE_ENV === 'development') { | ||
config.entry = resolve('test', 'main.js'); | ||
config.plugins.push( | ||
new webpack.HotModuleReplacementPlugin(), | ||
new ExtractTextPlugin('style.css'), | ||
new HtmlWebpackPlugin({ | ||
@@ -47,6 +63,8 @@ "template": "./test/index.html", | ||
"xhtml": true, | ||
})); | ||
}) | ||
); | ||
config.devtool = 'source-map'; | ||
config.externals = {}; | ||
} | ||
module.exports = config; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2014
1
88334
17
16