Skip to content

Analyse doesn't care about whether the language is case-insensitive #1118

@Chi-Iroh

Description

@Chi-Iroh

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

<lexer>
  <config>
    ...
    <case_insensitive>true</case_insensitive>
    <analyse>
      <regex pattern="ctl-opt" score="0.9"/>
    </analyse>
  </config>
</lexer>

Unless I made a mistake, with this lexer configuration, I declared the language as case-insensitive. However Analyse() seems to ignore the case-insensitivity.

To Reproduce

package main

import (
	"github.com/alecthomas/chroma/v2/lexers"
)

var s string = "Ctl-opt" // note the uppercase C

func main() {
	lexer := lexers.Analyse(s)
	if lexer == nil {
		println("nil !")
	} else {
		println(lexer.Config().Name)
	}
}

It should print the name of my lexer, but it actually prints "nil !", meaning the analysis failed. I added some debug log in Analyse() to display the weight of each lexer, and mine has indeed 0 instead of 0.9.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions