Class: LogoNxc
- Inherits:
-
Object
- Object
- LogoNxc
- Defined in:
- lib/logonxc.rb
Class Method Summary collapse
- .nxc(logo) ⇒ Object
-
.parse(text) ⇒ Object
ok so this probably isn’t the best way to write a language parser :).
- .wrap(nxc_block) ⇒ Object
Class Method Details
.nxc(logo) ⇒ Object
33 34 35 |
# File 'lib/logonxc.rb', line 33 def self.nxc(logo) wrap(parse(logo)) end |
.parse(text) ⇒ Object
ok so this probably isn’t the best way to write a language parser :)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/logonxc.rb', line 12 def self.parse text output = "" text.each_line do |line| case when line =~ /repeat\s+(\d+)\s+\[/ output << "repeat(#{$1}) {\n" when line =~ /(?:right|rt)\s*(\d+)/ output << "right(#{$1});\n" when line =~ /(?:left|lt)\s*(\d+)/ output << "left(#{$1});\n" when line =~ /(?:forward|fd)\s*(\d+)/ output << "forward(#{$1});\n" when line =~ /(?:back|bk)\s*(\d+)/ output << "back(#{$1});\n" when line =~ /\]/ output << "}\n" end end output end |
.wrap(nxc_block) ⇒ Object
5 6 7 8 9 |
# File 'lib/logonxc.rb', line 5 def self.wrap(nxc_block) tpl = File.(File.dirname(__FILE__) + "/../templates/logonxc.erb") template = Erubis::Eruby.new File.new(tpl).read template.result(:nxc_block => nxc_block) end |