Giter Club home page Giter Club logo

Comments (8)

rintaro avatar rintaro commented on September 15, 2024

CC: @nkcsgexi @akyrtzi

from swift-syntax.

akyrtzi avatar akyrtzi commented on September 15, 2024

Seems good idea to me. The benefit is you will be able to structurally distinguish what kind of quotes (multiline or single) were used, instead of searching the string literal text string in order to distinguish.

If we do this we should probably get rid of 'string_literal' token kind and use 'string_segment' token kind for the non-interpolation case as well.

from swift-syntax.

swift-ci avatar swift-ci commented on September 15, 2024

Comment by Yusuke Kita (JIRA)

Exactly.

Can I implement this fix? Seems quite interesting to dive into more details.

from swift-syntax.

akyrtzi avatar akyrtzi commented on September 15, 2024

Sure! Note that after changing the syntax definition file it would need a change on the C++ parser side.

from swift-syntax.

swift-ci avatar swift-ci commented on September 15, 2024

Comment by Yusuke Kita (JIRA)

I have a question about literal expression for this. I'm looking into Parser and wondering whether I should extend 'StringLiteralExpr' or create new one like 'NonInterpolatedStringLiteralExpr'. Which one do you think is better? @akyrtzi

I figured out how 'string_segment' is parsed in 'parseExprStringLiteral' func, but I haven't had conclusion for the interface yet.

from swift-syntax.

rintaro avatar rintaro commented on September 15, 2024

I think we should generalize StringLiteralExpr.
Basically, syntax change would be:

  • Remove StringLiteralExpr

  • Rename StringInterpolationExpr to StringLiteralExpr

  • Rename StringInterpolationSegments to StringLiteralSegment

like:

    Node('StringLiteralExpr', kind='Expr',
         children=[
             Child('OpenQuote', kind='Token',
                   token_choices=[
                       'StringQuoteToken',
                       'MultilineStringQuoteToken',
                   ]),
             Child('Segments', kind='StringLiteralSegments'),
             Child('CloseQuote', kind='Token',
                   token_choices=[
                       'StringQuoteToken',
                       'MultilineStringQuoteToken',
                   ]),
         ]),

We can easily check whether it's interpolated or not by (segments.count == 1 && segments[0] is StringSegmentToken)

from swift-syntax.

nkcsgexi avatar nkcsgexi commented on September 15, 2024

I'm not a big fan of adding `NonInterpolatedStringLiteralExpr` either. The reason is users are likely to have two overrides for either visit or rewrite functions to handle all string literal cases. We should strive to help users reduce code duplication. However, feel free to add a convenient function to `StringLIteralExpr` indicating whether there are interpolations in the node.

from swift-syntax.

swift-ci avatar swift-ci commented on September 15, 2024

Comment by Yusuke Kita (JIRA)

What Rintaro suggested makes sense to me. I'll go with `StringLiteralExpr` for the case. Thanks for your feedbacks!

from swift-syntax.

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.