From 48a2af1145fc0e355d0646d1d4e30078cd3f318b Mon Sep 17 00:00:00 2001 From: Kenneth Shaw Date: Tue, 23 Aug 2022 06:15:32 +0700 Subject: [PATCH] Update UsingByGroup documentation Bringing into line the documentation with the changed API for UsingByGroup. --- emitters.go | 55 +++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/emitters.go b/emitters.go index 67b80a8e7..0788b5b21 100644 --- a/emitters.go +++ b/emitters.go @@ -81,42 +81,39 @@ func ByGroupNames(emitters map[string]Emitter) Emitter { } // UsingByGroup emits tokens for the matched groups in the regex using a -// "sublexer". Used when lexing code blocks where the name of a sublexer is +// sublexer. Used when lexing code blocks where the name of a sublexer is // contained within the block, for example on a Markdown text block or SQL // language block. // -// The sublexer will be retrieved using sublexerGetFunc (typically -// internal.Get), using the captured value from the matched sublexerNameGroup. -// -// If sublexerGetFunc returns a non-nil lexer for the captured sublexerNameGroup, -// then tokens for the matched codeGroup will be emitted using the retrieved -// lexer. Otherwise, if the sublexer is nil, then tokens will be emitted from -// the passed emitter. +// An attempt to load the sublexer will be made using the captured value from +// the text of the matched sublexerNameGroup. If a sublexer matching the +// sublexerNameGroup is available, then tokens for the matched codeGroup will +// be emitted using the sublexer. Otherwise, if no sublexer is available, then +// tokens will be emitted from the passed emitter. // // Example: // -// var Markdown = internal.Register(MustNewLexer( -// &Config{ -// Name: "markdown", -// Aliases: []string{"md", "mkd"}, -// Filenames: []string{"*.md", "*.mkd", "*.markdown"}, -// MimeTypes: []string{"text/x-markdown"}, -// }, -// Rules{ -// "root": { -// {"^(```)(\\w+)(\\n)([\\w\\W]*?)(^```$)", -// UsingByGroup( -// internal.Get, -// 2, 4, -// String, String, String, Text, String, -// ), -// nil, -// }, -// }, -// }, -// )) +// var Markdown = internal.Register(MustNewLexer( +// &Config{ +// Name: "markdown", +// Aliases: []string{"md", "mkd"}, +// Filenames: []string{"*.md", "*.mkd", "*.markdown"}, +// MimeTypes: []string{"text/x-markdown"}, +// }, +// Rules{ +// "root": { +// {"^(```)(\\w+)(\\n)([\\w\\W]*?)(^```$)", +// UsingByGroup( +// 2, 4, +// String, String, String, Text, String, +// ), +// nil, +// }, +// }, +// }, +// )) // -// See the lexers/m/markdown.go for the complete example. +// See the lexers/markdown.go for the complete example. // // Note: panic's if the number of emitters does not equal the number of matched // groups in the regex.