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

Random orange-ish rectangles #156

Open
b1t-ninja opened this issue Nov 27, 2024 · 5 comments
Open

Random orange-ish rectangles #156

b1t-ninja opened this issue Nov 27, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@b1t-ninja
Copy link

Describe the bug
When I run freeze file.swift it produces an image which always contains at least one orange-red rectangle that appears in the first 3 lines of code.

Here's an example
freeze

If the file is just 3 lines of code it works fine.

To Reproduce
Steps to reproduce the behavior:

  1. Create .swift file and put
typealias PartOne = @Sendable (String) -> Int
@available(macOS 13.0, *)
let partOne: PartOne = { x in
  let digitPattern = /\d+/ // -- 1
  
  return x.split(separator: "\n").reduce(0) { acc, curr in // -- 2
    let matches = curr.matches(of: digitPattern) // -- 3
    guard let first = Int(matches.first!.0) else { return acc } // -- 3
    
    return acc + first + (matches.count > 1 ? Int(matches.last!.0)! : 0) // -- 4
  }
}

inside
3. run freeze file.swift
4. Tada !

Expected behavior
There should be an output image freeze.png

Desktop (please complete the following information):

  • OS: macOS Sequoia 15.1.1
@bashbunni
Copy link
Member

bashbunni commented Nov 28, 2024

I was able to reproduce this as well on master. I also tested the svg output (freeze file.swift -o freeze.svg) and it didn't have this issue (attached)
swift 1

Will have to take a look at the png conversion under the hood. Thanks for reporting this and providing us with steps to repro!

@bashbunni bashbunni added the bug Something isn't working label Nov 28, 2024
@prithvijj
Copy link

Just adding random comments:

I tried running the same code on Windows (go run . lol.swift), and while freeze.png looks okay,

image

When I tried running it with go run . lol2.swift -o freeze.svg and adding extra regexes ( maybe this is regice lol?),
it seems the red rectangles pops up, specifically for \d \n, but not for the /(.+?): (.+)/

image

and the red rectangle does seem to come from the style defined here

chroma.Error: "#F1F1F1 bg:#F05B5B",

Desktop:

  • OS: Windows 10

@prithvijj
Copy link

And seems like when parsing, the \ token? shows that it's an Error Type which is why the red color #F05B5B comes in

image

Running this in .vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
      {
        "name": "Debug Go Run",
        "type": "go",
        "request": "launch",
        "mode": "debug",
        "program": "${workspaceFolder}",
        "args": ["lol2.swift", "-o", "freeze.svg"],
        "showLog": true
      }
    ]
  }
  

@prithvijj
Copy link

And seems like when writing a similar-ish code for typescript

// lol2.ts

const digitPattern = /\d+/; // -- 1

image

and running go run . lol2.ts -o freeze.svg, seems like it's able to figure out the regex type is LiteralStringRegex (3114), (i.e. doesn't render any error, and doesn't draw the rectangle box)

which looks like it's been defined at
https://github.com/alecthomas/chroma/blob/79621af0ab93bb11ac72b35d97893b8787cd52c2/lexers/embedded/typescript.xml#L184-L187

Meanwhile swift.xml doesn't have anything related to LiteralStringRegex or regex typing in that sense, which might be causing the red rectangle to show up since it's an "Error"

https://github.com/alecthomas/chroma/blob/master/lexers/embedded/swift.xml

@arut-plus
Copy link

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants