feat: IBM i RPG (RPGLE, RPG III) language support
What problem does this solve?
IBM i shops keep large RPG codebases in git: RPG IV (.rpgle, .sqlrpgle, .rpgleinc) and older RPG II/III (.rpg, .rpg38, .sqlrpg). Today these files are skipped, so a repo of RPG programs indexes to nothing. Program-to-program calls, procedures, subroutines, data structures and copybook includes are exactly the kind of structure this tool is good at, and they are what people ask about first when they work on this code.
Proposed solution
Add CBM_LANG_RPG with a line scanner instead of a tree-sitter grammar.
Why not a grammar: fixed-form RPG is column based (spec letter in column 6, * in column 7 is a comment, every field has fixed columns), and RPG II/III uses different columns for the calculation specification than RPG IV. The same file can also mix fixed-form specs with free-form statements. A grammar would need a large external scanner to carry the column state and would still need a second grammar for RPG III. Reading the source line by line is simpler and handles fixed, mixed and **FREE source in one place. The registry already allows entries without a grammar (Nim, ObjectScript Export), and the published language count does not change.
What it would extract:
- a Module per file
- a Function for the program (named after the member), for each procedure (
dcl-proc/ P-spec) and for each subroutine (begsr) - Struct and Field for data structures, Enum and Field for
dcl-enum, Variable for module-level fields and constants - calls from
exsr,callp, bare prototyped calls,CALL/CALLBwith a literal,CASxxandexec sql call, withextpgm/extprocprototypes resolved to their target program or procedure - imports from
/copyand/include - cyclomatic complexity and loop counts per Function
Public repos that make good test beds:
- https://github.com/barrettotte/treesitter-ibmi (
fixtures/, MIT): 50 RPG files covering fixed, mixed, fully free and RPG III - https://github.com/codefori/vscode-rpgle (
tests/): RPGLE sources used by the IBM i VS Code extension - https://github.com/IBM/ibmi-bob (sample projects):
.pgm.rpgleprogram members
I have a working implementation with tests on my fork: https://github.com/danihrndzld/codebase-memory-mcp/tree/feat/rpg-language-support (CI run: https://github.com/danihrndzld/codebase-memory-mcp/pull/1). Indexing the 50 fixture files above gives 97 Functions, 57 Structs and 32 resolved CALLS edges with no skipped files. Following CONTRIBUTING, I would like your feedback before opening the PR here.
Alternatives considered
- Vendoring a tree-sitter grammar. The only usable one is
barrettotte/treesitter-ibmi(MIT, ABI 15, plain C scanner). It is six weeks old with a single author and 1.2 MB of generated C, and it treats/copyand declaration keywords as opaque tokens, so the include and prototype parsing would still be hand-written. The other two grammars on GitHub have no license file or no committed scanner. - Free-form only. Most existing RPG is fixed-form or mixed, so that would miss the code people most need help with.
Confirmations
- I searched existing issues and this is not a duplicate.
Source: DeusData/codebase-memory-mcp