Skip to content

Commit

Permalink
Run gofmt -s over the codebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Sep 26, 2017
1 parent c39abfb commit bc2d668
Show file tree
Hide file tree
Showing 33 changed files with 1,007 additions and 1,007 deletions.
2 changes: 1 addition & 1 deletion coalesce_test.go
Expand Up @@ -9,7 +9,7 @@ import (
func TestCoalesce(t *testing.T) {
lexer := Coalesce(MustNewLexer(nil, Rules{
"root": []Rule{
Rule{`[!@#$%^&*()]`, Punctuation, nil},
{`[!@#$%^&*()]`, Punctuation, nil},
},
}))
actual, err := Tokenise(lexer, nil, "!@#$")
Expand Down
6 changes: 3 additions & 3 deletions formatters/html/html_test.go
Expand Up @@ -36,14 +36,14 @@ func TestSplitTokensIntoLines(t *testing.T) {
{Value: " world\nwhat?\n", Type: chroma.NameKeyword},
}
expected := [][]*chroma.Token{
[]*chroma.Token{
{
{Type: chroma.NameKeyword, Value: "hello"},
{Type: chroma.NameKeyword, Value: " world\n"},
},
[]*chroma.Token{
{
{Type: chroma.NameKeyword, Value: "what?\n"},
},
[]*chroma.Token{
{
{Type: chroma.NameKeyword},
},
}
Expand Down
4 changes: 2 additions & 2 deletions formatters/tty_indexed.go
Expand Up @@ -16,7 +16,7 @@ type ttyTable struct {
var c = chroma.MustParseColour

var ttyTables = map[int]*ttyTable{
8: &ttyTable{
8: {
foreground: map[chroma.Colour]string{
c("#000000"): "\033[30m", c("#7f0000"): "\033[31m", c("#007f00"): "\033[32m", c("#7f7fe0"): "\033[33m",
c("#00007f"): "\033[34m", c("#7f007f"): "\033[35m", c("#007f7f"): "\033[36m", c("#e5e5e5"): "\033[37m",
Expand All @@ -30,7 +30,7 @@ var ttyTables = map[int]*ttyTable{
c("#0000ff"): "\033[104m", c("#ff00ff"): "\033[105m", c("#00ffff"): "\033[106m", c("#ffffff"): "\033[107m",
},
},
256: &ttyTable{
256: {
foreground: map[chroma.Colour]string{
c("#000000"): "\033[38;5;0m", c("#800000"): "\033[38;5;1m", c("#008000"): "\033[38;5;2m", c("#808000"): "\033[38;5;3m",
c("#000080"): "\033[38;5;4m", c("#800080"): "\033[38;5;5m", c("#008080"): "\033[38;5;6m", c("#c0c0c0"): "\033[38;5;7m",
Expand Down
146 changes: 73 additions & 73 deletions lexers/rst.go
@@ -1,85 +1,85 @@
package lexers

import (
"strings"
"strings"

. "github.com/alecthomas/chroma" // nolint
. "github.com/alecthomas/chroma" // nolint
)

// Restructuredtext lexer.
var Restructuredtext = Register(MustNewLexer(
&Config{
Name: "reStructuredText",
Aliases: []string{"rst", "rest", "restructuredtext"},
Filenames: []string{"*.rst", "*.rest"},
MimeTypes: []string{"text/x-rst", "text/prs.fallenstein.rst"},
},
Rules{
"root": {
{"^(=+|-+|`+|:+|\\.+|\\'+|\"+|~+|\\^+|_+|\\*+|\\++|#+)([ \\t]*\\n)(.+)(\\n)(\\1)(\\n)", ByGroups(GenericHeading, Text, GenericHeading, Text, GenericHeading, Text), nil},
{"^(\\S.*)(\\n)(={3,}|-{3,}|`{3,}|:{3,}|\\.{3,}|\\'{3,}|\"{3,}|~{3,}|\\^{3,}|_{3,}|\\*{3,}|\\+{3,}|#{3,})(\\n)", ByGroups(GenericHeading, Text, GenericHeading, Text), nil},
{`^(\s*)([-*+])( .+\n(?:\1 .+\n)*)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)([0-9#ivxlcmIVXLCM]+\.)( .+\n(?:\1 .+\n)*)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)(\(?[0-9#ivxlcmIVXLCM]+\))( .+\n(?:\1 .+\n)*)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)([A-Z]+\.)( .+\n(?:\1 .+\n)+)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)(\(?[A-Za-z]+\))( .+\n(?:\1 .+\n)+)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)(\|)( .+\n(?:\| .+\n)*)`, ByGroups(Text, Operator, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)((?:source)?code(?:-block)?)(::)([ \t]*)([^\n]+)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*|)\n)+)`, EmitterFunc(rstCodeBlock), nil},
{`^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))`, ByGroups(Punctuation, Text, OperatorWord, Punctuation, Text, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)(_(?:[^:\\]|\\.)+:)(.*?)$`, ByGroups(Punctuation, Text, NameTag, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)(\[.+\])(.*?)$`, ByGroups(Punctuation, Text, NameTag, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)(\|.+\|)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))`, ByGroups(Punctuation, Text, NameTag, Text, OperatorWord, Punctuation, Text, UsingSelf("inline")), nil},
{`^ *\.\..*(\n( +.*\n|\n)+)?`, CommentPreproc, nil},
{`^( *)(:[a-zA-Z-]+:)(\s*)$`, ByGroups(Text, NameClass, Text), nil},
{`^( *)(:.*?:)([ \t]+)(.*?)$`, ByGroups(Text, NameClass, Text, NameFunction), nil},
{`^(\S.*(?<!::)\n)((?:(?: +.*)\n)+)`, ByGroups(UsingSelf("inline"), UsingSelf("inline")), nil},
{`(::)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\3.*|)\n)+)`, ByGroups(LiteralStringEscape, Text, LiteralString, LiteralString, Text, LiteralString), nil},
Include("inline"),
},
"inline": {
{`\\.`, Text, nil},
{"``", LiteralString, Push("literal")},
{"(`.+?)(<.+?>)(`__?)", ByGroups(LiteralString, LiteralStringInterpol, LiteralString), nil},
{"`.+?`__?", LiteralString, nil},
{"(`.+?`)(:[a-zA-Z0-9:-]+?:)?", ByGroups(NameVariable, NameAttribute), nil},
{"(:[a-zA-Z0-9:-]+?:)(`.+?`)", ByGroups(NameAttribute, NameVariable), nil},
{`\*\*.+?\*\*`, GenericStrong, nil},
{`\*.+?\*`, GenericEmph, nil},
{`\[.*?\]_`, LiteralString, nil},
{`<.+?>`, NameTag, nil},
{"[^\\\\\\n\\[*`:]+", Text, nil},
{`.`, Text, nil},
},
"literal": {
{"[^`]+", LiteralString, nil},
{"``((?=$)|(?=[-/:.,; \\n\\x00\\\u2010\\\u2011\\\u2012\\\u2013\\\u2014\\\u00a0\\'\\\"\\)\\]\\}\\>\\\u2019\\\u201d\\\u00bb\\!\\?]))", LiteralString, Pop(1)},
{"`", LiteralString, nil},
},
},
&Config{
Name: "reStructuredText",
Aliases: []string{"rst", "rest", "restructuredtext"},
Filenames: []string{"*.rst", "*.rest"},
MimeTypes: []string{"text/x-rst", "text/prs.fallenstein.rst"},
},
Rules{
"root": {
{"^(=+|-+|`+|:+|\\.+|\\'+|\"+|~+|\\^+|_+|\\*+|\\++|#+)([ \\t]*\\n)(.+)(\\n)(\\1)(\\n)", ByGroups(GenericHeading, Text, GenericHeading, Text, GenericHeading, Text), nil},
{"^(\\S.*)(\\n)(={3,}|-{3,}|`{3,}|:{3,}|\\.{3,}|\\'{3,}|\"{3,}|~{3,}|\\^{3,}|_{3,}|\\*{3,}|\\+{3,}|#{3,})(\\n)", ByGroups(GenericHeading, Text, GenericHeading, Text), nil},
{`^(\s*)([-*+])( .+\n(?:\1 .+\n)*)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)([0-9#ivxlcmIVXLCM]+\.)( .+\n(?:\1 .+\n)*)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)(\(?[0-9#ivxlcmIVXLCM]+\))( .+\n(?:\1 .+\n)*)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)([A-Z]+\.)( .+\n(?:\1 .+\n)+)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)(\(?[A-Za-z]+\))( .+\n(?:\1 .+\n)+)`, ByGroups(Text, LiteralNumber, UsingSelf("inline")), nil},
{`^(\s*)(\|)( .+\n(?:\| .+\n)*)`, ByGroups(Text, Operator, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)((?:source)?code(?:-block)?)(::)([ \t]*)([^\n]+)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\8.*|)\n)+)`, EmitterFunc(rstCodeBlock), nil},
{`^( *\.\.)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))`, ByGroups(Punctuation, Text, OperatorWord, Punctuation, Text, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)(_(?:[^:\\]|\\.)+:)(.*?)$`, ByGroups(Punctuation, Text, NameTag, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)(\[.+\])(.*?)$`, ByGroups(Punctuation, Text, NameTag, UsingSelf("inline")), nil},
{`^( *\.\.)(\s*)(\|.+\|)(\s*)([\w:-]+?)(::)(?:([ \t]*)(.*))`, ByGroups(Punctuation, Text, NameTag, Text, OperatorWord, Punctuation, Text, UsingSelf("inline")), nil},
{`^ *\.\..*(\n( +.*\n|\n)+)?`, CommentPreproc, nil},
{`^( *)(:[a-zA-Z-]+:)(\s*)$`, ByGroups(Text, NameClass, Text), nil},
{`^( *)(:.*?:)([ \t]+)(.*?)$`, ByGroups(Text, NameClass, Text, NameFunction), nil},
{`^(\S.*(?<!::)\n)((?:(?: +.*)\n)+)`, ByGroups(UsingSelf("inline"), UsingSelf("inline")), nil},
{`(::)(\n[ \t]*\n)([ \t]+)(.*)(\n)((?:(?:\3.*|)\n)+)`, ByGroups(LiteralStringEscape, Text, LiteralString, LiteralString, Text, LiteralString), nil},
Include("inline"),
},
"inline": {
{`\\.`, Text, nil},
{"``", LiteralString, Push("literal")},
{"(`.+?)(<.+?>)(`__?)", ByGroups(LiteralString, LiteralStringInterpol, LiteralString), nil},
{"`.+?`__?", LiteralString, nil},
{"(`.+?`)(:[a-zA-Z0-9:-]+?:)?", ByGroups(NameVariable, NameAttribute), nil},
{"(:[a-zA-Z0-9:-]+?:)(`.+?`)", ByGroups(NameAttribute, NameVariable), nil},
{`\*\*.+?\*\*`, GenericStrong, nil},
{`\*.+?\*`, GenericEmph, nil},
{`\[.*?\]_`, LiteralString, nil},
{`<.+?>`, NameTag, nil},
{"[^\\\\\\n\\[*`:]+", Text, nil},
{`.`, Text, nil},
},
"literal": {
{"[^`]+", LiteralString, nil},
{"``((?=$)|(?=[-/:.,; \\n\\x00\\\u2010\\\u2011\\\u2012\\\u2013\\\u2014\\\u00a0\\'\\\"\\)\\]\\}\\>\\\u2019\\\u201d\\\u00bb\\!\\?]))", LiteralString, Pop(1)},
{"`", LiteralString, nil},
},
},
))

func rstCodeBlock(groups []string, lexer Lexer) Iterator {
iterators := []Iterator{}
tokens := []*Token{
{Punctuation, groups[1]},
{Text, groups[2]},
{OperatorWord, groups[3]},
{Punctuation, groups[4]},
{Text, groups[5]},
{Keyword, groups[6]},
{Text, groups[7]},
}
code := strings.Join(groups[8:], "")
lexer = Get(groups[6])
if lexer == nil {
tokens = append(tokens, &Token{String, code})
iterators = append(iterators, Literator(tokens...))
} else {
sub, err := lexer.Tokenise(nil, code)
if err != nil {
panic(err)
}
iterators = append(iterators, Literator(tokens...), sub)
}
return Concaterator(iterators...)
iterators := []Iterator{}
tokens := []*Token{
{Punctuation, groups[1]},
{Text, groups[2]},
{OperatorWord, groups[3]},
{Punctuation, groups[4]},
{Text, groups[5]},
{Keyword, groups[6]},
{Text, groups[7]},
}
code := strings.Join(groups[8:], "")
lexer = Get(groups[6])
if lexer == nil {
tokens = append(tokens, &Token{String, code})
iterators = append(iterators, Literator(tokens...))
} else {
sub, err := lexer.Tokenise(nil, code)
if err != nil {
panic(err)
}
iterators = append(iterators, Literator(tokens...), sub)
}
return Concaterator(iterators...)
}
20 changes: 10 additions & 10 deletions styles/abap.go
@@ -1,18 +1,18 @@
package styles

import (
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma"
)

// Abap style.
var Abap = Register(chroma.MustNewStyle("abap", chroma.StyleEntries{
chroma.Comment: "italic #888",
chroma.CommentSpecial: "#888",
chroma.Keyword: "#00f",
chroma.OperatorWord: "#00f",
chroma.Name: "#000",
chroma.LiteralNumber: "#3af",
chroma.LiteralString: "#5a2",
chroma.Error: "#F00",
chroma.Background: " bg:#ffffff",
chroma.Comment: "italic #888",
chroma.CommentSpecial: "#888",
chroma.Keyword: "#00f",
chroma.OperatorWord: "#00f",
chroma.Name: "#000",
chroma.LiteralNumber: "#3af",
chroma.LiteralString: "#5a2",
chroma.Error: "#F00",
chroma.Background: " bg:#ffffff",
}))
34 changes: 17 additions & 17 deletions styles/algol.go
@@ -1,25 +1,25 @@
package styles

import (
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma"
)

// Algol style.
var Algol = Register(chroma.MustNewStyle("algol", chroma.StyleEntries{
chroma.Comment: "italic #888",
chroma.CommentPreproc: "bold noitalic #888",
chroma.CommentSpecial: "bold noitalic #888",
chroma.Keyword: "underline bold",
chroma.KeywordDeclaration: "italic",
chroma.NameBuiltin: "bold italic",
chroma.NameBuiltinPseudo: "bold italic",
chroma.NameNamespace: "bold italic #666",
chroma.NameClass: "bold italic #666",
chroma.NameFunction: "bold italic #666",
chroma.NameVariable: "bold italic #666",
chroma.NameConstant: "bold italic #666",
chroma.OperatorWord: "bold",
chroma.LiteralString: "italic #666",
chroma.Error: "border:#FF0000",
chroma.Background: " bg:#ffffff",
chroma.Comment: "italic #888",
chroma.CommentPreproc: "bold noitalic #888",
chroma.CommentSpecial: "bold noitalic #888",
chroma.Keyword: "underline bold",
chroma.KeywordDeclaration: "italic",
chroma.NameBuiltin: "bold italic",
chroma.NameBuiltinPseudo: "bold italic",
chroma.NameNamespace: "bold italic #666",
chroma.NameClass: "bold italic #666",
chroma.NameFunction: "bold italic #666",
chroma.NameVariable: "bold italic #666",
chroma.NameConstant: "bold italic #666",
chroma.OperatorWord: "bold",
chroma.LiteralString: "italic #666",
chroma.Error: "border:#FF0000",
chroma.Background: " bg:#ffffff",
}))
34 changes: 17 additions & 17 deletions styles/algol_nu.go
@@ -1,25 +1,25 @@
package styles

import (
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma"
)

// Algol_Nu style.
var Algol_Nu = Register(chroma.MustNewStyle("algol_nu", chroma.StyleEntries{
chroma.Comment: "italic #888",
chroma.CommentPreproc: "bold noitalic #888",
chroma.CommentSpecial: "bold noitalic #888",
chroma.Keyword: "bold",
chroma.KeywordDeclaration: "italic",
chroma.NameBuiltin: "bold italic",
chroma.NameBuiltinPseudo: "bold italic",
chroma.NameNamespace: "bold italic #666",
chroma.NameClass: "bold italic #666",
chroma.NameFunction: "bold italic #666",
chroma.NameVariable: "bold italic #666",
chroma.NameConstant: "bold italic #666",
chroma.OperatorWord: "bold",
chroma.LiteralString: "italic #666",
chroma.Error: "border:#FF0000",
chroma.Background: " bg:#ffffff",
chroma.Comment: "italic #888",
chroma.CommentPreproc: "bold noitalic #888",
chroma.CommentSpecial: "bold noitalic #888",
chroma.Keyword: "bold",
chroma.KeywordDeclaration: "italic",
chroma.NameBuiltin: "bold italic",
chroma.NameBuiltinPseudo: "bold italic",
chroma.NameNamespace: "bold italic #666",
chroma.NameClass: "bold italic #666",
chroma.NameFunction: "bold italic #666",
chroma.NameVariable: "bold italic #666",
chroma.NameConstant: "bold italic #666",
chroma.OperatorWord: "bold",
chroma.LiteralString: "italic #666",
chroma.Error: "border:#FF0000",
chroma.Background: " bg:#ffffff",
}))
34 changes: 17 additions & 17 deletions styles/arduino.go
@@ -1,25 +1,25 @@
package styles

import (
"github.com/alecthomas/chroma"
"github.com/alecthomas/chroma"
)

// Arduino style.
var Arduino = Register(chroma.MustNewStyle("arduino", chroma.StyleEntries{
chroma.Error: "#a61717",
chroma.Comment: "#95a5a6",
chroma.CommentPreproc: "#728E00",
chroma.Keyword: "#728E00",
chroma.KeywordConstant: "#00979D",
chroma.KeywordPseudo: "#00979D",
chroma.KeywordReserved: "#00979D",
chroma.KeywordType: "#00979D",
chroma.Operator: "#728E00",
chroma.Name: "#434f54",
chroma.NameBuiltin: "#728E00",
chroma.NameFunction: "#D35400",
chroma.NameOther: "#728E00",
chroma.LiteralNumber: "#8A7B52",
chroma.LiteralString: "#7F8C8D",
chroma.Background: " bg:#ffffff",
chroma.Error: "#a61717",
chroma.Comment: "#95a5a6",
chroma.CommentPreproc: "#728E00",
chroma.Keyword: "#728E00",
chroma.KeywordConstant: "#00979D",
chroma.KeywordPseudo: "#00979D",
chroma.KeywordReserved: "#00979D",
chroma.KeywordType: "#00979D",
chroma.Operator: "#728E00",
chroma.Name: "#434f54",
chroma.NameBuiltin: "#728E00",
chroma.NameFunction: "#D35400",
chroma.NameOther: "#728E00",
chroma.LiteralNumber: "#8A7B52",
chroma.LiteralString: "#7F8C8D",
chroma.Background: " bg:#ffffff",
}))

0 comments on commit bc2d668

Please sign in to comment.