Rename "syntax" package to "lexers"

This commit is contained in:
2025-06-15 16:15:38 -04:00
parent 17be28e6b2
commit 21f55dd55e
44 changed files with 56 additions and 54 deletions
+10 -8
View File
@@ -9,14 +9,14 @@ It is meant to be a more minimal version with the syntax files embedded in the G
Language support is determined at build time by using build tags. To include a language, you must build with the appropriate tag. Language support is determined at build time by using build tags. To include a language, you must build with the appropriate tag.
For example, to include Go syntax highlighting, you must build with `-tags=stxGo`. For example, to include Go syntax highlighting, you must build with `-tags=stxGo`.
You may combine as many tags as you like, or use `-tags=stxAll` to include all syntax layers. You may combine as many tags as you like, or use `-tags=stxAll` to include all lexers.
### Contributing ### Contributing
If you would like to contribute a new syntax layer, please contribute to the parent repository [jessp01/gohighlight](https://github.com/jessp01/gohighlight). If you would like to contribute a new lexer, please contribute to the parent repository [jessp01/gohighlight](https://github.com/jessp01/gohighlight).
In an effort to minimize the size of this library, the syntax layers are modified to the point of being much less readable than the original. In an effort to minimize the size of this library, the lexers are modified to the point of being much less readable than the original.
Because of this, the parent repository is the canonical source for syntax layers. Because of this, the parent repository is the canonical source for lexers.
I will keep this repository up-to-date with any new syntax layers that are added to the parent repository, provided that they are for non-obsolete I will keep this repository up-to-date with any new lexers that are added to the parent repository, provided that they are for non-obsolete
programming languages or config formats (support will not be extended to cover individual shell commands). programming languages or config formats (support will not be extended to cover individual shell commands).
Other types of contributions are welcome as long as they do not go against the goal of keeping this library as lightweight as possible. Other types of contributions are welcome as long as they do not go against the goal of keeping this library as lightweight as possible.
@@ -29,7 +29,7 @@ $ go get github.com/rwinkhart/go-highlite
## Basic Usage ## Basic Usage
Below is a simple example for highlighting a Go snippet with ANSI colors. Below is a simple example for highlighting a Go snippet with ANSI colors.
It must be built with `-tags=stxGo` or `-tags=stxAll` to include the Go syntax layer. It must be built with `-tags=stxGo` or `-tags=stxAll` to include the Go lexer.
For a more advanced example on manually colorizing the output or colorizing it in a For a more advanced example on manually colorizing the output or colorizing it in a
different, non-ANSI format, see the `ansi.Colorize` function. different, non-ANSI format, see the `ansi.Colorize` function.
@@ -67,13 +67,15 @@ func helloWorld() {
## Roadmap ## Roadmap
- [ ] Implement more comprehensive testing - [ ] Implement more comprehensive testing
- [ ] Upgrade to gopkg.in/yaml.v3 **OR** remove the need for the dependency - [ ] Upgrade to gopkg.in/yaml.v3 **OR** remove the need for the dependency
- [ ] Add Zig syntax layer (and upstream it) - [ ] Add lexers (and upstream them)
- [ ] Zig
- [ ] Kotlin
- [ ] Upstream relevant changes - [ ] Upstream relevant changes
- [ ] staticcheck warnings (f5367779eb4bcaaca0640f1ce7316001e34f41d8) - [ ] staticcheck warnings (f5367779eb4bcaaca0640f1ce7316001e34f41d8)
- [ ] Modernization (depending on Go version support) - [ ] Modernization (depending on Go version support)
- [ ] c884c602e382789bf1ccef251d0d85af43da03e0 - [ ] c884c602e382789bf1ccef251d0d85af43da03e0
- [ ] 11161c71cdbbec95f6bacc3590b9077b4cac3668 - [ ] 11161c71cdbbec95f6bacc3590b9077b4cac3668
- [ ] Syntax layer changes - [ ] Lexer changes
- [ ] ef2880834a545b5353a35c7d918310b23d39d4f3 - [ ] ef2880834a545b5353a35c7d918310b23d39d4f3
- [ ] bae08261278f21569fc2266b4a4933a6c85b9b25 - [ ] bae08261278f21569fc2266b4a4933a6c85b9b25
- [ ] 6e8f69839f82fe23a3442f7f9d62d166cac260e3 (maybe) - [ ] 6e8f69839f82fe23a3442f7f9d62d166cac260e3 (maybe)
+4 -4
View File
@@ -6,16 +6,16 @@ import (
"strings" "strings"
"github.com/rwinkhart/go-highlite" "github.com/rwinkhart/go-highlite"
"github.com/rwinkhart/go-highlite/syntax" "github.com/rwinkhart/go-highlite/lexers"
) )
// Colorize takes a string of code and a language ID, and returns the code // Colorize takes a string of code and a language ID, and returns the code
// with ANSI color codes applied for syntax highlighting. // with ANSI color codes applied for syntax highlighting.
func Colorize(inputCode, languageID string, startingColor uint8) (string, error) { func Colorize(inputCode, languageID string, startingColor uint8) (string, error) {
// Load and parse the go syntax layer into a `*highlight.Def` // Load and parse the go lexer into a `*highlight.Def`
syntaxDef, err := highlite.ParseDef(syntax.Get(languageID)) syntaxDef, err := highlite.ParseDef(lexers.Get(languageID))
if err != nil { if err != nil {
return "", errors.New("unable to parse syntax layer: " + err.Error()) return "", errors.New("unable to parse lexer: " + err.Error())
} }
// Make a new highlighter from the definition // Make a new highlighter from the definition
+1 -1
View File
@@ -1,4 +1,4 @@
package syntax package lexers
import "sync" import "sync"
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxAsm || stxAll //go:build stxAsm || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["asm"] = &lazySyntax{init: func() []byte { syntaxMap["asm"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxC || stxAll //go:build stxC || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["c"] = &lazySyntax{init: func() []byte { syntaxMap["c"] = &lazySyntax{init: func() []byte {
@@ -1,6 +1,6 @@
//go:build stxCaddyfile || stxAll //go:build stxCaddyfile || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["caddyfile"] = &lazySyntax{init: func() []byte { syntaxMap["caddyfile"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxCmake || stxAll //go:build stxCmake || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["cmake"] = &lazySyntax{init: func() []byte { syntaxMap["cmake"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxCpp || stxAll //go:build stxCpp || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["cpp"] = &lazySyntax{init: func() []byte { syntaxMap["cpp"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxCsharp || stxAll //go:build stxCsharp || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["csharp"] = &lazySyntax{init: func() []byte { syntaxMap["csharp"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxCss || stxAll //go:build stxCss || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["css"] = &lazySyntax{init: func() []byte { syntaxMap["css"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxD || stxAll //go:build stxD || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["d"] = &lazySyntax{init: func() []byte { syntaxMap["d"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxDart || stxAll //go:build stxDart || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["dart"] = &lazySyntax{init: func() []byte { syntaxMap["dart"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxDiff || stxAll //go:build stxDiff || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["diff"] = &lazySyntax{init: func() []byte { syntaxMap["diff"] = &lazySyntax{init: func() []byte {
@@ -1,6 +1,6 @@
//go:build stxDockerfile || stxAll //go:build stxDockerfile || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["dockerfile"] = &lazySyntax{init: func() []byte { syntaxMap["dockerfile"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxFish || stxAll //go:build stxFish || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["fish"] = &lazySyntax{init: func() []byte { syntaxMap["fish"] = &lazySyntax{init: func() []byte {
@@ -1,6 +1,6 @@
//go:build stxFortran || stxAll //go:build stxFortran || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["fortran"] = &lazySyntax{init: func() []byte { syntaxMap["fortran"] = &lazySyntax{init: func() []byte {
@@ -1,6 +1,6 @@
//go:build stxGdscript || stxAll //go:build stxGdscript || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["gdscript"] = &lazySyntax{init: func() []byte { syntaxMap["gdscript"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxGo || stxAll //go:build stxGo || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["go"] = &lazySyntax{init: func() []byte { syntaxMap["go"] = &lazySyntax{init: func() []byte {
@@ -1,6 +1,6 @@
//go:build stxHaskell || stxAll //go:build stxHaskell || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["haskell"] = &lazySyntax{init: func() []byte { syntaxMap["haskell"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxHtml5 || stxAll //go:build stxHtml5 || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["html5"] = &lazySyntax{init: func() []byte { syntaxMap["html5"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxIni || stxAll //go:build stxIni || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["ini"] = &lazySyntax{init: func() []byte { syntaxMap["ini"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxIno || stxAll //go:build stxIno || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["ino"] = &lazySyntax{init: func() []byte { syntaxMap["ino"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxJava || stxAll //go:build stxJava || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["java"] = &lazySyntax{init: func() []byte { syntaxMap["java"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxJs || stxAll //go:build stxJs || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["js"] = &lazySyntax{init: func() []byte { syntaxMap["js"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxJson || stxAll //go:build stxJson || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["json"] = &lazySyntax{init: func() []byte { syntaxMap["json"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxLisp || stxAll //go:build stxLisp || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["lisp"] = &lazySyntax{init: func() []byte { syntaxMap["lisp"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxLua || stxAll //go:build stxLua || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["lua"] = &lazySyntax{init: func() []byte { syntaxMap["lua"] = &lazySyntax{init: func() []byte {
@@ -1,6 +1,6 @@
//go:build stxMakefile || stxAll //go:build stxMakefile || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["makefile"] = &lazySyntax{init: func() []byte { syntaxMap["makefile"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxObjc || stxAll //go:build stxObjc || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["objc"] = &lazySyntax{init: func() []byte { syntaxMap["objc"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxOcaml || stxAll //go:build stxOcaml || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["ocaml"] = &lazySyntax{init: func() []byte { syntaxMap["ocaml"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxPascal || stxAll //go:build stxPascal || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["pascal"] = &lazySyntax{init: func() []byte { syntaxMap["pascal"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxPerl || stxAll //go:build stxPerl || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["perl"] = &lazySyntax{init: func() []byte { syntaxMap["perl"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxPhp || stxAll //go:build stxPhp || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["php"] = &lazySyntax{init: func() []byte { syntaxMap["php"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxPython || stxAll //go:build stxPython || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["python"] = &lazySyntax{init: func() []byte { syntaxMap["python"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxR || stxAll //go:build stxR || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["r"] = &lazySyntax{init: func() []byte { syntaxMap["r"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxRuby || stxAll //go:build stxRuby || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["ruby"] = &lazySyntax{init: func() []byte { syntaxMap["ruby"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxRust || stxAll //go:build stxRust || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["rust"] = &lazySyntax{init: func() []byte { syntaxMap["rust"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxScala || stxAll //go:build stxScala || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["scala"] = &lazySyntax{init: func() []byte { syntaxMap["scala"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxShell || stxAll //go:build stxShell || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["shell"] = &lazySyntax{init: func() []byte { syntaxMap["shell"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxSwift || stxAll //go:build stxSwift || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["swift"] = &lazySyntax{init: func() []byte { syntaxMap["swift"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxToml || stxAll //go:build stxToml || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["toml"] = &lazySyntax{init: func() []byte { syntaxMap["toml"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxTs || stxAll //go:build stxTs || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["ts"] = &lazySyntax{init: func() []byte { syntaxMap["ts"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxXml || stxAll //go:build stxXml || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["xml"] = &lazySyntax{init: func() []byte { syntaxMap["xml"] = &lazySyntax{init: func() []byte {
+1 -1
View File
@@ -1,6 +1,6 @@
//go:build stxYaml || stxAll //go:build stxYaml || stxAll
package syntax package lexers
func init() { func init() {
syntaxMap["yaml"] = &lazySyntax{init: func() []byte { syntaxMap["yaml"] = &lazySyntax{init: func() []byte {