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.
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.
[
“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.
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…
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
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
Perhaps but it is not the size of your skillset, but how you apply it,
that matters
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.
Bihal
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.