...

Source file src/github.com/alecthomas/chroma/lexers/b/bibtex.go

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

     1  package b
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Bibtex lexer.
     9  var Bibtex = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:            "BibTeX",
    12  		Aliases:         []string{"bib", "bibtex"},
    13  		Filenames:       []string{"*.bib"},
    14  		MimeTypes:       []string{"text/x-bibtex"},
    15  		NotMultiline:    true,
    16  		CaseInsensitive: true,
    17  	},
    18  	bibtexRules,
    19  ))
    20  
    21  func bibtexRules() Rules {
    22  	return Rules{
    23  		"root": {
    24  			Include("whitespace"),
    25  			{`@comment`, Comment, nil},
    26  			{`@preamble`, NameClass, Push("closing-brace", "value", "opening-brace")},
    27  			{`@string`, NameClass, Push("closing-brace", "field", "opening-brace")},
    28  			{"@[a-z_@!$&*+\\-./:;<>?\\[\\\\\\]^`|~][\\w@!$&*+\\-./:;<>?\\[\\\\\\]^`|~]*", NameClass, Push("closing-brace", "command-body", "opening-brace")},
    29  			{`.+`, Comment, nil},
    30  		},
    31  		"opening-brace": {
    32  			Include("whitespace"),
    33  			{`[{(]`, Punctuation, Pop(1)},
    34  		},
    35  		"closing-brace": {
    36  			Include("whitespace"),
    37  			{`[})]`, Punctuation, Pop(1)},
    38  		},
    39  		"command-body": {
    40  			Include("whitespace"),
    41  			{`[^\s\,\}]+`, NameLabel, Push("#pop", "fields")},
    42  		},
    43  		"fields": {
    44  			Include("whitespace"),
    45  			{`,`, Punctuation, Push("field")},
    46  			Default(Pop(1)),
    47  		},
    48  		"field": {
    49  			Include("whitespace"),
    50  			{"[a-z_@!$&*+\\-./:;<>?\\[\\\\\\]^`|~][\\w@!$&*+\\-./:;<>?\\[\\\\\\]^`|~]*", NameAttribute, Push("value", "=")},
    51  			Default(Pop(1)),
    52  		},
    53  		"=": {
    54  			Include("whitespace"),
    55  			{`=`, Punctuation, Pop(1)},
    56  		},
    57  		"value": {
    58  			Include("whitespace"),
    59  			{"[a-z_@!$&*+\\-./:;<>?\\[\\\\\\]^`|~][\\w@!$&*+\\-./:;<>?\\[\\\\\\]^`|~]*", NameVariable, nil},
    60  			{`"`, LiteralString, Push("quoted-string")},
    61  			{`\{`, LiteralString, Push("braced-string")},
    62  			{`[\d]+`, LiteralNumber, nil},
    63  			{`#`, Punctuation, nil},
    64  			Default(Pop(1)),
    65  		},
    66  		"quoted-string": {
    67  			{`\{`, LiteralString, Push("braced-string")},
    68  			{`"`, LiteralString, Pop(1)},
    69  			{`[^\{\"]+`, LiteralString, nil},
    70  		},
    71  		"braced-string": {
    72  			{`\{`, LiteralString, Push()},
    73  			{`\}`, LiteralString, Pop(1)},
    74  			{`[^\{\}]+`, LiteralString, nil},
    75  		},
    76  		"whitespace": {
    77  			{`\s+`, Text, nil},
    78  		},
    79  	}
    80  }
    81  

View as plain text