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 / CALLB with a literal, CASxx and exec sql call, with extpgm / extproc prototypes resolved to their target program or procedure
- imports from
/copy and /include
- cyclomatic complexity and loop counts per Function
Public repos that make good test beds:
I have a working implementation with tests on my fork: https://github.com/danihrndzld/codebase-memory-mcp/tree/feat/rpg-language-support (CI run: danihrndzld#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 /copy and 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
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_RPGwith 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**FREEsource 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:
dcl-proc/ P-spec) and for each subroutine (begsr)dcl-enum, Variable for module-level fields and constantsexsr,callp, bare prototyped calls,CALL/CALLBwith a literal,CASxxandexec sql call, withextpgm/extprocprototypes resolved to their target program or procedure/copyand/includePublic repos that make good test beds:
fixtures/, MIT): 50 RPG files covering fixed, mixed, fully free and RPG IIItests/): RPGLE sources used by the IBM i VS Code extension.pgm.rpgleprogram membersI have a working implementation with tests on my fork: https://github.com/danihrndzld/codebase-memory-mcp/tree/feat/rpg-language-support (CI run: danihrndzld#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
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.Confirmations