Class: Solidity::Parser
- Inherits:
-
Object
- Object
- Solidity::Parser
- Defined in:
- lib/solidity/parser.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_quick_pass_one ⇒ Object
-
#initialize(txt) ⇒ Parser
constructor
A new instance of Parser.
- #outline ⇒ Object
- #pragmas ⇒ Object
Constructor Details
#initialize(txt) ⇒ Parser
Returns a new instance of Parser.
12 13 14 |
# File 'lib/solidity/parser.rb', line 12 def initialize( txt ) @txt = txt end |
Class Method Details
.read(path) ⇒ Object
5 6 7 8 |
# File 'lib/solidity/parser.rb', line 5 def self.read( path ) txt = read_text( path ) new( txt ) end |
Instance Method Details
#_quick_pass_one ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 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 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/solidity/parser.rb', line 20 def _quick_pass_one tree = [] lex = Lexer.new( @txt ) until lex.eos? case lex.peek when :comment ## single or multi-line comment tree << [:comment, lex.next] ## note: if next token is newline - slurp / ignore lex.next if lex.peek == :nl when :pragma code = lex.scan_until( :';', include: true ) ## print "pragma:" ## pp code tree << [:pragma, code] when :contract code = lex.scan_until( :'{' ) ## print "contract:" ## pp code tree << [:contract, code] when :abstract code = lex.scan_until( :'{' ) ## print "abstract contract:" ## pp code tree << [:abstract_contract, code] when :library code = lex.scan_until( :'{' ) ## print "library:" ## pp code tree << [:library, code] when :interface code = lex.scan_until( :'{' ) ## print "interface:" ## pp code tree << [:interface, code] else ## slurp chunk ,that is, until newline or comment or tracked keyword last = tree[-1] if last.is_a?( String ) last << lex.next ## append lexeme to last chunk else tree << lex.next ## start a new chunk end end end tree end |
#outline ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/solidity/parser.rb', line 73 def outline buf = String.new( '' ) tree = _quick_pass_one tree.each do |node| if node.is_a?( Array ) case node[0] when :contract then buf << node[1] << "\n" when :abstract_contract then buf << node[1] << "\n" when :interface then buf << node[1] << "\n" when :library then buf << node[1] << "\n" else end end end buf end |
#pragmas ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/solidity/parser.rb', line 92 def pragmas buf = String.new( '' ) tree = _quick_pass_one tree.each do |node| if node.is_a?( Array ) case node[0] when :pragma then buf << node[1] << "\n" end end end buf end |