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

5 Improve Robustness of Tailwind Class Parsing in Rust #6

Merged
merged 46 commits into from
Oct 11, 2023

Conversation

Oyelowo
Copy link
Owner

@Oyelowo Oyelowo commented Oct 11, 2023

Summary

This pull request introduces a significant refactor of the text parsing mechanism in the project. The initial implementation used manual string manipulation for parsing the text strings, which while functional, wasn't very scalable and maintainable. This PR replaces the manual string manipulation with a more sophisticated and efficient approach using combinatorial parsing techniques.

Able to parse this successfully with robust error checks:

tw!(
        r#"[mask-type:alpha] [mask-type:alpha] before:content-['rerer  erer re rr r  \re  reFestivus']
    after:content-['I am a content'] after:content-['I am a content'] after:content-['I am a content']
        active:hover:text-[#bada55] active:hover:text-[#fa5] text-[#bada55] hover:aria-checked:text-[22px]
        text-[22.34e434cm]
        before:content-['hello\_world']
    grid grid-cols-[fit-content(theme(spacing.32))]
    bg-[--my-color]
        text-[var(--my-var)]
        text-[length:var(--my-var)]
        text-[color:var(--my-var)]
        [--scroll-offset:56px] lg:[--scroll-offset:44px]
        btn bg-[url('/img/down-arrow.svg')] ring-white/10   bg-black/25  bg-black/[80%] bg-black/[100] bg-black/[0.75]    active:hover:collapse-arrow

    [mask-image:linear-gradient(180deg,white,rgba(255,255,255,0))]

    pt-8 text-base font-semibold leading-7

    bg-[rgb(0,0,3)] absolute inset-0 bg-center 

    -mt-4

        lg:[&:nth-child(3)]:hover:underline
        group-[:nth-of-type(3)_&]:block
     [&_p]:mt-4

     flex [@supports(display:grid)]:grid
     flex active:hover:[@supports(display:grid)]:grid

     [@media(any-hover:hover){&:hover}]:opacity-100

         hidden group-[.is-published]:block
     group-[:nth-of-type(3)_&]:block
     peer-[.is-dirty]:peer-required:block hidden
     hidden peer-[:nth-of-type(3)_&]:block

         group/edit invisible hover:bg-slate-200 group-hover/item:visible

     peer-checked/published:text-sky-500
    
after:content-['*'] after:ml-0.5 after:text-red-500 block text-sm font-medium text-slate-700

    before:content-[''] before:block
content-[>]
content-[<]
    
    bg-black/75 supports-[backdrop-filter]:bg-black/25 supports-[backdrop-filter]:backdrop-blur

aria-[sort=ascending]:bg-[url('/img/down-arrow.svg')] aria-[sort=descending]:bg-[url('/img/up-arrow.svg')]


 group-aria-[sort=ascending]:rotate-0 group-aria-[sort=descending]:rotate-180
    
 data-[size=large]:p-8

    open:bg-white dark:open:bg-slate-900 open:ring-1 open:ring-black/5 dark:open:ring-white/10 open:shadow-lg p-6 rounded-lg
    
    lg:[&:nth-child(3)]:hover:underline

     min-[320rem]:text-center max-[600px]:bg-sky-300

 top-[117px] lg:top-[344px]

     bg-[#bada55] text-[22px] before:content-['Festivus']


     grid grid-cols-[fit-content(theme(spacing.32))]

     bg-[--my-color]

 [mask-type:luminance] hover:[mask-type:alpha]

 [--scroll-offset:56px] lg:[--scroll-offset:44px]

 lg:[&:nth-child(3)]:hover:underline
 bg-[url('/what_a_rush.png')]
 before:content-['hello\_world']
 text-[22px]
 text-[#bada55]
 text-[var(--my-var)]
 text-[length:var(--my-var)]
 text-[color:var(--my-var)]


     p-6 max-w-sm mx-auto bg-white rounded-xl shadow-lg flex items-center space-x-4


              w-[calc(100%_-_theme("spacing[1.5]))"]
          shadow-[inset_0_-3em_3em_rgba(0,_0,_0,_0.1),_0_0_0_2px_rgb(255,_255,_255),_0.3em_0.3em_1em_rgba(0,_0,_0,_0.3)]


        "#
    );

Changes

  • Replaced manual string manipulation functions with a combinatorial parser.
  • Added new utility functions for more readable and maintainable code.
  • Updated unit tests to reflect the changes in the parsing logic.
  • Improved error handling and validation checks.
  • Added extensive comments and documentation for the new implementation.

Rationale

The manual string manipulation was becoming complex, error-prone, and hard to maintain as the requirements evolved. The new combinatorial parsing approach offers the following advantages:

  1. Scalability: Easily extendable to accommodate new parsing rules.
  2. Maintainability: Easier to read and manage the codebase.
  3. Performance: Faster parsing times and optimized memory usage.
  4. Robustness: Improved error handling and validation.

Testing

  • All existing unit tests pass.
  • Added new unit tests to cover additional edge cases.
  • Conducted performance benchmarks to verify the improvements.

Future Work

  • Further optimization of the parsing algorithm.
  • Adding more features that could leverage the new parsing mechanism.

Deployment

  • Ensure that you run the updated unit tests before merging this PR.
  • Follow the usual deployment steps as outlined in the project's README.

This PR has been meticulously designed to provide a high-quality, scalable solution for our text parsing needs. It significantly improves upon the previous implementation and sets the stage for future extensions.

Reviewers

  • Please review the changes and run the unit tests.
  • Any feedback on the new implementation is highly welcome.

This Pull Request aims to maintain the high standards of code quality and performance that we aim for in this project.

@Oyelowo Oyelowo linked an issue Oct 11, 2023 that may be closed by this pull request
@Oyelowo Oyelowo self-assigned this Oct 11, 2023
@Oyelowo Oyelowo added bug Something isn't working enhancement New feature or request labels Oct 11, 2023
@Oyelowo Oyelowo changed the title 5 use a more robust parsing for tailwind classes 5 Improve Robustness of Tailwind Class Parsing in Rust Oct 11, 2023
@Oyelowo Oyelowo requested a review from oyedayo October 11, 2023 05:40
@Oyelowo Oyelowo merged commit afd9e58 into master Oct 11, 2023
@Oyelowo Oyelowo deleted the 5-use-a-more-robust-parsing-for-tailwind-classes branch October 11, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use a more robust parsing for tailwind classes
2 participants