...

Source file src/github.com/alecthomas/chroma/lexers/s/smalltalk.go

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

     1  package s
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Smalltalk lexer.
     9  var Smalltalk = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Smalltalk",
    12  		Aliases:   []string{"smalltalk", "squeak", "st"},
    13  		Filenames: []string{"*.st"},
    14  		MimeTypes: []string{"text/x-smalltalk"},
    15  	},
    16  	smalltalkRules,
    17  ))
    18  
    19  func smalltalkRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`(<)(\w+:)(.*?)(>)`, ByGroups(Text, Keyword, Text, Text), nil},
    23  			Include("squeak fileout"),
    24  			Include("whitespaces"),
    25  			Include("method definition"),
    26  			{`(\|)([\w\s]*)(\|)`, ByGroups(Operator, NameVariable, Operator), nil},
    27  			Include("objects"),
    28  			{`\^|:=|_`, Operator, nil},
    29  			{`[\]({}.;!]`, Text, nil},
    30  		},
    31  		"method definition": {
    32  			{`([a-zA-Z]+\w*:)(\s*)(\w+)`, ByGroups(NameFunction, Text, NameVariable), nil},
    33  			{`^(\b[a-zA-Z]+\w*\b)(\s*)$`, ByGroups(NameFunction, Text), nil},
    34  			{`^([-+*/\\~<>=|&!?,@%]+)(\s*)(\w+)(\s*)$`, ByGroups(NameFunction, Text, NameVariable, Text), nil},
    35  		},
    36  		"blockvariables": {
    37  			Include("whitespaces"),
    38  			{`(:)(\s*)(\w+)`, ByGroups(Operator, Text, NameVariable), nil},
    39  			{`\|`, Operator, Pop(1)},
    40  			Default(Pop(1)),
    41  		},
    42  		"literals": {
    43  			{`'(''|[^'])*'`, LiteralString, Push("afterobject")},
    44  			{`\$.`, LiteralStringChar, Push("afterobject")},
    45  			{`#\(`, LiteralStringSymbol, Push("parenth")},
    46  			{`\)`, Text, Push("afterobject")},
    47  			{`(\d+r)?-?\d+(\.\d+)?(e-?\d+)?`, LiteralNumber, Push("afterobject")},
    48  		},
    49  		"_parenth_helper": {
    50  			Include("whitespaces"),
    51  			{`(\d+r)?-?\d+(\.\d+)?(e-?\d+)?`, LiteralNumber, nil},
    52  			{`[-+*/\\~<>=|&#!?,@%\w:]+`, LiteralStringSymbol, nil},
    53  			{`'(''|[^'])*'`, LiteralString, nil},
    54  			{`\$.`, LiteralStringChar, nil},
    55  			{`#*\(`, LiteralStringSymbol, Push("inner_parenth")},
    56  		},
    57  		"parenth": {
    58  			{`\)`, LiteralStringSymbol, Push("root", "afterobject")},
    59  			Include("_parenth_helper"),
    60  		},
    61  		"inner_parenth": {
    62  			{`\)`, LiteralStringSymbol, Pop(1)},
    63  			Include("_parenth_helper"),
    64  		},
    65  		"whitespaces": {
    66  			{`\s+`, Text, nil},
    67  			{`"(""|[^"])*"`, Comment, nil},
    68  		},
    69  		"objects": {
    70  			{`\[`, Text, Push("blockvariables")},
    71  			{`\]`, Text, Push("afterobject")},
    72  			{`\b(self|super|true|false|nil|thisContext)\b`, NameBuiltinPseudo, Push("afterobject")},
    73  			{`\b[A-Z]\w*(?!:)\b`, NameClass, Push("afterobject")},
    74  			{`\b[a-z]\w*(?!:)\b`, NameVariable, Push("afterobject")},
    75  			{`#("(""|[^"])*"|[-+*/\\~<>=|&!?,@%]+|[\w:]+)`, LiteralStringSymbol, Push("afterobject")},
    76  			Include("literals"),
    77  		},
    78  		"afterobject": {
    79  			{`! !$`, Keyword, Pop(1)},
    80  			Include("whitespaces"),
    81  			{`\b(ifTrue:|ifFalse:|whileTrue:|whileFalse:|timesRepeat:)`, NameBuiltin, Pop(1)},
    82  			{`\b(new\b(?!:))`, NameBuiltin, nil},
    83  			{`:=|_`, Operator, Pop(1)},
    84  			{`\b[a-zA-Z]+\w*:`, NameFunction, Pop(1)},
    85  			{`\b[a-zA-Z]+\w*`, NameFunction, nil},
    86  			{`\w+:?|[-+*/\\~<>=|&!?,@%]+`, NameFunction, Pop(1)},
    87  			{`\.`, Punctuation, Pop(1)},
    88  			{`;`, Punctuation, nil},
    89  			{`[\])}]`, Text, nil},
    90  			{`[\[({]`, Text, Pop(1)},
    91  		},
    92  		"squeak fileout": {
    93  			{`^"(""|[^"])*"!`, Keyword, nil},
    94  			{`^'(''|[^'])*'!`, Keyword, nil},
    95  			{`^(!)(\w+)( commentStamp: )(.*?)( prior: .*?!\n)(.*?)(!)`, ByGroups(Keyword, NameClass, Keyword, LiteralString, Keyword, Text, Keyword), nil},
    96  			{`^(!)(\w+(?: class)?)( methodsFor: )('(?:''|[^'])*')(.*?!)`, ByGroups(Keyword, NameClass, Keyword, LiteralString, Keyword), nil},
    97  			{`^(\w+)( subclass: )(#\w+)(\s+instanceVariableNames: )(.*?)(\s+classVariableNames: )(.*?)(\s+poolDictionaries: )(.*?)(\s+category: )(.*?)(!)`, ByGroups(NameClass, Keyword, LiteralStringSymbol, Keyword, LiteralString, Keyword, LiteralString, Keyword, LiteralString, Keyword, LiteralString, Keyword), nil},
    98  			{`^(\w+(?: class)?)(\s+instanceVariableNames: )(.*?)(!)`, ByGroups(NameClass, Keyword, LiteralString, Keyword), nil},
    99  			{`(!\n)(\].*)(! !)$`, ByGroups(Keyword, Text, Keyword), nil},
   100  			{`! !$`, Keyword, nil},
   101  		},
   102  	}
   103  }
   104  

View as plain text