I work for a software development company that is currently writing an
in-house grammar for parsing Ruby. I've been frustrated by it many,
many, many times. Maybe it's easy to program in, but it's a nightmare to
parse.
My particular question (right now :P) is in reference to the do keyword.
I was sure that if there was a "do" eg.
expression.each do | [
name
]+
>
body
end
there would be an "end". But now I've run into this particular example.
def _tags
rv = [
"title",
"link",
"description",
"language",
"copyright",
"managingEditor",
"webMaster",
"rating",
"docs",
"skipDays",
"skipHours",
"image",
"textInput",
"cloud",
].delete_if do |x|
send(x).nil?
end.collect do |elem|
[nil, elem]
end
@item.each do
rv << [nil, "item"]
end
rv
end
Can someone please enlighten me as to why this particular do is special?
I work for a software development company that is currently writing an in-house grammar for parsing Ruby. I've been frustrated by it many, many, many times. Maybe it's easy to program in, but it's a nightmare to parse.
Agreed.
My particular question (right now :P) is in reference to the do keyword. I was sure that if there was a "do" eg.
[snip]
Can someone please enlighten me as to why this particular do is special?
I'm confused -- I see three do's and three end's, don't I?
Why is any of them special?
I work for a software development company that is currently writing an
in-house grammar for parsing Ruby. I've been frustrated by it many,
many, many times. Maybe it's easy to program in, but it's a nightmare to
parse.
As for whether you need to know the language or not, I know as well as
anyone else here, which is not at all. But writing a grammar does
give you a different perspective on a language.
[
"title",
...etc...
"cloud",
].delete_if do |x|
send(x).nil?
end
And then calling the "collect" method for the result of that operation.
Jeff
It is. I mis-read the code and wasted an afternoon. The Ruby editor I
was using didn't highlight the end. as being the end keyword, and I
didn't look too closely. Not that I consider it easy to read anyway.
And Eric, sorry if I mislead you, by example code I meant any code I
could get my hands on to test the grammar on, not one someone wrote as
an example.
Not that it is impossible, but I would guess that trying to
learn to parse a language before you understand the language
is perhaps only going to lead to premature grey hair, or perhaps
no hair at all. Not that anyone on a mailing list bothers
to look in a mirror more than once a month anyway..
Maybe thats just me, ok ok, but anyway..then again, perhaps
writing a parser is a fantastic way to learn a new language,
what the heck to I know..
I like to think I'm an experienced developer, and I like to presume I
know a bit about Ruby by now. I'm interested in parsing and language
processing in general.
Probably _for_ these reasons, I still wouldn't relish the prospect of
writing a Ruby parser. Those Grammarians have bigger, umm, skill-sets,
than me
···
On Mon, 2006-04-10 at 18:58 +0900, Alex Combas wrote:
Not that it is impossible, but I would guess that trying to
learn to parse a language before you understand the language
is perhaps only going to lead to premature grey hair, or perhaps
no hair at all. Not that anyone on a mailing list bothers
to look in a mirror more than once a month anyway..
Maybe thats just me, ok ok, but anyway..then again, perhaps
writing a parser is a fantastic way to learn a new language,
what the heck to I know..
Perhaps but it is not the size of your skillset, but how you apply it,
that matters
···
On 4/10/06, Ross Bamford <rossrt@roscopeco.co.uk> wrote:
On Mon, 2006-04-10 at 18:58 +0900, Alex Combas wrote:
> Not that it is impossible, but I would guess that trying to
> learn to parse a language before you understand the language
> is perhaps only going to lead to premature grey hair, or perhaps
> no hair at all. Not that anyone on a mailing list bothers
> to look in a mirror more than once a month anyway..
>
> Maybe thats just me, ok ok, but anyway..then again, perhaps
> writing a parser is a fantastic way to learn a new language,
> what the heck to I know..
I like to think I'm an experienced developer, and I like to presume I
know a bit about Ruby by now. I'm interested in parsing and language
processing in general.
Probably _for_ these reasons, I still wouldn't relish the prospect of
writing a Ruby parser. Those Grammarians have bigger, umm, skill-sets,
than me