Skip to content

feat: IBM i RPG (RPGLE, RPG III) language support #2222

Description

@danihrndzld

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

  • I searched existing issues and this is not a duplicate.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    editor/integrationEditor compatibility and CLI integrationlanguage-requestRequest for new language supportparsing/qualityGraph extraction bugs, false positives, missing edges

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions