Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #3025
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail |
|---|---|
| From | Felipe Balbi <balbif@gmail.com> |
| Newsgroups | comp.lang.ruby |
| Subject | Making a simple parser |
| Date | Sat, 16 Apr 2011 14:52:16 -0500 |
| Organization | Service de news de lacave.net |
| Lines | 55 |
| Message-ID | <87adbac7061a00a72e282c160ed42414@ruby-forum.com> (permalink) |
| NNTP-Posting-Host | bristol.highgroove.com |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Trace | talisker.lacave.net 1302983673 96845 65.111.164.187 (16 Apr 2011 19:54:33 GMT) |
| X-Complaints-To | abuse@lacave.net |
| NNTP-Posting-Date | Sat, 16 Apr 2011 19:54:33 +0000 (UTC) |
| X-Received-From | This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway |
| X-Mail-Count | 381716 |
| X-Ml-Name | ruby-talk |
| X-Rubymirror | Yes |
| X-Ruby-Talk | <87adbac7061a00a72e282c160ed42414@ruby-forum.com> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.ruby:3025 |
Show key headers only | View raw
Hi all,
To automate some of the tests I have to run, I decided to use ruby to
generate some script files on a particular (very simple) language based
on several possible input files. My first approach at this was to use
inherited method on a parent class (which I called InputFormat) to hold
all the children in an array. Then, different formats could become a
child class of InputFormat and return a known data format (I decided to
use an array of hashes because the output is really really simple) to
the output generator code.
So the idea is something like:
class InputFormat
@children = []
def initialize(input)
@input = input
end
def parse
@children.each { |child|
child.parse(@input) if child.supported?(@input)
}
end
def self.inherited(child)
@children << child
end
end
class AInputFormat < InputFormat
def supported?
# check if we can parse this type of file
end
def parse
# parse and generate array of hashes in known format
end
end
Then on the core file I would have something like:
input = InputFormat.new(ARGV[0])
input.parse
As it turns out, this isn't working because AInputFormat will only
inherit from InputFormat at the time I actually use it, am I right ? Any
tips you guys could give me to achieve what I want ? (from several
possible input formats generate one output format)
--
Posted via http://www.ruby-forum.com/.
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar | Unroll thread
Making a simple parser Felipe Balbi <balbif@gmail.com> - 2011-04-16 14:52 -0500
Re: Making a simple parser 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-16 22:31 -0500
Re: Making a simple parser jake kaiden <jakekaiden@yahoo.com> - 2011-04-17 12:01 -0500
Re: Making a simple parser Felipe Balbi <balbif@gmail.com> - 2011-04-17 15:22 -0500
Re: Making a simple parser jake kaiden <jakekaiden@yahoo.com> - 2011-04-17 21:10 -0500
Re: Making a simple parser Jesús Gabriel y Galán <jgabrielygalan@gmail.com> - 2011-04-18 02:22 -0500
Re: Making a simple parser Felipe Balbi <balbif@gmail.com> - 2011-04-19 16:03 -0500
Re: Making a simple parser 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-18 13:24 -0500
Re: Making a simple parser 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-18 15:22 -0500
csiph-web