...

Source file src/github.com/alecthomas/chroma/lexers/z/zig.go

Documentation: github.com/alecthomas/chroma/lexers/z

     1  package z
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Zig lexer.
     9  var Zig = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Zig",
    12  		Aliases:   []string{"zig"},
    13  		Filenames: []string{"*.zig"},
    14  		MimeTypes: []string{"text/zig"},
    15  	},
    16  	zigRules,
    17  ))
    18  
    19  func zigRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`\n`, TextWhitespace, nil},
    23  			{`\s+`, TextWhitespace, nil},
    24  			{`//.*?\n`, CommentSingle, nil},
    25  			{Words(``, `\b`, `break`, `return`, `continue`, `asm`, `defer`, `errdefer`, `unreachable`, `try`, `catch`, `async`, `await`, `suspend`, `resume`, `cancel`), Keyword, nil},
    26  			{Words(``, `\b`, `const`, `var`, `extern`, `packed`, `export`, `pub`, `noalias`, `inline`, `comptime`, `nakedcc`, `stdcallcc`, `volatile`, `allowzero`, `align`, `linksection`, `threadlocal`), KeywordReserved, nil},
    27  			{Words(``, `\b`, `struct`, `enum`, `union`, `error`), Keyword, nil},
    28  			{Words(``, `\b`, `while`, `for`), Keyword, nil},
    29  			{Words(``, `\b`, `bool`, `f16`, `f32`, `f64`, `f128`, `void`, `noreturn`, `type`, `anyerror`, `promise`, `i0`, `u0`, `isize`, `usize`, `comptime_int`, `comptime_float`, `c_short`, `c_ushort`, `c_int`, `c_uint`, `c_long`, `c_ulong`, `c_longlong`, `c_ulonglong`, `c_longdouble`, `c_voidi8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`), KeywordType, nil},
    30  			{Words(``, `\b`, `true`, `false`, `null`, `undefined`), KeywordConstant, nil},
    31  			{Words(``, `\b`, `if`, `else`, `switch`, `and`, `or`, `orelse`), Keyword, nil},
    32  			{Words(``, `\b`, `fn`, `usingnamespace`, `test`), Keyword, nil},
    33  			{`0x[0-9a-fA-F]+\.[0-9a-fA-F]+([pP][\-+]?[0-9a-fA-F]+)?`, LiteralNumberFloat, nil},
    34  			{`0x[0-9a-fA-F]+\.?[pP][\-+]?[0-9a-fA-F]+`, LiteralNumberFloat, nil},
    35  			{`[0-9]+\.[0-9]+([eE][-+]?[0-9]+)?`, LiteralNumberFloat, nil},
    36  			{`[0-9]+\.?[eE][-+]?[0-9]+`, LiteralNumberFloat, nil},
    37  			{`0b(?:_?[01])+`, LiteralNumberBin, nil},
    38  			{`0o(?:_?[0-7])+`, LiteralNumberOct, nil},
    39  			{`0x(?:_?[0-9a-fA-F])+`, LiteralNumberHex, nil},
    40  			{`(?:_?[0-9])+`, LiteralNumberInteger, nil},
    41  			{`@[a-zA-Z_]\w*`, NameBuiltin, nil},
    42  			{`[a-zA-Z_]\w*`, Name, nil},
    43  			{`\'\\\'\'`, LiteralStringEscape, nil},
    44  			{`\'\\(|x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{6}|[nr\\t\'"])\'`, LiteralStringEscape, nil},
    45  			{`\'[^\\\']\'`, LiteralString, nil},
    46  			{`\\\\[^\n]*`, LiteralStringHeredoc, nil},
    47  			{`c\\\\[^\n]*`, LiteralStringHeredoc, nil},
    48  			{`c?"`, LiteralString, Push("string")},
    49  			{`[+%=><|^!?/\-*&~:]`, Operator, nil},
    50  			{`[{}()\[\],.;]`, Punctuation, nil},
    51  		},
    52  		"string": {
    53  			{`\\(x[a-fA-F0-9]{2}|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{6}|[nr\\t\'"])`, LiteralStringEscape, nil},
    54  			{`[^\\"\n]+`, LiteralString, nil},
    55  			{`"`, LiteralString, Pop(1)},
    56  		},
    57  	}
    58  }
    59  

View as plain text