Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Perl mode and y=>

13 views
Skip to first unread message

Mark Tilford

unread,
Sep 27, 2011, 1:51:08 PM9/27/11
to help-gn...@gnu.org
For some reason, Perl mode behaves oddly whenever it hits the syntax
"y => " (it thinks stuff after that is still quoted), which is used
frequently in Imager (
http://search.cpan.org/~tonyc/Imager-0.85/lib/Imager/Draw.pod#getscanline()
)
I have to replace that with "'y' =>" or "'y', ". "x =>" or "z =>"
does not cause this problem.

1) Any idea why?
2) Could somebody fix this?

S Boucher

unread,
Sep 27, 2011, 3:26:09 PM9/27/11
to Mark Tilford, help-gn...@gnu.org

----- Original Message -----

> For some reason, Perl mode behaves oddly

Perl is... odd.  I've used perl for a long time with emacs.  You just learn to live with the problems.

Perl's syntax has too many cases of context sensitive interpretations of characters.  It's just hell to make emacs capable to deal with all this.  I suspect Perl is the only software capable of parsing perl code :-)

If it's any consolation, we managed to convince Larry Wall back in the days when perl 5 was being "designed" to not follow Tom Christiansen's idea of what the scope operator should be. Tom wanted the single quote. Most prefered C++'s :: for familiarity and friendlyness to parsers.  If you think things are bad now, imagine having the single quote has the scope operator :-)

John Bokma

unread,
Sep 27, 2011, 6:01:12 PM9/27/11
to
Mark Tilford <ralphm...@gmail.com> writes:

> For some reason, Perl mode

Which one? IIRC there are two. I use cperl-mode and don't have that
problem.

y => $y

Shows as how I expect it.


--
John Bokma j3b

Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html

Stefan Monnier

unread,
Sep 28, 2011, 12:40:38 AM9/28/11
to
Because `y' is a special command (an alias for the special command `tr'), so
yXblablaXtrutruX is an instruction, and that goes for any choice of X,
pretty much, including y=blabla=trutru=. Same goes for `s' instead of `y'.

> 2) Could somebody fix this?

The patch below should fix it (so "=>" is treated specially after things
like `y' and `s', which seems to be what Perl does to disambiguate the
syntax). It'll be in Emacs-24.


Stefan


=== modified file 'lisp/progmodes/perl-mode.el'
--- lisp/progmodes/perl-mode.el 2011-05-08 18:23:11 +0000
+++ lisp/progmodes/perl-mode.el 2011-09-28 01:53:11 +0000
@@ -304,11 +304,12 @@
(put-text-property (match-beginning 2) (match-end 2)
'syntax-table (string-to-syntax "\""))
(perl-syntax-propertize-special-constructs end)))))
- ("\\(^\\|[?:.,;=!~({[ \t]\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\([^])}> \n\t]\\)"
+ ("\\(^\\|[?:.,;=!~({[ \t]\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\(?:\\([^])}>= \n\t]\\)\\|\\(?3:=\\)[^>]\\)"
;; Nasty cases:
;; /foo/m $a->m $#m $m @m %m
;; \s (appears often in regexps).
;; -s file
+ ;; y => 3
;; sub tr {...}
(3 (ignore
(if (save-excursion (goto-char (match-beginning 0))



LanX

unread,
Sep 29, 2011, 5:33:52 AM9/29/11
to

> > For some reason, Perl mode behaves oddly
>
> Perl is... odd.  I've used perl for a long time with emacs.  You just learn to live with the problems.

Sorry, but I don't like these kind of complaints ...

The OP wants to use a special Perl DWIM feature called "autoquoting",
meaning that in a "('key', value)" pair with "fat-comma" '=>' the
quotes are optional on the LHS : "(key => value)".

But if you put a variable or function on the LHS it will be evaluated
to the key:

$key="k"; %h=($key => 1)

And IMHO the parsing rules are not too complicated: "check for
following =>".

At least cperl-mode gets it right.

Now how do other languages solve this problem?

AFAI can see Python has nothing like autoquoting", everything unquoted
is evaluated:

x={"a":1}

And JS has autoquoting, but the LHS is _never_ evaluated:

x={a:1}

You can't make an omelette without breaking eggs.

If you want python's semantics you need python's restrictions and put
quotes!


> Perl's syntax has too many cases of context sensitive interpretations of characters.  It's just hell to make emacs capable to deal with all this.  I suspect Perl is the only software capable of parsing perl code :-)

True unfortunately the grammar doesn't have a formal specification,
but there IS a module on CPAN called PPI, doing the parsing extremely
well.

> If it's any consolation, we managed to convince Larry Wall back in the days when perl 5 was being "designed" to not follow Tom Christiansen's idea of what the scope operator should be. Tom wanted the single quote. Most prefered C++'s :: for familiarity and friendlyness to parsers.  If you think things are bad now, imagine having the single quote has the scope operator :-)

The simple quote was the Perl4 standard and is for compatibility
reasons still supported in Perl5.
But I think it will be deprecated soon.

IIRC the perldoc cites "problems with emacs" for changing this
behaviour. :)

Cheers
Rolf
0 new messages