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

Swift: Major improvements #3022

Merged
merged 9 commits into from Aug 9, 2021

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Jul 31, 2021

I made a number of changes to Swift:

  1. Added support for nested comment (/* /* foo */ */).
  2. Added support for multi-line strings (""" foo """) and raw strings (#" foo "#)
  3. Removed single-quoted strings. Swift does not and has never supported single-quoted strings.
  4. Correct tokenization for all operators + punctuation.
  5. Added "omit" rule for _.
  6. Added support for statement labels. (foo: while ...)
  7. Removed builtin functions/properties. They just looked out of place and provided no real value.
  8. Improved function detection.
  9. Naming-based type detection. All type-like structures (classes, structs, protocols, etc.) typically have UpperCamelCase names.

Edit:

  1. Support directives.
  2. Support all/custom attributes.
  3. Updated keywords.

@AvdLee
I hope this helps with #3021.

Also, I'm not familiar with Swift and not sure about the naming-based class detection. Can we assume that everything starting with an upper-case letter and containing a lower-case letter is a class name?

@github-actions
Copy link

github-actions bot commented Jul 31, 2021

JS File Size Changes (gzipped)

A total of 2 files have changed, with a combined diff of +211 B (+6.4%).

file master pull size diff % diff
components/prism-swift.min.js 1.06 KB 1.28 KB +216 B +20.4%
plugins/autoloader/prism-autoloader.min.js 2.24 KB 2.23 KB -5 B -0.2%

Generated by 🚫 dangerJS against 8c70ed8

@AvdLee
Copy link
Contributor

AvdLee commented Aug 2, 2021

Also, I'm not familiar with Swift and not sure about the naming-based class detection. Can we assume that everything starting with an upper-case letter and containing a lower-case letter is a class name?

It's fair to say yes, but Swift doesn't enforce us doing so. I haven't seen any code examples though in which developers defined classes starting with a lowercase!

@AvdLee
Copy link
Contributor

AvdLee commented Aug 2, 2021

@AvdLee
I hope this helps with #3021.

Really impressive PR! Thanks a lot, I'm learning a lot about this library as well now 🙂
I'm sure we're getting closer and closer to better support!

Btw, if you like to explore how Prism is behaving with Swift, you can check out my articles here: avanderlee.com
All highlighted code is backed by Prism 💪

@RunDevelopment
Copy link
Member Author

@AvdLee I think I got everything from #3021 now.

Also, in your article about dependency injection, you presented this attribute: @Injected(\.networkProvider). What does the \. mean?

@AvdLee
Copy link
Contributor

AvdLee commented Aug 3, 2021

@AvdLee I think I got everything from #3021 now.

Dang, that's amazing! Thanks a ton 💪

Also, in your article about dependency injection, you presented this attribute: @injected(.networkProvider). What does the . mean?

It's an accessor to a key path reference. See "Key-Path Expression" in this document: https://docs.swift.org/swift-book/ReferenceManual/Expressions.html

@RunDevelopment
Copy link
Member Author

It's an accessor to a key path reference.

Seems like I missed that part while scanning through the docs. Thank you!

@RunDevelopment RunDevelopment merged commit 8541db2 into PrismJS:master Aug 9, 2021
@RunDevelopment RunDevelopment deleted the swift-improvements branch August 9, 2021 09:45
@AvdLee AvdLee mentioned this pull request Oct 28, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants