Created
February 9, 2026 18:04
-
-
Save hishamhm/45427652b41698f1991e4fe78e41e77c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S tl run | |
| math.randomseed(os.time()) | |
| print("micro fuzz!") | |
| --local parser = require("tl") | |
| local parser = require("teal.parser") | |
| local tokens = { | |
| -- cat docs/src/grammar.md | sed 's,’,’\n,g;s,‘,\n‘,g' | grep '^‘' | sort -u | tr -d '‘’' | sed 's/\(.*\)/"\1",/g' | |
| "#", | |
| "%", | |
| "&", | |
| "(", | |
| ")", | |
| "*", | |
| "+", | |
| ",", | |
| "-", | |
| "...", | |
| "..", | |
| ".", | |
| "//", | |
| "/", | |
| "::", | |
| ":", | |
| ";", | |
| "<<", | |
| "<=", | |
| "<", | |
| "==", | |
| "=", | |
| ">=", | |
| ">>", | |
| ">", | |
| "?", | |
| "[", | |
| "]", | |
| "^", | |
| "{", | |
| "|", | |
| "}", | |
| "~=", | |
| "~", | |
| "and", | |
| "as", | |
| "boolean", | |
| "break", | |
| "do", | |
| "else", | |
| "elseif", | |
| "end", | |
| "enum", | |
| "false", | |
| "for", | |
| "function", | |
| "global", | |
| "goto", | |
| "if", | |
| "in", | |
| "interface", | |
| "is", | |
| "local", | |
| "macroexp", | |
| "metamethod", | |
| "nil", | |
| "not", | |
| "number", | |
| "or", | |
| "record", | |
| "repeat", | |
| "require", | |
| "return", | |
| "string", | |
| "then", | |
| "true", | |
| "type", | |
| "until", | |
| "userdata", | |
| "where", | |
| "while", | |
| -- other tokens | |
| "\"a string\"", | |
| "'a string'", | |
| "[==[a string]==]", | |
| "--#pragma arity on\n", | |
| "0", | |
| "123.456", | |
| "-2", | |
| "-234.56", | |
| -- macros | |
| "$", | |
| "`", | |
| "```", | |
| -- snippets | |
| "local record Foo", | |
| "local record Foo x: ", | |
| "interface Bla is Foo where", | |
| "if x < 2 then", | |
| "while true do", | |
| "else if x > 3 then", | |
| "local function hello()", | |
| "for _, x in ipairs(foo) do", | |
| "local xyz = ", | |
| "global xyz = ", | |
| "local xyz: ", | |
| "global xyz: ", | |
| "; local record Foo", | |
| "; local record Foo x: ", | |
| "; interface Bla is Foo where", | |
| "; if x < 2 then", | |
| "; while true do", | |
| "; else if x > 3 then", | |
| "; local function hello()", | |
| "; for _, x in ipairs(foo) do", | |
| "; local xyz = ", | |
| "; global xyz = ", | |
| "; local xyz: ", | |
| "; global xyz: ", | |
| "end", | |
| "end", | |
| "end", | |
| "end", | |
| } | |
| local program_tokens = {} | |
| for _ = 1, 10 do | |
| table.insert(program_tokens, tokens[math.random(#tokens)]) | |
| end | |
| while true do | |
| local program = table.concat(program_tokens, " ") | |
| --print("\27[2J\27[H") | |
| local _, errs = parser.parse(program, "foo.tl") | |
| if #errs > 0 then | |
| if errs[1].x > 50 then | |
| print(#program_tokens, errs[1].x, program) | |
| end | |
| local first_error = errs[1].x | |
| local good_tokens = 0 | |
| local len = 0 | |
| for i = 1, #program_tokens do | |
| if len < first_error then | |
| len = len + #program_tokens[i] + 1 | |
| good_tokens = good_tokens + 1 | |
| end | |
| end | |
| while #program_tokens > good_tokens do | |
| table.remove(program_tokens) | |
| end | |
| if math.random(2) == 1 then | |
| table.remove(program_tokens) | |
| end | |
| if math.random(2) == 1 then | |
| table.remove(program_tokens) | |
| end | |
| end | |
| if math.random(3) == 1 then | |
| table.insert(program_tokens, tokens[math.random(#tokens)]) | |
| end | |
| if math.random(3) == 1 then | |
| table.insert(program_tokens, tokens[math.random(#tokens)]) | |
| end | |
| if math.random(3) == 1 then | |
| table.insert(program_tokens, tokens[math.random(#tokens)]) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment