1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-11-25 22:32:32 +02:00

Add a bunch of automatically translated lexers.

This commit is contained in:
Alec Thomas
2017-06-04 22:18:35 +10:00
parent b30de35ff1
commit 5dedc6e45b
20 changed files with 749 additions and 214 deletions

View File

@@ -20,7 +20,7 @@ func TestSimpleLexer(t *testing.T) {
Filenames: []string{"*.ini", "*.cfg"},
},
map[string][]Rule{
"root": []Rule{
"root": {
{`\s+`, Whitespace, nil},
{`;.*?$`, Comment, nil},
{`\[.*?\]$`, Keyword, nil},
@@ -29,24 +29,24 @@ func TestSimpleLexer(t *testing.T) {
},
)
require.NoError(t, err)
actual, err := lexer.Tokenise(`
actual, err := Tokenise(lexer, nil, `
; this is a comment
[section]
a = 10
`)
require.NoError(t, err)
expected := []Token{
Token{Whitespace, "\n\t"},
Token{Comment, "; this is a comment"},
Token{Whitespace, "\n\t"},
Token{Keyword, "[section]"},
Token{Whitespace, "\n\t"},
Token{Name, "a"},
Token{Whitespace, " "},
Token{Operator, "="},
Token{Whitespace, " "},
Token{LiteralString, "10"},
Token{Whitespace, "\n"},
{Whitespace, "\n\t"},
{Comment, "; this is a comment"},
{Whitespace, "\n\t"},
{Keyword, "[section]"},
{Whitespace, "\n\t"},
{Name, "a"},
{Whitespace, " "},
{Operator, "="},
{Whitespace, " "},
{LiteralString, "10"},
{Whitespace, "\n"},
}
require.Equal(t, expected, actual)
}