├── README.md ├── package.json └── solidity.js /README.md: -------------------------------------------------------------------------------- 1 | **:DEPRECATED:** 2 | 3 | This repository has moved to https://github.com/highlightjs/highlightjs-solidity 4 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "highlightjs-solidity", 3 | "version": "1.0.6", 4 | "description": "highlight.js syntax definition for Ethereum's Solidity language", 5 | "main": "solidity.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+ssh://git@github.com/pospi/highlightjs-solidity.git" 12 | }, 13 | "keywords": [ 14 | "Solidity", 15 | "Ethereum", 16 | "highlight.js", 17 | "highlightjs", 18 | "syntax" 19 | ], 20 | "author": "pospi", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/pospi/highlightjs-solidity/issues" 24 | }, 25 | "homepage": "https://github.com/pospi/highlightjs-solidity#readme" 26 | } 27 | -------------------------------------------------------------------------------- /solidity.js: -------------------------------------------------------------------------------- 1 | /** 2 | * highlight.js Solidity syntax highlighting definition 3 | * 4 | * @see https://github.com/isagalaev/highlight.js 5 | * 6 | * :TODO: 7 | * - fixed point numbers 8 | * - `_` inside modifiers 9 | * - assembly block keywords 10 | * 11 | * @package: highlightjs-solidity 12 | * @author: Sam Pospischil 13 | * @since: 2016-07-01 14 | */ 15 | 16 | var module = module ? module : {}; // shim for browser use 17 | 18 | function hljsDefineSolidity(hljs) { 19 | var SOL_KEYWORDS = { 20 | keyword: 21 | 'var bool string ' + 22 | 'int uint int8 uint8 int16 uint16 int24 uint24 int32 uint32 ' + 23 | 'int40 uint40 int48 uint48 int56 uint56 int64 uint64 ' + 24 | 'int72 uint72 int80 uint80 int88 uint88 int96 uint96 ' + 25 | 'int104 uint104 int112 uint112 int120 uint120 int128 uint128 ' + 26 | 'int136 uint136 int144 uint144 int152 uint152 int160 uint160 ' + 27 | 'int168 uint168 int176 uint176 int184 uint184 int192 uint192 ' + 28 | 'int200 uint200 int208 uint208 int216 uint216 int224 uint224 ' + 29 | 'int232 uint232 int240 uint240 int248 uint248 int256 uint256 ' + 30 | 'byte bytes bytes1 bytes2 bytes3 bytes4 bytes5 bytes6 bytes7 bytes8 ' + 31 | 'bytes9 bytes10 bytes11 bytes12 bytes13 bytes14 bytes15 bytes16 ' + 32 | 'bytes17 bytes18 bytes19 bytes20 bytes21 bytes22 bytes23 bytes24 ' + 33 | 'bytes25 bytes26 bytes27 bytes28 bytes29 bytes30 bytes31 bytes32 ' + 34 | 'enum struct mapping address ' + 35 | 36 | 'new delete ' + 37 | 'if else for while continue break return throw assert require revert ' + 38 | 39 | 'function modifier event ' + 40 | 'constant anonymous indexed ' + 41 | 'storage memory ' + 42 | 'external public internal pure view private returns ' + 43 | 44 | 'import using ' + 45 | 'contract interface library ' + 46 | 'assembly', 47 | literal: 48 | 'true false ' + 49 | 'wei szabo finney ether ' + 50 | 'second seconds minute minutes hour hours day days week weeks year years', 51 | built_in: 52 | 'self ' + // :NOTE: not a real keyword, but a convention used in storage manipulation libraries 53 | 'this super selfdestruct ' + 54 | 'now ' + 55 | 'msg ' + 56 | 'block ' + 57 | 'tx ' + 58 | 'sha3 sha256 ripemd160 erecover addmod mulmod ' + 59 | // :NOTE: not really toplevel, but advantageous to have highlighted as if reserved to 60 | // avoid newcomers making mistakes due to accidental name collisions. 61 | 'send call callcode delegatecall', 62 | }; 63 | 64 | var SOL_NUMBER = { 65 | className: 'number', 66 | variants: [ 67 | { begin: '\\b(0[bB][01]+)' }, 68 | { begin: '\\b(0[oO][0-7]+)' }, 69 | { begin: hljs.C_NUMBER_RE }, 70 | ], 71 | relevance: 0, 72 | }; 73 | 74 | var SOL_FUNC_PARAMS = { 75 | className: 'params', 76 | begin: /\(/, end: /\)/, 77 | excludeBegin: true, 78 | excludeEnd: true, 79 | keywords: SOL_KEYWORDS, 80 | contains: [ 81 | hljs.C_LINE_COMMENT_MODE, 82 | hljs.C_BLOCK_COMMENT_MODE, 83 | hljs.APOS_STRING_MODE, 84 | hljs.QUOTE_STRING_MODE, 85 | SOL_NUMBER, 86 | ], 87 | }; 88 | 89 | var SOL_RESERVED_MEMBERS = { 90 | begin: /\.\s*/, // match any property access up to start of prop 91 | end: /[^A-Za-z0-9$_\.]/, 92 | excludeBegin: true, 93 | excludeEnd: true, 94 | keywords: { 95 | built_in: 'gas value send call callcode delegatecall balance length push', 96 | }, 97 | relevance: 2, 98 | }; 99 | 100 | function makeBuiltinProps(obj, props) { 101 | return { 102 | begin: obj + '\\.\\s*', 103 | end: /[^A-Za-z0-9$_\.]/, 104 | excludeBegin: false, 105 | excludeEnd: true, 106 | keywords: { 107 | built_in: obj + ' ' + props, 108 | }, 109 | contains: [ 110 | SOL_RESERVED_MEMBERS, 111 | ], 112 | relevance: 10, 113 | }; 114 | } 115 | 116 | return { 117 | aliases: ['sol'], 118 | keywords: SOL_KEYWORDS, 119 | contains: [ 120 | // basic literal definitions 121 | hljs.APOS_STRING_MODE, 122 | hljs.QUOTE_STRING_MODE, 123 | hljs.C_LINE_COMMENT_MODE, 124 | hljs.C_BLOCK_COMMENT_MODE, 125 | SOL_NUMBER, 126 | { // functions 127 | className: 'function', 128 | beginKeywords: 'function modifier event', end: /[{;]/, excludeEnd: true, 129 | contains: [ 130 | hljs.inherit(hljs.TITLE_MODE, { 131 | begin: /[A-Za-z$_][0-9A-Za-z$_]*/, 132 | keywords: SOL_KEYWORDS, 133 | }), 134 | SOL_FUNC_PARAMS, 135 | ], 136 | illegal: /\[|%/, 137 | }, 138 | // built-in members 139 | makeBuiltinProps('msg', 'data sender sig'), 140 | makeBuiltinProps('block', 'blockhash coinbase difficulty gaslimit number timestamp '), 141 | makeBuiltinProps('tx', 'gasprice origin'), 142 | SOL_RESERVED_MEMBERS, 143 | { // contracts & libraries & interfaces 144 | className: 'class', 145 | beginKeywords: 'contract interface library', end: /[{]/, excludeEnd: true, 146 | illegal: /[:"\[\]]/, 147 | contains: [ 148 | { beginKeywords: 'is' }, 149 | hljs.UNDERSCORE_TITLE_MODE, 150 | SOL_FUNC_PARAMS, 151 | ], 152 | }, 153 | { // imports 154 | beginKeywords: 'import', end: '[;$]', 155 | keywords: 'import * from as', 156 | contains: [ 157 | hljs.APOS_STRING_MODE, 158 | hljs.QUOTE_STRING_MODE, 159 | ], 160 | }, 161 | ], 162 | illegal: /#/, 163 | }; 164 | } 165 | 166 | module.exports = function(hljs) { 167 | hljs.registerLanguage('solidity', hljsDefineSolidity); 168 | }; 169 | 170 | module.exports.definer = hljsDefineSolidity; 171 | --------------------------------------------------------------------------------