Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solidity syntax highlighting #109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
r: ['r'],
ruby: ['rakefile', 'gemfile', 'rb'],
scala: ['scala', 'scl', 'sca', 'scb'],
solidity: ['sol'],
scss: ['scss', 'sass'],
smalltalk: ['st', 'sm', 'sll'],
sml: ['sml'],
Expand Down
92 changes: 92 additions & 0 deletions js/languages/solidity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Language: Solidity
Author: Your Name <[email protected]>
Description: language definition for Solidity programming language used for developing smart contracts on the Ethereum blockchain
Website: https://soliditylang.org/
Category: common, blockchain
*/

hljs.registerLanguage('solidity', function(hljs) {
var NUMBER = {className: 'number', relevance: 0, variants: [
{begin: '\\b(0[bB][01]+)'}, // binary
{begin: '\\b(0[oO][0-7]+)'}, // octal
{begin: '\\b(0[xX][0-9a-fA-F]+)'}, // hex
{begin: '\\b([0-9]+(\\.[0-9]+)?([eE][+-]?[0-9]+)?)'} // decimal
]};
var KEYWORDS = {
keyword:
'pragma return assembly break continue do else for if import ' +
'new try catch throw while emit event mapping struct enum ' +
'constructor modifier function selfdestruct payable view pure ' +
'constant external public private internal indexed memory storage ' +
'function view payable returns',
built_in:
'assert require revert block coinbase difficulty gaslimit ' +
'gasprice number timestamp tx blockhash'
};
return {
aliases: ['solidity', 'sol'],
case_insensitive: true,
keywords: KEYWORDS,
contains: [
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
hljs.QUOTE_STRING_MODE,
hljs.APOS_STRING_MODE,
{
className: 'string',
begin: '"""', end: '"""',
relevance: 10
},
NUMBER,
{
className: 'meta',
begin: '^\\s*#', end: '$',
contains: [
{
className: 'meta-string',
variants: [
{ begin: /<.*?>/ },
{ begin: /\".*\"/ },
{ begin: /\'.*\'/ }
]
}
]
},
{
className: 'function',
beginKeywords: 'function', end: /\{/, excludeEnd: true,
illegal: /\[|%/,
contains: [
hljs.TITLE_MODE,
{
className: 'params',
begin: /\(/, end: /\)/,
excludeBegin: true,
excludeEnd: true,
contains: [
hljs.SELF_CONTAINED,
{
className: 'param',
begin: /(\b[a-zA-Z_$][\w$]*)\s*:/, end: /,/,
returnBegin: true, excludeEnd: true
}
]
}
]
},
{
className: 'class',
beginKeywords: 'contract interface', end: /\{/, excludeEnd: true,
contains: [
hljs.TITLE_MODE,
{
className: 'inheritance',
begin: /is/, end: /(\s|\{|$)/,
keywords: {keyword: 'is'}
}
]
}
]
};
})