Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser confused in block form of map with quote operators #905

Closed
p5pRT opened this issue Dec 1, 1999 · 3 comments
Closed

Parser confused in block form of map with quote operators #905

p5pRT opened this issue Dec 1, 1999 · 3 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Dec 1, 1999

Migrated from rt.perl.org#1840 (status was 'resolved')

Searchable as RT1840$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 1, 1999

From m.pearce@inpharmatica.co.uk

[martyn]$ perl -ce 'map {qr"$x",1} @​x'
-e syntax OK
*[martyn]$ perl -ce 'map {qw"$x",1} @​x'
-e syntax OK
*[martyn]$ perl -ce 'map {qx"$x",1} @​x'
syntax error at -e line 1, next char @​
-e had compilation errors.
*[martyn]$ perl -ce 'map {q"$x",1} @​x'
syntax error at -e line 1, next char @​
-e had compilation errors.
*[martyn]$ perl -ce 'map {"$x",1} @​x'
syntax error at -e line 1, next char @​
-e had compilation errors.
*[martyn]$ perl -ce 'map {$x,1} @​x'
-e syntax OK

As shown, map seems to get confused by quotes & quotelikes with a list
return value. Making the list explicit, (e.g., by surrounding with
parens) means the parser can cope, but given the different behaviour of
qr and qq, for example, I think this must be a buglet.

This is also true of 5.005_62 .

Perl Info


Site configuration information for perl 5.00503:

Configured by matthew at Tue Apr 27 16:12:32 BST 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.4, archname=i586-linux
    uname='linux paddington.inpharmatica.co.uk 2.2.4 #5 tue apr 13 16:50:35 bst 1999 i586 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='gcc -pipe', optimize='-O2', gccversion=egcs-2.91.57 19980901 (egcs-1.1 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='gcc -pipe', ldflags ='-s -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/local/common/martyn/Development/inpharmatica/idaps/common/db_access
    /usr/local/common/martyn/Development/inpharmatica/idaps/common/utility
    /usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/load_pdb/pdb_loading/xmas
    /usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/common_data/base_entries
    /usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/common_data/generic_loader
    /usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/common_data/writeables
    /home/victoria/martyn/devel/perl
    /export/data/test/martyn/perl/lib/site_perl/5.005/i586-linux
    /export/data/test/martyn/perl/lib/site_perl/5.005/i586-linux
    /export/data/test/martyn/perl/lib/site_perl/5.005
    /usr/lib/perl5/5.00503/i586-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i586-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/victoria/martyn
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/local/common/java/linux/jdk117_v3/bin:/data/kingsbury/test/martyn/bin:/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/home/victoria/martyn/bin:/data/kingsbury/test/martyn/enlightenment/bin
    PERL5LIB=/usr/local/common/martyn/Development/inpharmatica/idaps/common/db_access:/usr/local/common/martyn/Development/inpharmatica/idaps/common/utility:/usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/load_pdb/pdb_loading/xmas:/usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/common_data/base_entries:/usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/common_data/generic_loader:/usr/local/common/martyn/Development/inpharmatica/idaps/load_seq_data/common_data/writeables:/home/victoria/martyn/devel/perl:/export/data/test/martyn/perl/lib/site_perl/5.005/i586-linux:/export/data/test/martyn/perl/lib/site_perl/5.005
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 1, 1999

From @ysth

In article <199912010856.IAA09792@​kingsbury.inpharmatica.co.uk>,
Martyn Pearce <m.pearce@​inpharmatica.co.uk> wrote​:

[martyn]$ perl -ce 'map {qr"$x",1} @​x'
-e syntax OK
*[martyn]$ perl -ce 'map {qw"$x",1} @​x'
-e syntax OK
*[martyn]$ perl -ce 'map {qx"$x",1} @​x'
syntax error at -e line 1, next char @​
-e had compilation errors.
*[martyn]$ perl -ce 'map {q"$x",1} @​x'
syntax error at -e line 1, next char @​
-e had compilation errors.
*[martyn]$ perl -ce 'map {"$x",1} @​x'
syntax error at -e line 1, next char @​
-e had compilation errors.
*[martyn]$ perl -ce 'map {$x,1} @​x'
-e syntax OK

As shown, map seems to get confused by quotes & quotelikes with a list
return value. Making the list explicit, (e.g., by surrounding with
parens) means the parser can cope, but given the different behaviour of
qr and qq, for example, I think this must be a buglet.

The error is given when these are parsed as map EXPR not map BLOCK
where the EXPR is an anonymous hash and needs a comma following it
(e.g. map {"I$_", "am in a hash"}, @​x).

Whenever you need a map {... , ...} to be unambiguously a BLOCK,
try map {; ... , ... }. As you noted, map {( ... , ...)} seems to
work also.

This leaves unanswered the question of why the different quote ops
give different results.

Also, map EXPR LIST (missing the comma) could give a more helpful error
message.

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 1, 1999

From @TimToady

sthoenna@​efn.org writes​:
: This leaves unanswered the question of why the different quote ops
: give different results.

Probably because qw and qr didn't exist when the {"a",1} dwimmer was written.
Not that I think either of those is likely at the front of an anonymous hash.
I suppose someone might write

  {qw(a 1)}

to mean

  { a => 1 }

but this dwimmer wouldn't pick that up anyway, since it's looking for
a comma or => after the first term.

: Also, map EXPR LIST (missing the comma) could give a more helpful error
: message.

Yes, it could, but not easily. A yacc is an unruly beast.

Larry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant