Skip to content

Commit

Permalink
hare: update to work with latest chroma
Browse files Browse the repository at this point in the history
  • Loading branch information
triallax committed Nov 13, 2023
1 parent 65a04e9 commit 1e6d554
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ translators for Pygments lexers and styles.
| E | EBNF, Elixir, Elm, EmacsLisp, Erlang |
| F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp |
| G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy |
| H | Handlebars, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
| H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
| I | Idris, Igor, INI, Io, ISCdhcpd |
| J | J, Java, JavaScript, JSON, Julia, Jungle |
| K | Kotlin |
Expand Down
110 changes: 55 additions & 55 deletions lexers/hare.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
package h
package lexers

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

// Hare lexer (WIP).
var Hare = internal.Register(MustNewLexer(
&Config{
Name: "Hare",
Aliases: []string{ "hare", },
Filenames: []string{ "*.ha", },
MimeTypes: []string{ "text/x-hare", },
},
Rules{
"whitespace": {
{ `^use\s.+;`, CommentPreproc, nil },
{ `@[a-z]+`, CommentPreproc, nil },
{ `\n`, Text, nil },
{ `\s+`, Text, nil },
{`//.*\n`, CommentSingle, nil},
},
"statements": {
{ `"`, LiteralString, Push("string") },
{ "`[^`]*`", LiteralString, nil },
{ `'(\\[\\0abfnrtv"']||\\(x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})|[^\\'])'`, LiteralStringChar, nil },
{ `(0|[1-9]\d*)\.\d+([eE][+-]?\d+)?(f32|f64)?`, LiteralNumberFloat, nil },
{ `(0|[1-9]\d*)([eE][+-]?\d+)?(f32|f64)`, LiteralNumberFloat, nil },
{ `0x[0-9a-fA-F]+\.[0-9a-fA-F]+([pP][+-]?\d+(f32|f64)?)?`, LiteralNumberFloat, nil },
{ `0x[0-9a-fA-F]+[pP][+-]?\d+(f32|f64)`, LiteralNumberFloat, nil },
{ `0x[0-9a-fA-F]+(z|[iu](8|16|32|64)?)?`, LiteralNumberHex, nil },
{ `0o[0-7]+(z|[iu](8|16|32|64)?)?`, LiteralNumberOct, nil },
{ `0b[01]+(z[iu](8|16|32|64)?)?`, LiteralNumberBin, nil },
{ `(0|[1-9]\d*)([eE][+-]?\d+)?(z|[iu](8|16|32|64)?)?`, LiteralNumberInteger, nil },
{ `[~!%^&*+=|?:<>/-]|[ai]s\b|\.\.\.`, Operator, nil },
{ `[()\[\],.{};]`, Punctuation, nil },
{ Words(``, `\b`, `_`, `align`, `break`, `const`, `continue`,
`else`, `enum`, `export`, `for`, `if`, `return`, `size`,
`static`, `struct`, `offset`, `union`, `fn`, `free`, `assert`,
`abort`, `alloc`, `let`, `len`, `def`, `type`, `match`,
`switch`, `case`, `append`, `delete`, `insert`, `defer`,
`yield`, `vastart`, `vaarg`, `vaend`), Keyword, nil },
{ `(str|rune|bool|int|uint|uintptr|u8|u16|u32|u64|i8|i16|i32|i64|f32|f64|null|void|nullable|valist|opaque|never)\b`, KeywordType, nil },
{ `(true|false)\b`, NameBuiltin, nil },
{ `[a-zA-Z_]\w*`, Name, nil },
},
"string": {
{ `"`, LiteralString, Pop(1) },
{ `\\([\\0abfnrtv"']|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})`, LiteralStringEscape, nil },
{ `[^\\"\n]+`, LiteralString, nil },
{ `\\`, LiteralString, nil },
},
"root": {
Include("whitespace"),
Include("statements"),
},
},
// Hare lexer.
var Hare = Register(MustNewLexer(
&Config{
Name: "Hare",
Aliases: []string{"hare"},
Filenames: []string{"*.ha"},
MimeTypes: []string{"text/x-hare"},
},
func() Rules {
return Rules{
"whitespace": {
{`^use\s.+;`, CommentPreproc, nil},
{`@[a-z]+`, CommentPreproc, nil},
{`\n`, Text, nil},
{`\s+`, Text, nil},
{`//.*\n`, CommentSingle, nil},
},
"statements": {
{`"`, LiteralString, Push("string")},
{"`[^`]*`", LiteralString, nil},
{`'(\\[\\0abfnrtv"']||\\(x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})|[^\\'])'`, LiteralStringChar, nil},
{`(0|[1-9]\d*)\.\d+([eE][+-]?\d+)?(f32|f64)?`, LiteralNumberFloat, nil},
{`(0|[1-9]\d*)([eE][+-]?\d+)?(f32|f64)`, LiteralNumberFloat, nil},
{`0x[0-9a-fA-F]+\.[0-9a-fA-F]+([pP][+-]?\d+(f32|f64)?)?`, LiteralNumberFloat, nil},
{`0x[0-9a-fA-F]+[pP][+-]?\d+(f32|f64)`, LiteralNumberFloat, nil},
{`0x[0-9a-fA-F]+(z|[iu](8|16|32|64)?)?`, LiteralNumberHex, nil},
{`0o[0-7]+(z|[iu](8|16|32|64)?)?`, LiteralNumberOct, nil},
{`0b[01]+(z[iu](8|16|32|64)?)?`, LiteralNumberBin, nil},
{`(0|[1-9]\d*)([eE][+-]?\d+)?(z|[iu](8|16|32|64)?)?`, LiteralNumberInteger, nil},
{`[~!%^&*+=|?:<>/-]|[ai]s\b|\.\.\.`, Operator, nil},
{`[()\[\],.{};]`, Punctuation, nil},
{Words(``, `\b`, `_`, `align`, `break`, `const`, `continue`,
`else`, `enum`, `export`, `for`, `if`, `return`, `size`,
`static`, `struct`, `offset`, `union`, `fn`, `free`, `assert`,
`abort`, `alloc`, `let`, `len`, `def`, `type`, `match`,
`switch`, `case`, `append`, `delete`, `insert`, `defer`,
`yield`, `vastart`, `vaarg`, `vaend`), Keyword, nil},
{`(str|rune|bool|int|uint|uintptr|u8|u16|u32|u64|i8|i16|i32|i64|f32|f64|null|void|nullable|valist|opaque|never)\b`, KeywordType, nil},
{`(true|false)\b`, NameBuiltin, nil},
{`[a-zA-Z_]\w*`, Name, nil},
},
"string": {
{`"`, LiteralString, Pop(1)},
{`\\([\\0abfnrtv"']|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8})`, LiteralStringEscape, nil},
{`[^\\"\n]+`, LiteralString, nil},
{`\\`, LiteralString, nil},
},
"root": {
Include("whitespace"),
Include("statements"),
},
}
},
))

0 comments on commit 1e6d554

Please sign in to comment.