This file contains 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
[{:name => :integer_literal, :value => "-101" }] |
This file contains 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 = ('+'|'-')?[0-9]+; | |
main := |* | |
integer => { | |
emit(:integer_literal, data, token_array, ts, te) | |
}; |
This file contains 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
def emit(token_name, data, target_array, ts, te) | |
target_array << {:name => token_name.to_sym, :value => data[ts...te].pack("c*") } | |
end |
This file contains 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 = ('+'|'-')?[0-9]+; | |
main := |* | |
integer => { puts "Integer: " + data[ts..te].pack("c*") }; | |
*|; | |
This file contains 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 = ('+'|'-')?[0-9]+; | |
main := |* | |
integer => { puts "Integer" }; | |
*|; | |
This file contains 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 = ('+'|'-')?[0-9]+; | |
main := |* | |
integer; | |
*|; | |
This file contains 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 = ('+'|'-')?[0-9]+; | |
}%% |
This file contains 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
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 |
This file contains 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 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>}; |