mirror of
https://github.com/alecthomas/chroma.git
synced 2025-07-03 00:37:01 +02:00
Invert default "ensure newline" behaviour so that it is opt-in.
See #47.
This commit is contained in:
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestCoalesce(t *testing.T) {
|
func TestCoalesce(t *testing.T) {
|
||||||
lexer := Coalesce(MustNewLexer(&Config{DontEnsureNL: true}, Rules{
|
lexer := Coalesce(MustNewLexer(nil, Rules{
|
||||||
"root": []Rule{
|
"root": []Rule{
|
||||||
{`[!@#$%^&*()]`, Punctuation, nil},
|
{`[!@#$%^&*()]`, Punctuation, nil},
|
||||||
},
|
},
|
||||||
|
4
lexer.go
4
lexer.go
@ -44,9 +44,9 @@ type Config struct {
|
|||||||
// Strip all leading and trailing whitespace from the input
|
// Strip all leading and trailing whitespace from the input
|
||||||
// StripAll bool
|
// StripAll bool
|
||||||
|
|
||||||
// Make sure that the input does not end with a newline. This
|
// Make sure that the input ends with a newline. This
|
||||||
// is required for some lexers that consume input linewise.
|
// is required for some lexers that consume input linewise.
|
||||||
DontEnsureNL bool
|
EnsureNL bool
|
||||||
|
|
||||||
// If given and greater than 0, expand tabs in the input.
|
// If given and greater than 0, expand tabs in the input.
|
||||||
// TabSize int
|
// TabSize int
|
||||||
|
@ -11,6 +11,7 @@ var Makefile = Register(MustNewLexer(
|
|||||||
Aliases: []string{"make", "makefile", "mf", "bsdmake"},
|
Aliases: []string{"make", "makefile", "mf", "bsdmake"},
|
||||||
Filenames: []string{"*.mak", "*.mk", "Makefile", "makefile", "Makefile.*", "GNUmakefile"},
|
Filenames: []string{"*.mak", "*.mk", "Makefile", "makefile", "Makefile.*", "GNUmakefile"},
|
||||||
MimeTypes: []string{"text/x-makefile"},
|
MimeTypes: []string{"text/x-makefile"},
|
||||||
|
EnsureNL: true,
|
||||||
},
|
},
|
||||||
Rules{
|
Rules{
|
||||||
"root": {
|
"root": {
|
||||||
|
@ -44,7 +44,7 @@ func TestInclude(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCombine(t *testing.T) {
|
func TestCombine(t *testing.T) {
|
||||||
l := MustNewLexer(&Config{DontEnsureNL: true}, Rules{
|
l := MustNewLexer(nil, Rules{
|
||||||
"root": {{`hello`, String, Combined("world", "bye", "space")}},
|
"root": {{`hello`, String, Combined("world", "bye", "space")}},
|
||||||
"world": {{`world`, Name, nil}},
|
"world": {{`world`, Name, nil}},
|
||||||
"bye": {{`bye`, Name, nil}},
|
"bye": {{`bye`, Name, nil}},
|
||||||
|
@ -300,7 +300,7 @@ func (r *RegexLexer) Tokenise(options *TokeniseOptions, text string) (Iterator,
|
|||||||
if options == nil {
|
if options == nil {
|
||||||
options = defaultOptions
|
options = defaultOptions
|
||||||
}
|
}
|
||||||
if !r.config.DontEnsureNL && !strings.HasSuffix(text, "\n") {
|
if r.config.EnsureNL && !strings.HasSuffix(text, "\n") {
|
||||||
text += "\n"
|
text += "\n"
|
||||||
}
|
}
|
||||||
state := &LexerState{
|
state := &LexerState{
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestRemappingLexer(t *testing.T) {
|
func TestRemappingLexer(t *testing.T) {
|
||||||
var lexer Lexer = MustNewLexer(&Config{DontEnsureNL: true}, Rules{
|
var lexer Lexer = MustNewLexer(nil, Rules{
|
||||||
"root": {
|
"root": {
|
||||||
{`\s+`, Whitespace, nil},
|
{`\s+`, Whitespace, nil},
|
||||||
{`\w+`, Name, nil},
|
{`\w+`, Name, nil},
|
||||||
|
Reference in New Issue
Block a user