...

Source file src/github.com/alecthomas/chroma/lexers/g/genshi.go

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

     1  package g
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  	. "github.com/alecthomas/chroma/lexers/p"
     7  )
     8  
     9  // Genshi Text lexer.
    10  var GenshiText = internal.Register(MustNewLazyLexer(
    11  	&Config{
    12  		Name:      "Genshi Text",
    13  		Aliases:   []string{"genshitext"},
    14  		Filenames: []string{},
    15  		MimeTypes: []string{"application/x-genshi-text", "text/x-genshi"},
    16  	},
    17  	genshiTextRules,
    18  ))
    19  
    20  func genshiTextRules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`[^#$\s]+`, Other, nil},
    24  			{`^(\s*)(##.*)$`, ByGroups(Text, Comment), nil},
    25  			{`^(\s*)(#)`, ByGroups(Text, CommentPreproc), Push("directive")},
    26  			Include("variable"),
    27  			{`[#$\s]`, Other, nil},
    28  		},
    29  		"directive": {
    30  			{`\n`, Text, Pop(1)},
    31  			{`(?:def|for|if)\s+.*`, Using(Python), Pop(1)},
    32  			{`(choose|when|with)([^\S\n]+)(.*)`, ByGroups(Keyword, Text, Using(Python)), Pop(1)},
    33  			{`(choose|otherwise)\b`, Keyword, Pop(1)},
    34  			{`(end\w*)([^\S\n]*)(.*)`, ByGroups(Keyword, Text, Comment), Pop(1)},
    35  		},
    36  		"variable": {
    37  			{`(?<!\$)(\$\{)(.+?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
    38  			{`(?<!\$)(\$)([a-zA-Z_][\w.]*)`, NameVariable, nil},
    39  		},
    40  	}
    41  }
    42  
    43  // Html+Genshi lexer.
    44  var GenshiHTMLTemplate = internal.Register(MustNewLazyLexer(
    45  	&Config{
    46  		Name:         "Genshi HTML",
    47  		Aliases:      []string{"html+genshi", "html+kid"},
    48  		Filenames:    []string{},
    49  		MimeTypes:    []string{"text/html+genshi"},
    50  		NotMultiline: true,
    51  		DotAll:       true,
    52  	},
    53  	genshiMarkupRules,
    54  ))
    55  
    56  // Genshi lexer.
    57  var Genshi = internal.Register(MustNewLazyLexer(
    58  	&Config{
    59  		Name:         "Genshi",
    60  		Aliases:      []string{"genshi", "kid", "xml+genshi", "xml+kid"},
    61  		Filenames:    []string{"*.kid"},
    62  		MimeTypes:    []string{"application/x-genshi", "application/x-kid"},
    63  		NotMultiline: true,
    64  		DotAll:       true,
    65  	},
    66  	genshiMarkupRules,
    67  ))
    68  
    69  func genshiMarkupRules() Rules {
    70  	return Rules{
    71  		"root": {
    72  			{`[^<$]+`, Other, nil},
    73  			{`(<\?python)(.*?)(\?>)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
    74  			{`<\s*(script|style)\s*.*?>.*?<\s*/\1\s*>`, Other, nil},
    75  			{`<\s*py:[a-zA-Z0-9]+`, NameTag, Push("pytag")},
    76  			{`<\s*[a-zA-Z0-9:.]+`, NameTag, Push("tag")},
    77  			Include("variable"),
    78  			{`[<$]`, Other, nil},
    79  		},
    80  		"pytag": {
    81  			{`\s+`, Text, nil},
    82  			{`[\w:-]+\s*=`, NameAttribute, Push("pyattr")},
    83  			{`/?\s*>`, NameTag, Pop(1)},
    84  		},
    85  		"pyattr": {
    86  			{`(")(.*?)(")`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)},
    87  			{`(')(.*?)(')`, ByGroups(LiteralString, Using(Python), LiteralString), Pop(1)},
    88  			{`[^\s>]+`, LiteralString, Pop(1)},
    89  		},
    90  		"tag": {
    91  			{`\s+`, Text, nil},
    92  			{`py:[\w-]+\s*=`, NameAttribute, Push("pyattr")},
    93  			{`[\w:-]+\s*=`, NameAttribute, Push("attr")},
    94  			{`/?\s*>`, NameTag, Pop(1)},
    95  		},
    96  		"attr": {
    97  			{`"`, LiteralString, Push("attr-dstring")},
    98  			{`'`, LiteralString, Push("attr-sstring")},
    99  			{`[^\s>]*`, LiteralString, Pop(1)},
   100  		},
   101  		"attr-dstring": {
   102  			{`"`, LiteralString, Pop(1)},
   103  			Include("strings"),
   104  			{`'`, LiteralString, nil},
   105  		},
   106  		"attr-sstring": {
   107  			{`'`, LiteralString, Pop(1)},
   108  			Include("strings"),
   109  			{`'`, LiteralString, nil},
   110  		},
   111  		"strings": {
   112  			{`[^"'$]+`, LiteralString, nil},
   113  			Include("variable"),
   114  		},
   115  		"variable": {
   116  			{`(?<!\$)(\$\{)(.+?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
   117  			{`(?<!\$)(\$)([a-zA-Z_][\w\.]*)`, NameVariable, nil},
   118  		},
   119  	}
   120  }
   121  

View as plain text