lexer-generator
Skill17 starsChanged 9 months agoApache-2.0View on GitHub
Generates lexical analyzers from regex specifications. Use when: (1)
In this repository98 other files it gives its agents.
- abstract-interpretation-engineSkill
- abstract-machineSkill
- acsl-annotation-assistantSkill
- actor-model-implementerSkill
- algebraic-effectsSkill
- alias-and-points-to-analysisSkill
- axiomatic-semanticsSkill
- bidirectional-type-checkingSkill
- bisimulation-checkerSkill
- capability-systemSkill
- closure-converterSkill
- common-subexpression-eliminatorSkill
- concurrency-verifierSkill
- constant-propagation-passSkill
- contextual-equivalenceSkill
- control-flow-analysisSkill
- coq-proof-assistantSkill
- cps-transformerSkill
- dafny-verifierSkill
- dataflow-analysis-frameworkSkill
- dead-code-eliminatorSkill
- defunctionalizationSkill
- denotational-semantics-builderSkill
- dependent-type-implementerSkill
- dsl-embeddingSkill
- effect-handlers-implementerSkill
- effect-systemSkill
- effect-type-systemSkill
- escape-analysisSkill
- existential-typesSkill
- ffi-designerSkill
- fuzzer-generatorSkill
- gadt-implementerSkill
- garbage-collector-implementerSkill
- graalvm-truffle-implementerSkill
- gradual-typing-implementerSkill
- higher-order-abstract-syntaxSkill
- hoare-logic-verifierSkill
- incremental-computationSkill
- information-flow-analyzerSkill
- inline-expanderSkill
- interprocedural-analysisSkill
- invariant-generatorSkill
- jit-compiler-builderSkill
- lambda-calculus-interpreterSkill
- language-server-protocolSkill
- lean-proverSkill
- linear-type-implementerSkill
- liveness-analysisSkill
- llvm-backend-generatorSkill
- lock-free-data-structureSkill
- loop-optimizerSkill
- loop-termination-proverSkill
- macro-expanderSkill
- memory-allocatorSkill
- message-passing-systemSkill
- mlir-dialect-designerSkill
- model-checkerSkill
- module-systemSkill
- monad-transformerSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 54
Consider lookahead for better error recovery
- Distinctive: line 93
For simple formats: Use existing parsers (JSON, CSV)
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Lexer Generator
Generates lexical analyzers (tokenizers) from regex specifications.
When to Use
- Building compilers or interpreters
- Creating lexers for DSLs
- Parsing structured text formats
- Implementing programming languages
What This Skill Does
- Parses regex specs - Converts regex to NFA/DFA
- Generates lexers - Produces executable tokenizer code
- Handles conflicts - Resolves longest-match ambiguities
- Optimizes - Minimizes DFA states
Key Concepts
| Concept | Description |
| Token | Lexical unit (keyword, identifier, number) |
| Lexeme | Actual source text matched |
| Position | Location info for error reporting |
| Longest match | Prefer longest matching lexeme |
| Priority | First matching rule wins (tie-break) |
Tips
- Handle unicode properly (use Unicode flag)
- Track line/column for error messages
- Skip comments and whitespace
- Handle reserved words (keyword vs identifier)
- Consider lookahead for better error recovery
Common Issues
| Issue | Solution |
| Ambiguous patterns | Use longest match + priority |
| Performance | Use DFA, not backtracking |
| Unicode | Use re.UNICODE flag |
| String literals | Use greedy matching carefully |
Related Skills
parser-generator- Generate parsersprogram-transformer- Build ASTslambda-calculus-interpreter- Execute programs
Canonical References
| Reference | Why It Matters |
| Aho et al., "Compilers: Principles, Techniques, and Tools" (1986) | Dragon Book; chapters 3-4 on lexical analysis |
| Thompson, "Programming Techniques: Regular Expression Search Algorithm" (1968) | Original NFA construction |
| McNaughton & Yamada, "Regular Expressions and State Graphs" (1960) | DFA construction |
| Fischer & LeBlanc, "Crafting a Compiler" (1988) | Practical lexer design |
| Russ Cox, "Regular Expression Matching Can Be Simple and Fast" (2007) | Modern regex implementation |
Tradeoffs and Limitations
Lexer Algorithm Tradeoffs
| Approach | Pros | Cons |
| Regex-based | Easy to write | May backtrack |
| NFA-based | Simple construction | Large states |
| DFA-based | Fast matching | Large table |
When NOT to Build a Custom Lexer
- For simple formats: Use existing parsers (JSON, CSV)
- For prototyping: String splitting may suffice
- For existing tools: Lex/Flex generate efficient lexers
Complexity Considerations
- DFA construction: O(n²) worst case in states
- Matching: O(1) per character with DFA
- NFA simulation: O(n) per character
Limitations
- Ambiguity: Keywords vs identifiers, longest match rule
- Context sensitivity: Can't handle indentation (use parser)
- Unicode: Complex character classes
- Error recovery: Hard to provide good error messages
- Performance: Backtracking regex can be exponential
Research Tools & Artifacts
Lexer generators and tools:
| Tool | Language | What to Learn |
| Flex | C | Fast lexer generation |
| ANTLR lexer | Java | Integrated lexing/parsing |
| PLY | Python | Lex in Python |
| rustlex | Rust | Safe lexer generation |
| JFlex | Java | Java lexer generation |
Regex Implementations
- RE2 (Google) - DFA-based, linear time
- Hyperscan (Intel) - Pattern matching
- PCRE2 - Backtracking with optimizations
Research Frontiers
1. Unicode Lexing
- Challenge: Character classes across scripts
- Approach: Unicode property classes, grapheme clusters
- Papers: "Unicode Support in Parsing" (various)
2. Incremental Lexing
- Challenge: Edit-based lexing for IDEs
- Approach: Cache tokens, re-lex only affected regions
- Tools: Tree-sitter (incremental)
3. Scannerless Parsing
- Challenge: Lexer/parser coupling
- Approach: Combine into single phase
- Tools: Scannerless GLR parsers
Implementation Pitfalls
| Pitfall | Real Consequence | Solution |
| Longest match | "=" vs "==" ambiguity | Use longest match |
| Keyword vs identifier | "if" recognized as identifier | Reserve keywords |
| Greedy matching | "//" parsed as "/" + "/" | Careful regex |
| Unicode | Wrong character classes | Use Unicode properties |
The "Keyword vs Identifier" Problem
Simple lexer issue:
if -> KEYWORD
iff -> IDENTIFIERSolution: Check keywords after matching identifier:
def tokenize(self, source):
match = self.longest_match(source)
if match.type == 'IDENT' and match.text in self.keywords:
match.type = 'KEYWORD'
return matchThis is why lexers need reservation!
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

