Class: Rouge::Lexers::Solidity

Inherits:
RegexLexer show all
Defined in:
lib/rouge/lexers/solidity.rb

Constant Summary

Constants inherited from RegexLexer

RegexLexer::MAX_NULL_SCANS

Constants included from Token::Tokens

Token::Tokens::Num, Token::Tokens::Str

Instance Attribute Summary

Attributes inherited from Rouge::Lexer

#options

Class Method Summary collapse

Methods inherited from RegexLexer

append, #delegate, #goto, #group, #groups, #in_state?, #pop!, prepend, #push, #recurse, replace_state, #reset!, #reset_stack, #stack, start, start_procs, state, #state, #state?, state_definitions, states, #step, #stream_tokens, #token

Methods inherited from Rouge::Lexer

aliases, all, #as_bool, #as_lexer, #as_list, #as_string, #as_token, #bool_option, continue_lex, #continue_lex, debug_enabled?, demo, demo_file, desc, detectable?, disable_debug!, enable_debug!, filenames, find, find_fancy, guess, guess_by_filename, guess_by_mimetype, guess_by_source, guesses, #hash_option, #initialize, lex, #lex, #lexer_option, #list_option, lookup_fancy, mimetypes, option, option_docs, #reset!, #stream_tokens, #string_option, #tag, tag, title, #token_option, #with

Methods included from Token::Tokens

token

Constructor Details

This class inherits a constructor from Rouge::Lexer

Class Method Details

.builtinsObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rouge/lexers/solidity.rb', line 33

def self.builtins
  return @builtins if @builtins

  @builtins = Set.new %w(
    now
    false true
    balance now selector super this
    blockhash gasleft
    assert require revert
    selfdestruct suicide
    call callcode delegatecall
    send transfer
    addmod ecrecover keccak256 mulmod sha256 sha3 ripemd160
  )

  # TODO: use (currently shadowed by catch-all in :statements)
  abi = %w(decode encode encodePacked encodeWithSelector encodeWithSignature)
  @builtins.merge( abi.map { |i| "abi.#{i}" } )
  block = %w(coinbase difficulty gaslimit hash number timestamp)
  @builtins.merge( block.map { |i| "block.#{i}" } )
  msg = %w(data gas sender sig value)
  @builtins.merge( msg.map { |i| "msg.#{i}" } )
  tx = %w(gasprice origin)
  @builtins.merge( tx.map { |i| "tx.#{i}" } )
end

.constantsObject



59
60
61
62
63
64
# File 'lib/rouge/lexers/solidity.rb', line 59

def self.constants
  @constants ||= Set.new %w(
    wei finney szabo ether
    seconds minutes hours days weeks years
  )
end

.detect?(text) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rouge/lexers/solidity.rb', line 16

def self.detect?(text)
  return true if text.start_with? 'pragma solidity'
end

.keywordsObject

TODO: seperate by "type"



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rouge/lexers/solidity.rb', line 21

def self.keywords
  @keywords ||= Set.new %w(
    abstract anonymous as assembly break catch calldata constant
    constructor continue contract do delete else emit enum event
    external fallback for function hex if indexed interface
    internal import is library mapping memory modifier new
    override payable public pure pragma private receive return
    returns storage struct throw try type using var view virtual
    while
  )
end

.keywords_typeObject



66
67
68
69
70
# File 'lib/rouge/lexers/solidity.rb', line 66

def self.keywords_type
  @keywords_type ||= Set.new %w(
    address bool byte bytes int string uint
  )
end

.reservedObject



72
73
74
75
76
77
78
79
# File 'lib/rouge/lexers/solidity.rb', line 72

def self.reserved
  @reserved ||= Set.new %w(
    alias after apply auto case copyof default define final fixed
    immutable implements in inline let macro match mutable null of
    partial promise reference relocatable sealed sizeof static
    supports switch typedef typeof ufixed unchecked
  )
end