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

Basic minifier #18

Merged
merged 5 commits into from
Mar 29, 2023
Merged

Basic minifier #18

merged 5 commits into from
Mar 29, 2023

Conversation

CosmicHorrorDev
Copy link
Collaborator

Resolves #17

This is by no means a perfect minifier, but it's simple and certainly good enough for most cases you'll see with ANSI styling

This PR stubs a minifier in between munching the ANSI codes / text and converting it to HTML. The minifier works by condensing all of the input into tidy chains of text and ANSI codes. Then it runs a pass over all the input and discards any runs of ANSI codes that wind up with the same style as the last set

There's a snapshot test included that should act as a good demo. The input text was taken from running the following with some manual replace-all'ing of the ANSI codes to get a more human readable format

use ariadne::{Color, Config, Label, Report, ReportKind, Source};

fn main() {
    Report::build(ReportKind::Error, (), 34)
        .with_config(Config::default().with_char_set(ariadne::CharSet::Ascii))
        .with_message("Incompatible types")
        .with_label(
            Label::new(32..33)
                .with_message("This is of type Nat")
                .with_color(Color::Cyan),
        )
        .with_label(
            Label::new(42..45)
                .with_message("This is of type Str")
                .with_color(Color::Blue),
        )
        .finish()
        .print(Source::from(include_str!("sample.tao")))
        .unwrap();
}

sample.tao

def five = match () in {
	() => 5,
	() => "5",
}

def six =
    five
    + 1

@Aloso
Copy link
Owner

Aloso commented Mar 21, 2023

Thanks! I won't get around to review this today, since it's release day for Pomsky, but it's on my radar.

@CosmicHorrorDev
Copy link
Collaborator Author

All good! I'm in no rush :)

Copy link
Owner

@Aloso Aloso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, busy week :)

I'd like to rewrite this code using a more functional approach, using Iterators to avoid allocations. But that doesn't block this PR. Thanks for working on this.

@Aloso Aloso merged commit e5a51d2 into Aloso:main Mar 29, 2023
@Aloso
Copy link
Owner

Aloso commented Mar 29, 2023

@CosmicHorrorDev I appreciate your contributions, so I added you as a collaborator to the repo. This means that you can merge your own PRs now. I'd still like to review PRs that include substantial code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reduce number of tags further
2 participants