diff options
| author | 2025-06-09 15:00:32 +0200 | |
|---|---|---|
| committer | 2025-06-09 15:00:32 +0200 | |
| commit | 8dfc2eb9df4aed8ffbb912ef6b6a8f40881b0706 (patch) | |
| tree | 785bda6d1c44fbcb037d03a64c29e36ab417a103 /examples | |
| parent | patok: use `self:next()` over `self.next()` when dropping tokens (diff) | |
This only shows off the lexer for now, but it does demonstrate the
drops feature.
Useful as a regression test for #1.
Acked-by: ChloƩ Vulquin <code@toast.bunkerlabs.net>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/minilua.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/minilua.lua b/examples/minilua.lua new file mode 100644 index 0000000..c31e606 --- /dev/null +++ b/examples/minilua.lua @@ -0,0 +1,35 @@ +local patok = require 'patok' + +local lexer = patok { + keyword = { + 'local', + 'function', + 'return', + 'end', + }, + equal = '=', + left_paren = '%(', + right_paren = '%)', +}{ + identifier = '[%w_][%w%d_]*', + whitespace = { '%s+', drop = true }, + number = '%d+', + op = '[+%-*/]', +}() + +local source = [[ +local function getSalary(hour) + return hour * 60 + 12 +end + +local bills = 40 +local savings = getSalary(4) - bills +]] + +lexer:reset(source) +local token = lexer:next() + +while token ~= nil do + print(token.value) + token = lexer:next() +end |
