Browse Source

solidity builtins auto-completion and syntax highlight

cl-refactor
arkpar 10 years ago
parent
commit
618189fb7c
  1. 9
      mix/qml/html/cm/anyword-hint.js
  2. 2
      mix/qml/html/cm/inkpot.css
  3. 2
      mix/qml/html/cm/solidity.js
  4. 24
      mix/qml/html/cm/solidityToken.js

9
mix/qml/html/cm/anyword-hint.js

@ -24,6 +24,15 @@
list = addSolToken(curWord, list, seen, solMisc(), solMisc); list = addSolToken(curWord, list, seen, solMisc(), solMisc);
} }
//TODO: tokenize properly
if (curLine.slice(start - 6, start) === "block.")
list = addSolToken(curWord, list, seen, solBlock(), solBlock);
else if (curLine.slice(start - 4, start) === "msg.")
list = addSolToken(curWord, list, seen, solMsg(), solMsg);
else if (curLine.slice(start - 3, start) === "tx.")
list = addSolToken(curWord, list, seen, solTx(), solTx);
var previousWord = ""; var previousWord = "";
var re = new RegExp(word.source, "g"); var re = new RegExp(word.source, "g");
for (var dir = -1; dir <= 1; dir += 2) { for (var dir = -1; dir <= 1; dir += 2) {

2
mix/qml/html/cm/inkpot.css

@ -21,7 +21,7 @@ https://github.com/ciaranm/inkpot
.cm-s-inkpot span.cm-comment { color: #cd8b00; } .cm-s-inkpot span.cm-comment { color: #cd8b00; }
.cm-s-inkpot span.cm-def { color: #cfbfad; font-weight:bold; } .cm-s-inkpot span.cm-def { color: #cfbfad; font-weight:bold; }
.cm-s-inkpot span.cm-keyword { color: #808bed; } .cm-s-inkpot span.cm-keyword { color: #808bed; }
.cm-s-inkpot span.cm-builtin { color: #cfbfad; } .cm-s-inkpot span.cm-builtin { color: #efac6d; }
.cm-s-inkpot span.cm-variable { color: #cfbfad; } .cm-s-inkpot span.cm-variable { color: #cfbfad; }
.cm-s-inkpot span.cm-string { color: #ffcd8b; } .cm-s-inkpot span.cm-string { color: #ffcd8b; }
.cm-s-inkpot span.cm-number { color: #f0ad6d; } .cm-s-inkpot span.cm-number { color: #f0ad6d; }

2
mix/qml/html/cm/solidity.js

@ -16,6 +16,7 @@ CodeMirror.defineMode("solidity", function(config) {
var stdContract = solStdContract(); var stdContract = solStdContract();
var keywords = solKeywords(); var keywords = solKeywords();
var atoms = solMisc(); var atoms = solMisc();
var builtins = solBuiltIn();
var isOperatorChar = /[+\-*&^%:=<>!|\/]/; var isOperatorChar = /[+\-*&^%:=<>!|\/]/;
@ -64,6 +65,7 @@ CodeMirror.defineMode("solidity", function(config) {
if (atoms.propertyIsEnumerable(cur)) return "atom"; if (atoms.propertyIsEnumerable(cur)) return "atom";
if (types.propertyIsEnumerable(cur)) return "variable-2"; if (types.propertyIsEnumerable(cur)) return "variable-2";
if (stdContract.propertyIsEnumerable(cur)) return "variable-3"; if (stdContract.propertyIsEnumerable(cur)) return "variable-3";
if (builtins.propertyIsEnumerable(cur)) return "builtin";
return "variable"; return "variable";
} }

24
mix/qml/html/cm/solidityToken.js

@ -28,6 +28,26 @@ function solMisc()
return { "true": true, "false": true, "null": true }; return { "true": true, "false": true, "null": true };
} }
function solBuiltIn()
{
return { "msg": true, "tx": true, "block": true, "now": true };
}
function solBlock()
{
return { "coinbase": true, "difficulty": true, "gaslimit": true, "number": true, "blockhash": true, "timestamp":true };
}
function solMsg()
{
return { "data": true, "gas": true, "sender": true, "sig": true, "value": true };
}
function solTx()
{
return { "gasprice": true, "origin": true }
}
function keywordsName() function keywordsName()
{ {
var keywords = {}; var keywords = {};
@ -37,5 +57,9 @@ function keywordsName()
keywords[solTime.name.toLowerCase()] = "Time"; keywords[solTime.name.toLowerCase()] = "Time";
keywords[solTypes.name.toLowerCase()] = "Type"; keywords[solTypes.name.toLowerCase()] = "Type";
keywords[solMisc.name.toLowerCase()] = "Misc"; keywords[solMisc.name.toLowerCase()] = "Misc";
keywords[solBuiltIn.name.toLowerCase()] = "BuiltIn";
keywords[solBlock.name.toLowerCase()] = "Block";
keywords[solMsg.name.toLowerCase()] = "Message";
keywords[solTx.name.toLowerCase()] = "Transaction";
return keywords; return keywords;
} }

Loading…
Cancel
Save