Skip to content

Instantly share code, notes, and snippets.

View aarongough's full-sized avatar

Aaron Gough (He/Him) aarongough

View GitHub Profile
object_with_size = derive_from(basic_object)
send(object_with_size, :add_method, :size) do |this, params|
this[:size]
end
send(object_with_size, :size)
# => 1
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?)
# lexer.rl
%%{
machine test_lexer;
}%%
%% write data;
%%{
machine test_lexer;
<scanner_name> := |*
<token_description> => {<action>};
<token_description> => {<action>};
*|;
}%%
%%{
machine test_lexer;
integer = <token_description>;
float = <token_description>;
main := |*
integer => {<action>};
float => {<action>};
def run_lexer(data)
data = data.unpack("c*") if(data.is_a?(String))
eof = data.length
token_array = []
%% write init;
%% write exec;
puts token_array.inspect
end
%%{
machine test_lexer;
integer = ('+'|'-')?[0-9]+;
}%%
%%{
machine test_lexer;
integer = ('+'|'-')?[0-9]+;
main := |*
integer;
*|;