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

PHP mode: False syntax error #2232

Closed
Cyphis opened this issue Nov 11, 2014 · 2 comments
Closed

PHP mode: False syntax error #2232

Cyphis opened this issue Nov 11, 2014 · 2 comments

Comments

@Cyphis
Copy link

Cyphis commented Nov 11, 2014

The editor returns a false syntax error when a certain case statement is used with a switch statement. "Syntax error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}'"

Example:

<?php
session_start();
ini_set('display_errors', -1);

if(!isset($_SESSION['secure_token'], $_POST['action'], $_POST['token']))
    die(json_encode(array("error" => "missing vars")));

require("functions.php");

if($_POST['token'] != $_SESSION['secure_token']) {
    add_error("CSRF", $_SERVER['SCRIPT_NAME']);
    $_SESSION['secure_token'] = create_secure_token();
    die(json_encode(array("error" => "invalid session")));
}

switch($_POST['action']) {

    // Syntax error occurs on the line below - it is valid syntax normally used for comparisons
    case("open_editor"):

    // rest of code irrelevant

}
?>
@nightwing
Copy link
Member

Ace uses https://github.com/niklasvh/php.js/ for parsing php, but sadly php.js doesn't handle some of less used syntax constructs.

@danyaPostfactum
Copy link
Contributor

This is because of incorrect regex: https://github.com/niklasvh/php.js/blob/master/src/parser/lexer.js#L173

In general, lexer should be completely rewritten. May be lexer generator should be used.

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

3 participants