Bumps the go-modules-updates group with 11 updates in the /backend directory: | Package | From | To | | --- | --- | --- | | [github.com/PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery) | `1.10.2` | `1.11.0` | | [github.com/alecthomas/chroma/v2](https://github.com/alecthomas/chroma) | `2.15.0` | `2.20.0` | | [github.com/go-chi/chi/v5](https://github.com/go-chi/chi) | `5.2.1` | `5.2.3` | | [github.com/go-chi/cors](https://github.com/go-chi/cors) | `1.2.1` | `1.2.2` | | [github.com/go-pkgz/jrpc](https://github.com/go-pkgz/jrpc) | `0.3.1` | `0.4.0` | | [github.com/go-pkgz/lgr](https://github.com/go-pkgz/lgr) | `0.12.0` | `0.12.1` | | [github.com/go-pkgz/rest](https://github.com/go-pkgz/rest) | `1.20.3` | `1.20.4` | | [github.com/golang-jwt/jwt/v5](https://github.com/golang-jwt/jwt) | `5.2.2` | `5.3.0` | | [github.com/stretchr/testify](https://github.com/stretchr/testify) | `1.10.0` | `1.11.1` | | [go.etcd.io/bbolt](https://github.com/etcd-io/bbolt) | `1.4.0` | `1.4.3` | | [golang.org/x/image](https://github.com/golang/image) | `0.26.0` | `0.33.0` | Updates `github.com/PuerkitoBio/goquery` from 1.10.2 to 1.11.0 - [Release notes](https://github.com/PuerkitoBio/goquery/releases) - [Commits](https://github.com/PuerkitoBio/goquery/compare/v1.10.2...v1.11.0) Updates `github.com/alecthomas/chroma/v2` from 2.15.0 to 2.20.0 - [Release notes](https://github.com/alecthomas/chroma/releases) - [Commits](https://github.com/alecthomas/chroma/compare/v2.15.0...v2.20.0) Updates `github.com/go-chi/chi/v5` from 5.2.1 to 5.2.3 - [Release notes](https://github.com/go-chi/chi/releases) - [Changelog](https://github.com/go-chi/chi/blob/master/CHANGELOG.md) - [Commits](https://github.com/go-chi/chi/compare/v5.2.1...v5.2.3) Updates `github.com/go-chi/cors` from 1.2.1 to 1.2.2 - [Release notes](https://github.com/go-chi/cors/releases) - [Commits](https://github.com/go-chi/cors/compare/v1.2.1...v1.2.2) Updates `github.com/go-pkgz/jrpc` from 0.3.1 to 0.4.0 - [Release notes](https://github.com/go-pkgz/jrpc/releases) - [Commits](https://github.com/go-pkgz/jrpc/compare/v0.3.1...v0.4.0) Updates `github.com/go-pkgz/lgr` from 0.12.0 to 0.12.1 - [Release notes](https://github.com/go-pkgz/lgr/releases) - [Commits](https://github.com/go-pkgz/lgr/compare/v0.12.0...v0.12.1) Updates `github.com/go-pkgz/rest` from 1.20.3 to 1.20.4 - [Release notes](https://github.com/go-pkgz/rest/releases) - [Commits](https://github.com/go-pkgz/rest/compare/v1.20.3...v1.20.4) Updates `github.com/golang-jwt/jwt/v5` from 5.2.2 to 5.3.0 - [Release notes](https://github.com/golang-jwt/jwt/releases) - [Commits](https://github.com/golang-jwt/jwt/compare/v5.2.2...v5.3.0) Updates `github.com/stretchr/testify` from 1.10.0 to 1.11.1 - [Release notes](https://github.com/stretchr/testify/releases) - [Commits](https://github.com/stretchr/testify/compare/v1.10.0...v1.11.1) Updates `go.etcd.io/bbolt` from 1.4.0 to 1.4.3 - [Release notes](https://github.com/etcd-io/bbolt/releases) - [Commits](https://github.com/etcd-io/bbolt/compare/v1.4.0...v1.4.3) Updates `golang.org/x/image` from 0.26.0 to 0.33.0 - [Commits](https://github.com/golang/image/compare/v0.26.0...v0.33.0) --- updated-dependencies: - dependency-name: github.com/PuerkitoBio/goquery dependency-version: 1.11.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/alecthomas/chroma/v2 dependency-version: 2.20.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/go-chi/chi/v5 dependency-version: 5.2.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: github.com/go-chi/cors dependency-version: 1.2.2 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: github.com/go-pkgz/jrpc dependency-version: 0.4.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/go-pkgz/lgr dependency-version: 0.12.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: github.com/go-pkgz/rest dependency-version: 1.20.4 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: github.com/golang-jwt/jwt/v5 dependency-version: 5.3.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: github.com/stretchr/testify dependency-version: 1.11.1 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates - dependency-name: go.etcd.io/bbolt dependency-version: 1.4.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-modules-updates - dependency-name: golang.org/x/image dependency-version: 0.33.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-modules-updates ... Signed-off-by: dependabot[bot] <support@github.com>
180 lines
4.9 KiB
Go
180 lines
4.9 KiB
Go
package chroma
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
defaultOptions = &TokeniseOptions{
|
|
State: "root",
|
|
EnsureLF: true,
|
|
}
|
|
)
|
|
|
|
// Config for a lexer.
|
|
type Config struct {
|
|
// Name of the lexer.
|
|
Name string `xml:"name,omitempty"`
|
|
|
|
// Shortcuts for the lexer
|
|
Aliases []string `xml:"alias,omitempty"`
|
|
|
|
// File name globs
|
|
Filenames []string `xml:"filename,omitempty"`
|
|
|
|
// Secondary file name globs
|
|
AliasFilenames []string `xml:"alias_filename,omitempty"`
|
|
|
|
// MIME types
|
|
MimeTypes []string `xml:"mime_type,omitempty"`
|
|
|
|
// Regex matching is case-insensitive.
|
|
CaseInsensitive bool `xml:"case_insensitive,omitempty"`
|
|
|
|
// Regex matches all characters.
|
|
DotAll bool `xml:"dot_all,omitempty"`
|
|
|
|
// Regex does not match across lines ($ matches EOL).
|
|
//
|
|
// Defaults to multiline.
|
|
NotMultiline bool `xml:"not_multiline,omitempty"`
|
|
|
|
// Don't strip leading and trailing newlines from the input.
|
|
// DontStripNL bool
|
|
|
|
// Strip all leading and trailing whitespace from the input
|
|
// StripAll bool
|
|
|
|
// Make sure that the input ends with a newline. This
|
|
// is required for some lexers that consume input linewise.
|
|
EnsureNL bool `xml:"ensure_nl,omitempty"`
|
|
|
|
// If given and greater than 0, expand tabs in the input.
|
|
// TabSize int
|
|
|
|
// Priority of lexer.
|
|
//
|
|
// If this is 0 it will be treated as a default of 1.
|
|
Priority float32 `xml:"priority,omitempty"`
|
|
|
|
// Analyse is a list of regexes to match against the input.
|
|
//
|
|
// If a match is found, the score is returned if single attribute is set to true,
|
|
// otherwise the sum of all the score of matching patterns will be
|
|
// used as the final score.
|
|
Analyse *AnalyseConfig `xml:"analyse,omitempty"`
|
|
}
|
|
|
|
// AnalyseConfig defines the list of regexes analysers.
|
|
type AnalyseConfig struct {
|
|
Regexes []RegexConfig `xml:"regex,omitempty"`
|
|
// If true, the first matching score is returned.
|
|
First bool `xml:"first,attr"`
|
|
}
|
|
|
|
// RegexConfig defines a single regex pattern and its score in case of match.
|
|
type RegexConfig struct {
|
|
Pattern string `xml:"pattern,attr"`
|
|
Score float32 `xml:"score,attr"`
|
|
}
|
|
|
|
// Token output to formatter.
|
|
type Token struct {
|
|
Type TokenType `json:"type"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
func (t *Token) String() string { return t.Value }
|
|
func (t *Token) GoString() string { return fmt.Sprintf("&Token{%s, %q}", t.Type, t.Value) }
|
|
|
|
// Clone returns a clone of the Token.
|
|
func (t *Token) Clone() Token {
|
|
return *t
|
|
}
|
|
|
|
// EOF is returned by lexers at the end of input.
|
|
var EOF Token
|
|
|
|
// TokeniseOptions contains options for tokenisers.
|
|
type TokeniseOptions struct {
|
|
// State to start tokenisation in. Defaults to "root".
|
|
State string
|
|
// Nested tokenisation.
|
|
Nested bool
|
|
|
|
// If true, all EOLs are converted into LF
|
|
// by replacing CRLF and CR
|
|
EnsureLF bool
|
|
}
|
|
|
|
// A Lexer for tokenising source code.
|
|
type Lexer interface {
|
|
// Config describing the features of the Lexer.
|
|
Config() *Config
|
|
// Tokenise returns an Iterator over tokens in text.
|
|
Tokenise(options *TokeniseOptions, text string) (Iterator, error)
|
|
// SetRegistry sets the registry this Lexer is associated with.
|
|
//
|
|
// The registry should be used by the Lexer if it needs to look up other
|
|
// lexers.
|
|
SetRegistry(registry *LexerRegistry) Lexer
|
|
// SetAnalyser sets a function the Lexer should use for scoring how
|
|
// likely a fragment of text is to match this lexer, between 0.0 and 1.0.
|
|
// A value of 1 indicates high confidence.
|
|
//
|
|
// Lexers may ignore this if they implement their own analysers.
|
|
SetAnalyser(analyser func(text string) float32) Lexer
|
|
// AnalyseText scores how likely a fragment of text is to match
|
|
// this lexer, between 0.0 and 1.0. A value of 1 indicates high confidence.
|
|
AnalyseText(text string) float32
|
|
}
|
|
|
|
// Trace is the trace of a tokenisation process.
|
|
type Trace struct {
|
|
Lexer string `json:"lexer"`
|
|
State string `json:"state"`
|
|
Rule int `json:"rule"`
|
|
Pattern string `json:"pattern"`
|
|
Pos int `json:"pos"`
|
|
Length int `json:"length"`
|
|
Elapsed float64 `json:"elapsedMs"` // Elapsed time spent matching for this rule.
|
|
}
|
|
|
|
// TracingLexer is a Lexer that can trace its tokenisation process.
|
|
type TracingLexer interface {
|
|
Lexer
|
|
SetTracing(enable bool)
|
|
}
|
|
|
|
// Lexers is a slice of lexers sortable by name.
|
|
type Lexers []Lexer
|
|
|
|
func (l Lexers) Len() int { return len(l) }
|
|
func (l Lexers) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
|
|
func (l Lexers) Less(i, j int) bool {
|
|
return strings.ToLower(l[i].Config().Name) < strings.ToLower(l[j].Config().Name)
|
|
}
|
|
|
|
// PrioritisedLexers is a slice of lexers sortable by priority.
|
|
type PrioritisedLexers []Lexer
|
|
|
|
func (l PrioritisedLexers) Len() int { return len(l) }
|
|
func (l PrioritisedLexers) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
|
|
func (l PrioritisedLexers) Less(i, j int) bool {
|
|
ip := l[i].Config().Priority
|
|
if ip == 0 {
|
|
ip = 1
|
|
}
|
|
jp := l[j].Config().Priority
|
|
if jp == 0 {
|
|
jp = 1
|
|
}
|
|
return ip > jp
|
|
}
|
|
|
|
// Analyser determines how appropriate this lexer is for the given text.
|
|
type Analyser interface {
|
|
AnalyseText(text string) float32
|
|
}
|