From 618189fb7c0d6ebdfd6a0ccabbc29af7ff7b9b7e Mon Sep 17 00:00:00 2001 From: arkpar Date: Thu, 6 Aug 2015 14:31:13 +0200 Subject: [PATCH] solidity builtins auto-completion and syntax highlight --- mix/qml/html/cm/anyword-hint.js | 9 +++++++++ mix/qml/html/cm/inkpot.css | 2 +- mix/qml/html/cm/solidity.js | 2 ++ mix/qml/html/cm/solidityToken.js | 24 ++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/mix/qml/html/cm/anyword-hint.js b/mix/qml/html/cm/anyword-hint.js index d1034ed8c..050d59ddf 100644 --- a/mix/qml/html/cm/anyword-hint.js +++ b/mix/qml/html/cm/anyword-hint.js @@ -24,6 +24,15 @@ 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 re = new RegExp(word.source, "g"); for (var dir = -1; dir <= 1; dir += 2) { diff --git a/mix/qml/html/cm/inkpot.css b/mix/qml/html/cm/inkpot.css index b31e20ad8..4a2197cfc 100644 --- a/mix/qml/html/cm/inkpot.css +++ b/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-def { color: #cfbfad; font-weight:bold; } .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-string { color: #ffcd8b; } .cm-s-inkpot span.cm-number { color: #f0ad6d; } diff --git a/mix/qml/html/cm/solidity.js b/mix/qml/html/cm/solidity.js index e1cfeefbb..23f1e460c 100644 --- a/mix/qml/html/cm/solidity.js +++ b/mix/qml/html/cm/solidity.js @@ -16,6 +16,7 @@ CodeMirror.defineMode("solidity", function(config) { var stdContract = solStdContract(); var keywords = solKeywords(); var atoms = solMisc(); + var builtins = solBuiltIn(); var isOperatorChar = /[+\-*&^%:=<>!|\/]/; @@ -64,6 +65,7 @@ CodeMirror.defineMode("solidity", function(config) { if (atoms.propertyIsEnumerable(cur)) return "atom"; if (types.propertyIsEnumerable(cur)) return "variable-2"; if (stdContract.propertyIsEnumerable(cur)) return "variable-3"; + if (builtins.propertyIsEnumerable(cur)) return "builtin"; return "variable"; } diff --git a/mix/qml/html/cm/solidityToken.js b/mix/qml/html/cm/solidityToken.js index 1c12278e1..fbed0287e 100644 --- a/mix/qml/html/cm/solidityToken.js +++ b/mix/qml/html/cm/solidityToken.js @@ -28,6 +28,26 @@ function solMisc() 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() { var keywords = {}; @@ -37,5 +57,9 @@ function keywordsName() keywords[solTime.name.toLowerCase()] = "Time"; keywords[solTypes.name.toLowerCase()] = "Type"; 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; }