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

Implemented support for f-string expressions #455

Merged

Conversation

Luna-Klatzer
Copy link
Member

@Luna-Klatzer Luna-Klatzer commented May 30, 2023

What type of change does this PR perform?

  • New feature (Non-breaking change which adds functionality)

Summary

Implemented F-String Expressions according to #287, which allow complex string concatenation and manipulation.

Closes #287

Summary of Changes

  • Rewrote parts of the Kipper Lexer & Parser to allow for the nested expressions.
  • Implemented F-Strings Expression according to the planned feature set.

Does this PR create new warnings?

No.

Detailed Changelog

Not present for website/docs changes

Added

  • Support for complex string formatting (or also called templating) in the form of Python-like F-Strings. (#287).
  • New valid conversions:
    • void to str.
    • null to str.
    • undefined to str.
  • New parameters:
    • ignoreParams in genJSFunction, which, if true makes the function signature define no parameters.
    • ignoreParams in createJSFunctionSignature, which, if true makes the function signature define no parameters.
    • ignoreParams in genTSFunction, which, if true makes the function signature define no parameters.
    • ignoreParams in createTSFunctionSignature, which, if true makes the function signature define no parameters.
  • New field:
    • KipperError.programCtx, which contains, if KipperError.tracebackData.errorNode is not undefined, the program
      context of the error.
  • New functions:
    • KipperTargetBuiltInGenerator.voidToStr, for the built-in conversion from void to str.
    • KipperTargetBuiltInGenerator.nullToStr, for the built-in conversion from null to str.
    • KipperTargetBuiltInGenerator.undefinedToStr, for the built-in conversion from undefined to str.

Changed

  • Made VoidOrNullOrUndefinedPrimaryExpression a constant expression and inherit from the ConstantExpression class.
    This means it's AST kind number is now also added to the ASTConstantExpressionKind type and its context class is
    also part of the ParserConstantExpressionContext type.
  • Renamed:
    • FunctionCallPostfixTypeSemantics to FunctionCallExpressionTypeSemantics.
    • FStringPrimaryExpressionSemantics.items to atoms.
    • getTSFunction() to genTSFunction().

Linked issues or PRs

…ntlr4 parser

This is due to the fact generating the parser should be preferably done on the root level, as the lexer and parser are usually also referenced in other packages
The update for the lexer syntax also includes the introduction of new parsing modes to support the complex recognition of nested expressions and sub-parts of f-strings
This is due to unexpected conflicts when performing tests, as that ts-node version is seemingly incompatible with typescript 4.9.x
The bug caused `abortOnFirstError` to not precede `recover`, meaning that instead of an error being thrown the failed result was returned
@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label May 30, 2023
@Luna-Klatzer Luna-Klatzer added this to the v0.11.0 milestone May 30, 2023
@Luna-Klatzer Luna-Klatzer self-assigned this May 30, 2023
@Luna-Klatzer
Copy link
Member Author

In work, some commits not pushed yet.

@codecov
Copy link

codecov bot commented May 30, 2023

Codecov Report

Patch coverage: 95.00% and project coverage change: +0.14 🎉

Comparison is base (436ca2f) 85.63% compared to head (c1641e1) 85.78%.

Additional details and impacted files
@@              Coverage Diff               @@
##           dev-0.11.0     #455      +/-   ##
==============================================
+ Coverage       85.63%   85.78%   +0.14%     
==============================================
  Files             117      118       +1     
  Lines            2214     2230      +16     
  Branches          248      249       +1     
==============================================
+ Hits             1896     1913      +17     
+ Misses            202      201       -1     
  Partials          116      116              
Impacted Files Coverage Δ
kipper/cli/src/commands/run.ts 32.50% <0.00%> (ø)
kipper/core/src/compiler/const.ts 96.96% <ø> (ø)
...per/core/src/compiler/parser/parser-ast-mapping.ts 100.00% <ø> (ø)
kipper/core/src/compiler/runtime-built-ins.ts 100.00% <ø> (ø)
.../target-presets/translation/built-ins-generator.ts 100.00% <ø> (ø)
.../expressions/primary/fstring-primary-expression.ts 100.00% <100.00%> (+6.66%) ⬆️
.../src/compiler/parser/antlr/base/KipperLexerBase.ts 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@github-actions
Copy link
Contributor

github-actions bot commented May 30, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
./kipper/web/kipper-standalone.min.js 133.93 KB (0%) 2.7 s (0%) 288 ms (+31.63% 🔺) 3 s
./kipper/web/kipper-standalone.js 133.96 KB (0%) 2.7 s (0%) 279 ms (+1.81% 🔺) 3 s

@Luna-Klatzer Luna-Klatzer merged commit 34b83c7 into dev-0.11.0 Jun 7, 2023
@Luna-Klatzer Luna-Klatzer deleted the 287-feature-implement-support-for-f-string-expressions branch June 7, 2023 13:04
@Luna-Klatzer Luna-Klatzer mentioned this pull request Jul 10, 2024
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

Successfully merging this pull request may close these issues.

1 participant