[PHP-DEV] Patch: Nested comments

2001-11-27 Thread Anders Johannsen

This patch allows for nested 'C-style' comments, which can be useful
especially while debugging.

?php
/* comments
/* now /* nest */ */

/*/*/*/*
*/*/*/*/
*/
?

Since comments are handled purely lexical, there should be virtually no
performance hit.

The following two examples show how errors are handled:

1)
?php
/*
*/
*/
?

2)
?php
/*
/*
*/
?

Ad 1) This will yield a zend_error(E_COMPILE_ERROR,Invalid nesting of
comments) on the
last line. Unpatched, a parse error is the most likely result.

Ad 2) A zend_error(E_COMPILE_WARNING, unterminated comment starting line
%d, CG(comment_start_line)) is raised.

The attached patch is against latest CVS

Best regards,
Anders Johannsen
--
[EMAIL PROTECTED]

Index: zend_globals.h
===
RCS file: /repository/Zend/zend_globals.h,v
retrieving revision 1.80
diff -u -r1.80 zend_globals.h
--- zend_globals.h  2001/10/23 01:19:16 1.80
+++ zend_globals.h  2001/11/27 10:08:06
@@ -82,6 +82,7 @@
int comment_start_line;
char *heredoc;
int heredoc_len;
+unsigned int comment_nest_level;

zend_op_array *active_op_array;

