clark
What is clark
?
Clark
is a simple command-lexing package designed for chat systems such as Discord, Teamspeak, or Telegram. It is
therefore intended to facilitate the handling of user input and the parsing processes that follow.
Prerequisites
To use a Go package such as clark
, you must of course have Go installed on your system.
It is assumed that you have already worked with the Go environment. If this is not the case,
see this page first.
Installation
Install the package
To use clark
as a Go package, you must have it installed on your current system. If this is not the case, run the
command below.
go get -u github.com/lukasl-dev/clark
Install the CLI
Otherwise, if you want to use clark
inside your terminal, you need to have it installed as well. If this is not the
case, run the command below.
If you have no experience in this section,
read this.
go get -u github.com/lukasl-dev/clark/cmd/clark
Getting started
As an example, we create a strings.Reader
here.
reader := strings.NewReader("!help")
lex, err := clark.NewLexer(reader)
You can configure the lexer using the
variadic options.
See available Options.
lex, err := clark.NewLexer(
reader,
lexing.Prefixes("!"), lexing.Labels("help", "play", "help me"),
)
// handle error
Start the lexing progress
To execute the Lexer
, lex.Lex()
is executed as a goroutine. lex.Lex()
reads the passed reader lexicographically until io.EOF
and
returns the lexed tokens.
go lex.Lex()
Collect the lexed Tokens
During reading tokens are sent to the token
channel. This channel can be accessed via lex.Chan()
.
for token := range lex.Chan() {
// handle token
}
A Token has
a Type and an optional value.
See supported types.
Usage of the CLI