Hi, I working on syntax highlighting for ED4W and have problem with <<
because it has three uses.
<< operator
<< HERE Doc
class << Name - Singleton Class
The problem is determining if << starts a Here Doc. It is easy to handle
class<<Name is this regard, but I can’t see how you can work out << in
the following:
Ared = “mary”
angy = “bill”
angy <<Ared # does this start a Here Doc or is it operator <<
print <<Ared # as above.
Some editors (kate and vim, for example) assume the presence of a
whitespace
after the << in the operator case:
a=[]
s=“abc” #this gets highlighted as a HERE Doc
a<<s
#this gets highlighted as an operator
a<< s
Stefano
Stefano,
Thanks, but that isn’t how the Ruby interpreter works, so this is really
a hack that may or may not work with real code.
I can just do the same thing, but if possible I’d like a ‘correct’
solution.
I’ve been looking at all of the Ruby Editors on Windows and am surprised
at how poorly they handle Ruby syntax. I would never release a product
like these.
Ruby knows angy is a local variable, so that the interpreter consider
it is more likely a shift operator than a here-doc. If you want to
disambiguate, use parentheses.
I made an error there. “angy” followed by a String doesn’t make any
sense. It
works very well if written in in a senseful way.
But… - there is one thing I really don’t understand in the first
example. Ruby
recognizes “EOT” as an uninitialized constant, because “<<” ist
interpreted as
shift operator. But why is an open here-doc string recognized in line
008:0" in
the example?
But… - there is one thing I really don’t understand in the first example. Ruby recognizes “EOT” as an uninitialized constant,
because “<<” ist interpreted as shift operator. But why is an open here-doc string recognized in line 008:0" in the example?
Ruby knows angy is a local variable, so that the interpreter consider
it is more likely a shift operator than a here-doc. If you want to
disambiguate, use parentheses.
On Mon, 29 Jan 2007, Wolfgang Nádasi-Donner wrote:
But… - there is one thing I really don’t understand in the first example.
Ruby recognizes “EOT” as an uninitialized constant, because “<<” ist
interpreted as shift operator. But why is an open here-doc string recognized
in line 008:0" in the example?
I’m not quite sure either, but it seems to interpret <<EOT as the
start of a heredoc, and then later realize that it couldn’t have been.
Compare what happens if there’s a space before EOT:
irb(main):012:0> a = 1
=> 1
irb(main):013:0> a << EOT
NameError: uninitialized constant EOT
from (irb):13
Thanks to everyone for their replies. It looks like the only practical
way for me handle this is to assume << is an operator if a space follows
it, otherwise as a Here Doc.
Fortunately this is the only issue I’ve come across so far re. IDE
syntax highlighting and I’m a fair way down the track.
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
irb(main):003:0" ddd
Compare what happens if there’s a space before EOT:
irb(main):012:0> a = 1
=> 1
irb(main):013:0> a << EOT
NameError: uninitialized constant EOT
from (irb):13
I suspect part of the problem is that irb lexes your input to determine
the continuation prompt (and indeed if it should allow multiple lines of
input before evalling). IOW, irb has the same problem our poor text
editor’s do
Thanks to everyone for their replies. It looks like the only practical
way for me handle this is to assume << is an operator if a space follows
it, otherwise as a Here Doc.
FWIW, here’s how I implemented it in the ruby mode for jEdit. It
recognizes the following as a here document:
The << characters, optionally followed by a - character, followed
by printable characters enclosed in single or double quotes. E.g.
<<‘hello’
<<-‘thingy67%’
<<“foobar $”
<<-“boofar @”
The << characters, optionally followed by a - character, followed
by letters and/or underscores. E.g.
<<Hello_there
<<-Howdy
Looking at this now, that second case should probably have been
letters and numbers and underscores, but not starting with a number,
i.e. a valid identifier.