toktok
Generic tokenizer written in Nim language ๐ Powered by Nim's Macros
Summary
| Latest Version | Unknown |
|---|---|
| License | MIT |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-07-21 05:25 |
Tags
Installation
nimble install toktok
choosenim install toktok
git clone https://github.com/openpeeps/toktok
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| toktok | โ | โ | โ | - | - | - | - | - | - | - |
Source
| Repository | https://github.com/openpeeps/toktok |
|---|---|
| Homepage | https://github.com/openpeeps/toktok |
| Registry Source | nimble_official |
README

Generic tokenizer written in Nim language, powered by Nim's Macros ๐
nimble install toktok
๐ Key Features
- โจ Powered by Nim's Macros
- ๐ช Based on
std/lexbase/ Zero Regular Expression - Compile-time generation using macro-based TokenKind
enum,lexbase - Runtime generation using TokenKind
tables,lexbase - Open Source |
MIT
[!NOTE] This is a generic Lexer, based on std/
streams,lexbaseandmacros. It is meant to be used by higher level parsers for writing any kind of tools or programs.[!NOTE] Compile with
-d:toktokdebugto inspect the generated code.
Quick Example
# Register your custom handlers
handlers:
proc handleImport(lex: var Lexer, kind: TokenKind) =
# tokenize `import x, y, z`
lex.kind = kind
# Register your tokens
registerTokens defaultSettings:
`const` = "const"
`echo` = "hello"
asgn = '=': # `=` is tkAsgn
eq = '=' # `==` is tkEQ
excl = '!':
ne = '='
at = '@':
import = tokenizer(handleImport, "import")
# Tokenizing...
var
tok = lexer.init(sample)
prev: TokenTuple
curr: TokenTuple = tok.getToken
next: TokenTuple = tok.getToken
proc walk(tok: var Lexer) =
prev = curr
curr = next
next = tok.getToken
while likely(curr.kind != tkEOF):
if tok.hasError: break
echo curr # use `getToken` consumer to get token by token
walk tok
TODO
- [ ] Runtime Token generation using tables/critbits
โค Contributions & Support
- ๐ Found a bug? Create a new Issue
- ๐ Wanna help? Fork it!
๐ฉ License
MIT license. Made by Humans from OpenPeeps.
Copyright © 2026 OpenPeeps & Contributors — All rights reserved.