...

Source file src/github.com/alecthomas/chroma/lexers/n/newspeak.go

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

     1  package n
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Newspeak lexer.
     9  var Newspeak = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Newspeak",
    12  		Aliases:   []string{"newspeak"},
    13  		Filenames: []string{"*.ns2"},
    14  		MimeTypes: []string{"text/x-newspeak"},
    15  	},
    16  	newspeakRules,
    17  ))
    18  
    19  func newspeakRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`\b(Newsqueak2)\b`, KeywordDeclaration, nil},
    23  			{`'[^']*'`, LiteralString, nil},
    24  			{`\b(class)(\s+)(\w+)(\s*)`, ByGroups(KeywordDeclaration, Text, NameClass, Text), nil},
    25  			{`\b(mixin|self|super|private|public|protected|nil|true|false)\b`, Keyword, nil},
    26  			{`(\w+\:)(\s*)([a-zA-Z_]\w+)`, ByGroups(NameFunction, Text, NameVariable), nil},
    27  			{`(\w+)(\s*)(=)`, ByGroups(NameAttribute, Text, Operator), nil},
    28  			{`<\w+>`, CommentSpecial, nil},
    29  			Include("expressionstat"),
    30  			Include("whitespace"),
    31  		},
    32  		"expressionstat": {
    33  			{`(\d+\.\d*|\.\d+|\d+[fF])[fF]?`, LiteralNumberFloat, nil},
    34  			{`\d+`, LiteralNumberInteger, nil},
    35  			{`:\w+`, NameVariable, nil},
    36  			{`(\w+)(::)`, ByGroups(NameVariable, Operator), nil},
    37  			{`\w+:`, NameFunction, nil},
    38  			{`\w+`, NameVariable, nil},
    39  			{`\(|\)`, Punctuation, nil},
    40  			{`\[|\]`, Punctuation, nil},
    41  			{`\{|\}`, Punctuation, nil},
    42  			{`(\^|\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-|:)`, Operator, nil},
    43  			{`\.|;`, Punctuation, nil},
    44  			Include("whitespace"),
    45  			Include("literals"),
    46  		},
    47  		"literals": {
    48  			{`\$.`, LiteralString, nil},
    49  			{`'[^']*'`, LiteralString, nil},
    50  			{`#'[^']*'`, LiteralStringSymbol, nil},
    51  			{`#\w+:?`, LiteralStringSymbol, nil},
    52  			{`#(\+|\/|~|\*|<|>|=|@|%|\||&|\?|!|,|-)+`, LiteralStringSymbol, nil},
    53  		},
    54  		"whitespace": {
    55  			{`\s+`, Text, nil},
    56  			{`"[^"]*"`, Comment, nil},
    57  		},
    58  	}
    59  }
    60  

View as plain text