Skip to content

refactor: read_internal_functions_in_yacc #392

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

Merged
merged 1 commit into from
Sep 23, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 67 additions & 42 deletions src/parser/expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,72 @@ module.exports = {
/**
* Reads isset variables
*/
read_isset_variables: function () {
read_isset_variables: function() {
return this.read_function_list(this.read_isset_variable, ",");
},

/*
* Reads internal PHP functions
*/
read_internal_functions_in_yacc: function() {
let result = null;
switch (this.token) {
case this.tok.T_ISSET:
{
result = this.node("isset");
if (this.next().expect("(")) {
this.next();
}
const variables = this.read_isset_variables();
if (this.expect(")")) {
this.next();
}
result = result(variables);
}
break;
case this.tok.T_EMPTY:
{
result = this.node("empty");
if (this.next().expect("(")) {
this.next();
}
const expression = this.read_expr();
if (this.expect(")")) {
this.next();
}
result = result(expression);
}
break;
case this.tok.T_INCLUDE:
result = this.node("include")(false, false, this.next().read_expr());
break;
case this.tok.T_INCLUDE_ONCE:
result = this.node("include")(true, false, this.next().read_expr());
break;
case this.tok.T_EVAL:
{
result = this.node("eval");
if (this.next().expect("(")) {
this.next();
}
const expr = this.read_expr();
if (this.expect(")")) {
this.next();
}
result = result(expr);
}
break;
case this.tok.T_REQUIRE:
result = this.node("include")(false, true, this.next().read_expr());
break;
case this.tok.T_REQUIRE_ONCE:
result = this.node("include")(true, true, this.next().read_expr());
break;
}

return result;
},

/**
* ```ebnf
* Reads an expression
Expand Down Expand Up @@ -224,51 +286,14 @@ module.exports = {
case this.tok.T_NEW:
return this.read_new_expr();

case this.tok.T_ISSET: {
result = this.node("isset");
if (this.next().expect("(")) {
this.next();
}
const variables = this.read_isset_variables();
if (this.expect(")")) {
this.next();
}
return result(variables);
}
case this.tok.T_EMPTY: {
result = this.node("empty");
if (this.next().expect("(")) {
this.next();
}
const expression = this.read_expr();
if (this.expect(")")) {
this.next();
}
return result(expression);
}
case this.tok.T_ISSET:
case this.tok.T_EMPTY:
case this.tok.T_INCLUDE:
return this.node("include")(false, false, this.next().read_expr());

case this.tok.T_INCLUDE_ONCE:
return this.node("include")(true, false, this.next().read_expr());

case this.tok.T_EVAL:
case this.tok.T_REQUIRE:
return this.node("include")(false, true, this.next().read_expr());

case this.tok.T_REQUIRE_ONCE:
return this.node("include")(true, true, this.next().read_expr());

case this.tok.T_EVAL:
result = this.node("eval");
if (this.next().expect("(")) {
this.next();
}
expr = this.read_expr();
if (this.expect(")")) {
this.next();
}
return result(expr);

return this.read_internal_functions_in_yacc();
case this.tok.T_INT_CAST:
return this.read_expr_cast("int");

Expand Down