Skip to content

Commit

Permalink
Update UsingByGroup documentation
Browse files Browse the repository at this point in the history
Bringing into line the documentation with the changed API for
UsingByGroup.
  • Loading branch information
kenshaw authored and alecthomas committed Oct 6, 2022
1 parent 739028e commit 48a2af1
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions emitters.go
Expand Up @@ -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.
Expand Down

0 comments on commit 48a2af1

Please sign in to comment.