Giter Site home page Giter Site logo

Comments (3)

mousetraps avatar mousetraps commented on September 1, 2024

Aha! Good catch. Now I understand why the built-in tokenizer produces ArrayCast/BoolCast/etc. Tokens.

We should be able to just remove the call to parseCastExpressionGranular (which I had initially kept around to remain backwards compatible with the old lexer, and potentially to provide some nicer error handling in the future, but now we can just remove it.)
https://github.com/Microsoft/tolerant-php-parser/blob/master/src/Parser.php#L1459

Also, this would make a good first PR

from tolerant-php-parser.

CyrusNajmabadi avatar CyrusNajmabadi commented on September 1, 2024

Another option is to keep all these tokens, and parse like you're doing, but give a message stating that there can't be anything between the ( type and ).

Or, your parser can check the tokens as it is parsing, and only accept this production if there is no trivia between them.

--

Note C# has this for when it sees >>. Those are two separate tokens (so they can be used in List<List<int>>). But in an expression context it gets accepted as 'right shift' when there is no trivia between the tokens. i.e. we would not accept a >/**/> b.

from tolerant-php-parser.

mattacosta avatar mattacosta commented on September 1, 2024
<?php
define('int', 'i am a string');
echo (/**/int);  // prints "i am a string"

There can't be a message because the snippet above is valid code. So if the code were modified to add:

$a = ' really';
echo (/**/int)$a;

...then the error should be an unexpected variable, not an invalid cast error.

Since the parser uses PHP's own tokenizer, the second case would already return a cast token as well, so it's forced into the correct production.

from tolerant-php-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.