This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ragel -R lexer.rl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| integer = <token_description>; | |
| float = <token_description>; | |
| main := |* | |
| integer => {<action>}; | |
| float => {<action>}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %%{ | |
| machine test_lexer; | |
| <scanner_name> := |* | |
| <token_description> => {<action>}; | |
| <token_description> => {<action>}; | |
| *|; | |
| }%% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # lexer.rl | |
| %%{ | |
| machine test_lexer; | |
| }%% | |
| %% write data; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| blank_object = { | |
| :parent => nil, | |
| :slots => {}, | |
| :size => 0 | |
| } | |
| def send(receiver, message, *params, &block) | |
| method_owner = receiver | |
| while(method_owner[:slots][:lookup].nil?) | |
| puts "ERR: lookup failed for ':lookup' on object:\n#{receiver.inspect}" and break if(method_owner[:parent].nil?) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| send(object_with_size, :size) | |
| # => 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object_with_size = derive_from(basic_object) | |
| send(object_with_size, :add_method, :size) do |this, params| | |
| this[:size] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| basic_object[:size] = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| basic_object[:slots][:add_method] = Proc.new do |this, params| | |
| puts "ERR: add_method called without method key" and return unless(params.first.is_a?(String) || params.first.is_a?(Symbol)) | |
| puts "ERR: add_method called without block" and return unless(params.last.is_a?(Proc)) | |
| this[:slots][params.first.to_sym] = params.last | |
| this[:size] += 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| basic_object = derive_from(blank_object) | |
| basic_object[:slots][:lookup] = Proc.new do |this, message| | |
| method_owner = this | |
| while(!method_owner.nil? && method_owner[:slots][message.to_sym].nil?) | |
| puts "ERR: lookup failed for '#{message}' on object:\n#{this.inspect}" and break if(method_owner[:parent].nil?) | |
| method_owner = method_owner[:parent] | |
| end | |
| method_owner[:slots][message.to_sym] unless(method_owner.nil?) | |
| end |