diff options
| author | Felix Hanley <felix@userspace.com.au> | 2019-10-29 11:16:44 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2019-10-29 11:16:44 +0000 |
| commit | 9cc6bc35d7f22560a70d6f2c980a19fb401564a3 (patch) | |
| tree | a44ad08a458e02422cec7f2327e9be56392db626 | |
| parent | 19f04a689c3058e3cee7fa7496d0e96343fd2ec6 (diff) | |
| download | lexer-9cc6bc35d7f22560a70d6f2c980a19fb401564a3.tar.gz lexer-9cc6bc35d7f22560a70d6f2c980a19fb401564a3.tar.bz2 | |
Update package source and readme
| -rw-r--r-- | README.md | 32 | ||||
| -rw-r--r-- | go.mod | 2 |
2 files changed, 27 insertions, 7 deletions
@@ -1,14 +1,34 @@ # Generic Go lexer -A very simple lexer. +A very simple state-based lexer. ```go -import "github.com/felix/lexer" -``` +import "src.userspace.com.au/lexer" -or +// Define the tokens for the lexer. +const ( + _ lexer.TokenType = iota + tBREStart + tBREEnd + tRangeStart + tRangeDash + tRangeEnd + tCharacter + tClass + tNot +) -```go -import "src.userspace.com.au/felix/lexer" +// Define states returning a StateFunc. +func startState(l *lexer.Lexer) lexer.StateFunc { + l.SkipWhitespace() + r := l.Next() + if r != '[' { + return l.Error("expecting [") + } + l.Emit(tBREStart) + return beFirstState +} ``` +For a complete (but simple) example see the code in a [bracket expression +generator](https://src.userspace.com.au/bechars/tree/lexer.go). @@ -1,3 +1,3 @@ -module src.userspace.com.au/felix/lexer +module src.userspace.com.au/lexer go 1.12 |
