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

#line directive is messing up my comments #1177

Closed
p5pRT opened this issue Feb 14, 2000 · 1 comment
Closed

#line directive is messing up my comments #1177

p5pRT opened this issue Feb 14, 2000 · 1 comment

Comments

@p5pRT
Copy link

p5pRT commented Feb 14, 2000

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

Searchable as RT2146$

@p5pRT
Copy link
Author

p5pRT commented Feb 14, 2000

From rick@consumercontact.com

I had this comment in the middle of a program​:

# Province abbreviations for the provinces extracted from
# line 2 of the address (why don't people just use these
# in the first place?)

and I was getting warnings like

  Use of uninitialized value at of line 10

where of course line 10 was not where my problem was. Now, this is
working as advertised in perlsyn since the line does match

  /^#\s*line\s+(\d+)\s*(?​:\s"([^"]*)")?/

but I think it would make more sense if the filter was also anchored at
the end​:

  /^#\s*line\s+(\d+)\s*(?​:\s"([^"]*)")?$/

When I went to patch this I found a few other novelties​:

#!/usr/local/bin/perl -w

# 25 "foo"
warn 'No "line" here';

# line 50
warn '/\s+/ != / /';

# line 200 -- my favourite
warn "I don't think I'm really";
__END__
No "line" here at foo line 25.
/\s+/ != / / at foo line 28.
I don't think I'm really at -- line 200.

This patch on 5.5.650 fixes all of these and passes all tests that it
passed before. I can add more tests if someone tells me where to put
them (base/lex.t?).

I don't program in C much so this code could probably be improved.

Rick

*** perl5.5.650/toke.c.old Mon Feb 14 11​:11​:38 2000
--- perl5.5.650/toke.c Mon Feb 14 14​:15​:02 2000
***************
*** 464,480 ****
  dTHR;
  char *t;
  char *n;
  char ch;
- int sawline = 0;
 
  CopLINE_inc(PL_curcop);
  if (*s++ != '#')
  return;
  while (*s == ' ' || *s == '\t') s++;
! if (strnEQ(s, "line ", 5)) {
! s += 5;
! sawline = 1;
! }
  if (!isDIGIT(*s))
  return;
  n = s;
--- 464,485 ----
  dTHR;
  char *t;
  char *n;
+ char *e;
  char ch;
 
  CopLINE_inc(PL_curcop);
  if (*s++ != '#')
  return;
  while (*s == ' ' || *s == '\t') s++;
! if (strnEQ(s, "line", 4))
! s += 4;
! else
! return;
! if (*s == ' ' || *s == '\t')
! s++;
! else
! return;
! while (*s == ' ' || *s == '\t') s++;
  if (!isDIGIT(*s))
  return;
  n = s;
***************
*** 482,494 ****
  s++;
  while (*s == ' ' || *s == '\t')
  s++;
! if (*s == '"' && (t = strchr(s+1, '"')))
  s++;
  else {
- if (!sawline)
- return; /* false alarm */
  for (t = s; !isSPACE(*t); t++) ;
  }
  ch = *t;
  *t = '\0';
  if (t - s > 0)
--- 487,505 ----
  s++;
  while (*s == ' ' || *s == '\t')
  s++;
! if (*s == '"' && (t = strchr(s+1, '"'))) {
  s++;
+ e = t + 1;
+ }
  else {
  for (t = s; !isSPACE(*t); t++) ;
+ e = t;
  }
+ while (*e == ' ' || *e == '\t' || *e == '\r' || *e == '\f')
+ e++;
+ if (*e != '\n' && *e != '\0')
+ return; /* false alarm */
+
  ch = *t;
  *t = '\0';
  if (t - s > 0)

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

No branches or pull requests

1 participant