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

re2c 1.0.2 keeps the initial "/" at the beginning of an docblock (DCOMMENT-Token) #31

Closed
chilimatic opened this issue Oct 31, 2017 · 4 comments
Assignees

Comments

@chilimatic
Copy link

chilimatic commented Oct 31, 2017

Hey,

relates to zephir-lang/zephir#1591

I got an issue and I cannot pinpoint it, I already solved it but it's a hack.
I am not sure if even another user is affected, it could just be my setup.

The reason why I put it here an not the zephir compiler is that I didn't want to invest more than 5 hours into reading/debugging the C/C++ and PHP code, esp since I am not used to re2c syntax.

But first things first.
versions zephir_parser / zephir (i tried different tags with zephir it doesn't matter)

zephir parser Tag/v1.1.0
Zephir version 0.10.4-11e39849b0 

lib / program versions

re2c 1.0.2

gcc (GCC) 5.4.0

PHP 7.1.11 (cli) (built: Oct 25 2017 18:30:55) ( NTS )

Error log (shortened because it's the same error for all files)

/home/j/development/tools/php/cphalcon/ext/phalcon/exception.zep.c:18:2: error: stray ‘\’ in program
  * Phalcon\Exception
  ^
/home/j/development/tools/php/cphalcon/ext/phalcon/exception.zep.c:18:12: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Exception’
  * Phalcon\Exception
            ^
/home/j/development/tools/php/cphalcon/ext/phalcon/exception.zep.c:18:12: error: unknown type name ‘Exception’
....

The exception.zep.c compiled source code so the error is obvious:

#ifdef HAVE_CONFIG_H
#include "../ext_config.h"
#endif

#include <php.h>
#include "../php_ext.h"
#include "../ext.h"

#include <Zend/zend_operators.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>

#include "kernel/main.h"


//**
 * Phalcon\Exception
 *
 * All framework exceptions should use or extend this exception
 */
ZEPHIR_INIT_CLASS(Phalcon_Exception) {

	ZEPHIR_REGISTER_CLASS_EX(Phalcon, Exception, phalcon, exception, zend_exception_get_default(TSRMLS_C), NULL, 0);

	return SUCCESS;

}

as you can see -> there are two slashes for the doc block comment.

The scanner keeps the beginning slash in /** for the DCOMMENT token which your compiler does not expect.

the hacky fix is pretty simple in zephir/Compilerfile

    /**
     * @param array $topStatement
     */
    public function compileComment(CompilationContext $compilationContext, $topStatement)
    {
        $compilationContext->codePrinter->output('/' . ltrim($topStatement['value'], '/') . '/');
    }

this does not affect the behaviour and works for me locally but fixing symptoms is not a reasonable approach.

Since I cannot find anyone else complaining about this I assume this a local setup issue but it's still better to report such behavior than leave it unchecked.

Too me this is a low prio bug esp since I fixed it by a small hack in the compiler.

@chilimatic chilimatic changed the title adding an extra / in front of the docblock (zephir) re2c v1.1.0 keeps the initial "/" at the beginning of an docblock (DCOMMENT-Token) Oct 31, 2017
@sergeyklay sergeyklay self-assigned this Nov 3, 2017
@sergeyklay sergeyklay changed the title re2c v1.1.0 keeps the initial "/" at the beginning of an docblock (DCOMMENT-Token) re2c 1.0.2 keeps the initial "/" at the beginning of an docblock (DCOMMENT-Token) Nov 4, 2017
sergeyklay added a commit that referenced this issue Nov 4, 2017
Don't concatenate result output in tests to avoid confusion.

Correct parser output for the following text:
```
/**
 * Comment
 */
```

is:

```
/**
 * Comment
 *
```

Related issues:

* #31
* zephir-lang/zephir#1591
* phalcon/cphalcon#13140
sergeyklay added a commit that referenced this issue Nov 4, 2017
Don't concatenate result output with "/" in tests
to avoid confusion. Correct parser output for the
following text:

  /**
   * Comment
   */

is:

  **
  * Comment
  *

Related issues:

* #31
* zephir-lang/zephir#1591
* phalcon/cphalcon#13140

8ae4b82
sergeyklay added a commit that referenced this issue Nov 4, 2017
Actually this is temporary workaround to be able try latest changes
of re2c >= 1.x.

Related issues:

* skvadrik/re2c#197
* #31
* zephir-lang/zephir#1591
* phalcon/cphalcon#13140
@sergeyklay
Copy link
Contributor

@chilimatic I've prepared a patch for Zephir Parser to work with re2c >= 1.0. Could you please reinstall Zephir Parser from development branch?

@chilimatic
Copy link
Author

@sergeyklay yes ofc I was closely following these changes anyway. :)

@chilimatic
Copy link
Author

@sergeyklay works fine for me.

@sergeyklay
Copy link
Contributor

sergeyklay commented Nov 9, 2017

Fixed in the latest stable release. Feel free to open a new issue if the problem appears again. Thank you for the report, and for helping us make Zephir Parser better.

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

2 participants