Index: zend_language_scanner.l
===
RCS file: /repository/Zend/zend_language_scanner.l,v
retrieving revision 1.40
diff -u -r1.40 zend_language_scanner.l
--- zend_language_scanner.l 2001/09/22 00:06:27 1.40
+++ zend_language_scanner.l 2001/11/27 10:08:07
@@ -1,5 +1,4 @@
 %{
-
 /*

+--+
| Zend
Engine  |
@@ -125,6 +124,7 @@
 {
CG(heredoc) = NULL;
CG(heredoc_len)=0;
+   CG(comment_nest_level)=0;
 }


@@ -1057,24 +1057,39 @@
}
 }

+ST_IN_SCRIPTING*/ {
+   zend_error(E_COMPILE_ERROR,Invalid nesting of comments);
+}
+
 ST_IN_SCRIPTING/* {
CG(comment_start_line) = CG(zend_lineno);
BEGIN(ST_COMMENT);
+CG(comment_nest_level) = 1;
yymore();
 }

-
-ST_COMMENT[^*]+ {
+ST_COMMENT[^/*]+ {
yymore();
 }

+ST_COMMENT/* {
+CG(comment_nest_level)++;
+yymore();
+}
+
 ST_COMMENT*/ {
-   HANDLE_NEWLINES(yytext, yyleng);
-   BEGIN(ST_IN_SCRIPTING);
-   return T_COMMENT;
+CG(comment_nest_level)--;
+
+if (CG(comment_nest_level) == 0) {
+HANDLE_NEWLINES(yytext, yyleng);
+   BEGIN(ST_IN_SCRIPTING);
+   return T_COMMENT;
+} else {
+ yymore();
+}
 }

-ST_COMMENT* {
+ST_COMMENT*|/ {
yymore();
 }





-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Patch: Nested comments

2001-11-27 Thread Anders Johannsen

 /*

 ?
 Html code
 ?php

 */

 Would comment out the html code too..

I believe the Html code is ignored.

Best regards,
Anders Johannsen
--
[EMAIL PROTECTED]



-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Patch: Nested comments

2001-11-27 Thread Anders Johannsen

On Tue, 2001-11-27 at 21:16, Andi Gutmans wrote:

 It's not like I don't want to keep BC as much as possible for ZE2 too. 

I'm not sure how as much as possible differs from not at all in this
context? If code developed for ZE2 cannot run on ZE1, it should not
matter *how much* it is incompatible.

The submitted patch does not break any existing code (the same way one
would expect ZE2 to run all ZE1 code, but not necessarily the other way
around)

/A


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Patch: Nested comments

2001-11-27 Thread Anders Johannsen

On Tue, 2001-11-27 at 21:49, Stig Venaas wrote:
 On Tue, Nov 27, 2001 at 09:41:46PM +0100, Anders Johannsen wrote:
  The submitted patch does not break any existing code

Perhaps I should have added: ... unless you have a really silly
commenting style.

 Okay, it is a bit weird, but people do things like this. Wouldn't
 those scripts break?

They would break, warning the user about an unterminated comment.
However, I suspect that it will affect only very few people.

/A


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Range literal (proposal)

2001-09-03 Thread Anders Johannsen

It would be nice addition to have a Range literal in PHP. The range()
implements the functionality in part, but in an extremly ineffecient
manner. What I would like to see, is a builtin Range 'type', which only
holds the start and end points.

Let's consider some practical applications:

1:
$str = this is a test string; 
$str[0...4] #= this

2:
$arr = ['this', 'is', 'a', 'test']
$arr[2..4]  #= ['is', 'a']

3:
$str = hello world;
$offset = 6;
$end = 11;

substr($str, $offset...$end);  #= world

4:
foreach ('a'..'d' as $chr) {
print $chr;
}
# Prints a,b,c 

5:
$range = 5...10;

range_first($range);#= 5
range_last($range); #= 10
range_size($range); #= 6

6:
$range = range(0, 3);

for ($i = 0; $i == $range; $++) {
print $i;   
}

# Prints 0, 1, 2, 3

$i = 0;
while ($i == $range) {
print $i++;
}

# Prints 0, 1, 2, 3

An implementation of my suggestion would obviously require some work
(hacking?) inside the Zend Engine, which, I believe, is best left up to
people with a understanding of its internals (which rules me out).

Let me know what you think.

Btw: Is there a PHP mechanism for language improvement suggestions (such as
Perl's RFC or Ruby's RCR)?

/A
--
Anders Johannsen, Denmark

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Buildproblems in latest CVS

2001-08-21 Thread Anders Johannsen

On 21 Aug 2001 12:57:03 +0200, [EMAIL PROTECTED] wrote:
 On Thu, Aug 09, 2001 at 02:40:19AM +0200, Anders Johannsen wrote:
  I'am experiencing problems building PHP from the latest cvs. The errors
  occur when running 'buildconf'. The box is a Debian/unstable. Autoconf,
  automake and libtool versions seems to suffice.
  
  aj@uranos% ./buildconf
  buildconf: checking installation...
  buildconf: autoconf version 2.52 (ok)
  buildconf: automake version 1.4-p4 (ok)
  buildconf: libtool version 1.4b
 
 Please check if your auto* combination works with the patch provided in:

Except for one warning, it works excellent:

aj@uranos% time ./buildconf 
buildconf: checking installation...
buildconf: autoconf version 2.52 (ok)
buildconf: automake version 1.4-p4 (ok)
buildconf: libtool version 1.4b

1996, (ok)
rebuilding Makefile templates
automake: configure.in: installing `Zend/ylwrap'
rebuilding configure
configure.in:124: warning: AC_PROG_LEX invoked multiple times
rebuilding acconfig.h
rebuilding main/php_config.h.in
./buildconf  52.90s user 5.10s system 88% cpu 1:05.68 total

However it takes forever to run?

/A



-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] Buildproblems in latest CVS

2001-08-09 Thread Anders Johannsen

In article [EMAIL PROTECTED],
Jani Taskinen [EMAIL PROTECTED] wrote:

 Well, the latest CVS only supports these:
 
 libtool 1.4
 autoconf 2.13
 automake 1.4
 
 I think you only need to downgrade autoconf.

That was my original thought, however a downgrade yields:

aj@uranos% ./buildconf
buildconf: checking installation...
buildconf: autoconf version 2.13 (ok)
buildconf: automake version 1.4-p4 (ok)
buildconf: libtool version 1.4b

1996, (ok)
rebuilding Makefile templates
automake: configure.in: installing `Zend/ylwrap'
rebuilding configure
FATAL ERROR: Autoconf version 2.50 or higher is required for this script
rebuilding acconfig.h
rebuilding main/php_config.h.in
FATAL ERROR: Autoconf version 2.50 or higher is required for this script

Best regards
Anders Johannsen

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Buildproblems in latest CVS

2001-08-08 Thread Anders Johannsen

I'am experiencing problems building PHP from the latest cvs. The errors
occur when running 'buildconf'. The box is a Debian/unstable. Autoconf,
automake and libtool versions seems to suffice.

aj@uranos% ./buildconf
buildconf: checking installation...
buildconf: autoconf version 2.52 (ok)
buildconf: automake version 1.4-p4 (ok)
buildconf: libtool version 1.4b

1996, (ok)
rebuilding Makefile templates
automake: configure.in: installing `Zend/ylwrap'
rebuilding configure
./aclocal.m4:943: error: m4_defn: undefined macro: _m4_divert_diversion
./aclocal.m4:472: PHP_SUBST is expanded from...
./aclocal.m4:943: the top level
rebuilding acconfig.h
rebuilding main/php_config.h.in
./aclocal.m4:943: error: m4_defn: undefined macro: _m4_divert_diversion
./aclocal.m4:472: PHP_SUBST is expanded from...
./aclocal.m4:943: the top level
autoconf2.50: tracing failed
aj@uranos%  

Any help is much appreciated.

/A

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]