Skip to content

Commit

Permalink
Merge pull request #14410 from phalcon/fix/issue-14288-volt-set-is
Browse files Browse the repository at this point in the history
Volt: Corrected syntax recognize for "set" and "is" keywords
  • Loading branch information
sergeyklay authored Sep 24, 2019
2 parents 41d398b + 67d6c8d commit d9c6b18
Show file tree
Hide file tree
Showing 17 changed files with 1,132 additions and 745 deletions.
4 changes: 3 additions & 1 deletion .ci/run-volt-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# For the full copyright and license information, please view the
# LICENSE.txt file that was distributed with this source code.

set -e

NO_INTERACTION=1
REPORT_EXIT_STATUS=1
TEST_PHP_EXECUTABLE="$(phpenv which php)"
Expand All @@ -25,7 +27,7 @@ php ./ext/run-tests.php \
-d "report_zend_debug=0" \
-d "zend.assertions=1" \
-d "extension=$(php-config --extension-dir)/psr.so" \
-d "extension=${TRAVIS_BUILD_DIR}/ext/modules/phalcon.so" \
-d "extension=$(pwd)/ext/modules/phalcon.so" \
--offline \
--show-diff \
--set-timeout 120 \
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# [4.0.0-rc.2](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-rc.2) (2019-XX-XX)
## Fixed
- Fixed `Phalcon\Mvc\View\Engine\Volt\Compiler::parse()` Corrected syntax recognize for "set" keyword. [#14288](https://github.com/phalcon/cphalcon/issues/14288)
- Fixed `Phalcon\Mvc\View\Engine\Volt\Compiler::parse()` Corrected syntax recognize for "is" keyword. [#11683](https://github.com/phalcon/cphalcon/issues/11683)

# [4.0.0-rc.1](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-rc.1) (2019-09-23)

## Added
Expand Down
12 changes: 7 additions & 5 deletions ext/phalcon/mvc/view/engine/volt/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_pa
token.value = NULL;
token.len = 0;

/* To enable parser tracing decalre "#undef NDEBUG" in the lemon file */
#ifndef NDEBUG
phvolt_Trace(stderr, "[PARSER] ");
#endif
while (0 <= (scanner_status = phvolt_get_token(state, &token))) {

state->active_token = token.opcode;
Expand Down Expand Up @@ -565,10 +569,8 @@ int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_pa
case PHVOLT_T_DEFAULT:
if (state->switch_level != 0) {
phvolt_(phvolt_parser, PHVOLT_DEFAULT, NULL, parser_status);
efree(token.value);
} else {
// TODO: Make this better.
// Issue: https://github.com/phalcon/cphalcon/issues/13242
// Introduced: https://github.com/phalcon/cphalcon/pull/13130
phvolt_parse_with_token(phvolt_parser, PHVOLT_T_IDENTIFIER, PHVOLT_IDENTIFIER, &token, parser_status);
}

Expand Down Expand Up @@ -821,8 +823,6 @@ int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_pa
}
}

phvolt_Free(phvolt_parser, phvolt_wrapper_free);

if (status != FAILURE) {
if (parser_status->status == PHVOLT_PARSING_OK) {
if (Z_TYPE(parser_status->ret) != IS_UNDEF) {
Expand All @@ -833,6 +833,8 @@ int phvolt_internal_parse_view(zval **result, zval *view_code, zval *template_pa
}
}

phvolt_Free(phvolt_parser, phvolt_wrapper_free);

efree(parser_status);
efree(state);

Expand Down
47 changes: 29 additions & 18 deletions ext/phalcon/mvc/view/engine/volt/lemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
# endif
#endif

#ifdef __WIN32__
#ifdef __cplusplus
extern "C" {
#endif
extern int access(const char *path, int mode);
#ifdef __cplusplus
}
#endif
#else
#include <unistd.h>
#endif

/* #define PRIVATE static */
#define PRIVATE

Expand Down Expand Up @@ -570,7 +582,7 @@ int line;
*/

/* Find a precedence symbol of every rule in the grammar.
**
**
** Those rules which have a precedence symbol coded in the input
** grammar using the "[symbol]" construct will already have the
** rp->precsym field filled. Other rules take as their precedence
Expand Down Expand Up @@ -860,7 +872,7 @@ struct lemon *lemp;
cfp->status = INCOMPLETE;
}
}

do{
progress = 0;
for(i=0; i<lemp->nstate; i++){
Expand Down Expand Up @@ -892,7 +904,7 @@ struct lemon *lemp;
struct symbol *sp;
struct rule *rp;

/* Add all of the reduce actions
/* Add all of the reduce actions
** A reduce action is added for each element of the followset of
** a configuration which has its dot at the extreme right.
*/
Expand Down Expand Up @@ -1369,7 +1381,7 @@ char **argv;
OptInit(argv,options,stderr);
if( version ){
printf("Lemon version 1.0\n");
exit(0);
exit(0);
}
if( OptNArgs()!=1 ){
fprintf(stderr,"Exactly one filename argument is required.\n");
Expand Down Expand Up @@ -2052,7 +2064,7 @@ to follow the previous rule.");
case IN_RHS:
if( x[0]=='.' ){
struct rule *rp;
rp = (struct rule *)malloc( sizeof(struct rule) +
rp = (struct rule *)malloc( sizeof(struct rule) +
sizeof(struct symbol*)*psp->nrhs + sizeof(char*)*psp->nrhs );
if( rp==0 ){
ErrorMsg(psp->filename,psp->tokenlineno,
Expand Down Expand Up @@ -2615,7 +2627,7 @@ char *mode;
return fp;
}

/* Duplicate the input file without comments and without actions
/* Duplicate the input file without comments and without actions
** on rules */
void Reprint(lemp)
struct lemon *lemp;
Expand Down Expand Up @@ -2795,7 +2807,6 @@ int modemask;
char *pathlist;
char *path,*cp;
char c;
extern int access();

#ifdef __WIN32__
cp = strrchr(argv0,'\\');
Expand Down Expand Up @@ -3129,7 +3140,7 @@ PRIVATE char *translate_code(struct lemon *lemp, struct rule *rp){
rp->code = Strsafe(cp);
}

/*
/*
** Generate code which executes when the rule "rp" is reduced. Write
** the code to "out". Make sure lineno stays up-to-date.
*/
Expand Down Expand Up @@ -3529,7 +3540,7 @@ int mhflag; /* Output in makeheaders format if true */

/* Output the yy_shift_ofst[] table */
fprintf(out, "#define YY_SHIFT_USE_DFLT (%d)\n", mnTknOfst-1); lineno++;
fprintf(out, "static %s yy_shift_ofst[] = {\n",
fprintf(out, "static %s yy_shift_ofst[] = {\n",
minimum_size_type(mnTknOfst-1, mxTknOfst)); lineno++;
n = lemp->nstate;
for(i=j=0; i<n; i++){
Expand All @@ -3550,7 +3561,7 @@ int mhflag; /* Output in makeheaders format if true */

/* Output the yy_reduce_ofst[] table */
fprintf(out, "#define YY_REDUCE_USE_DFLT (%d)\n", mnNtOfst-1); lineno++;
fprintf(out, "static %s yy_reduce_ofst[] = {\n",
fprintf(out, "static %s yy_reduce_ofst[] = {\n",
minimum_size_type(mnNtOfst-1, mxNtOfst)); lineno++;
n = lemp->nstate;
for(i=j=0; i<n; i++){
Expand Down Expand Up @@ -3625,7 +3636,7 @@ int mhflag; /* Output in makeheaders format if true */
tplt_xfer(lemp->name,in,out,&lineno);

/* Generate code which executes every time a symbol is popped from
** the stack while processing errors or while destroying the parser.
** the stack while processing errors or while destroying the parser.
** (In other words, generate the %destructor actions)
*/
if( lemp->tokendest ){
Expand Down Expand Up @@ -3679,7 +3690,7 @@ int mhflag; /* Output in makeheaders format if true */
tplt_print(out,lemp,lemp->overflow,lemp->overflowln,&lineno);
tplt_xfer(lemp->name,in,out,&lineno);

/* Generate the table of rule information
/* Generate the table of rule information
**
** Note: This code depends on the fact that rules are number
** sequentually beginning with 0.
Expand Down Expand Up @@ -3757,7 +3768,7 @@ struct lemon *lemp;
for(i=1; i<lemp->nterminal; i++){
fprintf(out,"#define %s%-30s %2d\n",prefix,lemp->symbols[i]->name,i);
}
fclose(out);
fclose(out);
}
return;
}
Expand Down Expand Up @@ -3798,7 +3809,7 @@ struct lemon *lemp;
rbest = rp;
}
}

/* Do not make a default if the number of rules to default
** is not at least 2 */
if( nbest<2 ) continue;
Expand Down Expand Up @@ -3949,7 +3960,7 @@ void Strsafe_init(){
if( x1a ){
x1a->size = 1024;
x1a->count = 0;
x1a->tbl = (x1node*)malloc(
x1a->tbl = (x1node*)malloc(
(sizeof(x1node) + sizeof(x1node*))*1024 );
if( x1a->tbl==0 ){
free(x1a);
Expand Down Expand Up @@ -4111,7 +4122,7 @@ void Symbol_init(){
if( x2a ){
x2a->size = 128;
x2a->count = 0;
x2a->tbl = (x2node*)malloc(
x2a->tbl = (x2node*)malloc(
(sizeof(x2node) + sizeof(x2node*))*128 );
if( x2a->tbl==0 ){
free(x2a);
Expand Down Expand Up @@ -4317,7 +4328,7 @@ void State_init(){
if( x3a ){
x3a->size = 128;
x3a->count = 0;
x3a->tbl = (x3node*)malloc(
x3a->tbl = (x3node*)malloc(
(sizeof(x3node) + sizeof(x3node*))*128 );
if( x3a->tbl==0 ){
free(x3a);
Expand Down Expand Up @@ -4463,7 +4474,7 @@ void Configtable_init(){
if( x4a ){
x4a->size = 64;
x4a->count = 0;
x4a->tbl = (x4node*)malloc(
x4a->tbl = (x4node*)malloc(
(sizeof(x4node) + sizeof(x4node*))*64 );
if( x4a->tbl==0 ){
free(x4a);
Expand Down
Loading

0 comments on commit d9c6b18

Please sign in to comment.