@griffithswaite/ts-plsql-parser

中文文档
1.1.1发布于 2026/07/23BSD-3-ClauseTypeScriptESM + CJS近 30 天下载 2.2万

PL/SQL parser in TypeScript. Generated using Antlr4.

原始使用文档
文档目录6 节
  1. PL/SQL Parser in TypeScript
  2. What is Antlr?
  3. Why would I want to parse PL/SQL?
  4. Installation
  5. Usage
  6. Listener

PL/SQL Parser in TypeScript

Generated using Antlr4. Package and examples provided by Griffiths Waite.

What is Antlr?

From the docs: "ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files. It's widely used to build languages, tools, and frameworks. From a grammar, ANTLR generates a parser that can build parse trees and also generates a listener interface (or visitor) that makes it easy to respond to the recognition of phrases of interest."

Find out more about Antlr on its website.

Why would I want to parse PL/SQL?

Parsing code such as PL/SQL can be useful for a number of reasons, especially in Enterprise environments (or other environments where you have a lot of legacy code). For example:

  • Generate documentation from your codebase.
  • Create a list of all the functions and procedures in your codebase.
  • Generate type-safe consumer code for your API.
  • Find unused columns on your tables.
  • You can use it... to deduce just about anything you want from your code.

Being able to easily parse PL/SQL code can be an incredibly powerful tool in your arsenal for interrogating what your code is doing. Combined with our PL/SQL Viewer, you can quickly and easily take advantage of legacy code by interrogating it.

Check out the examples within this repository to see how you can use this package to parse PL/SQL code.

To try out an example, you can pull the repo and after installing dependencies do the following:

node --loader=ts-node/esm examples/interface-generator/index.ts

Installation

npm install @griffithswaite/ts-plsql-parser

Usage

Antlr produces two methods for parsing code: a visitor and a listener. We also provide a method for parsing code into a single JSON representation of the tree (getParsedNodes), this can be useful for quick parsing and debugging. You can read more about Antlr's visitor and listener patterns here.

The listener method is documented below in ESM format. If you're using CommonJS you may have to modify this code (such as removing the node:url import and __dirname definition).

Listener

import * as url from "node:url";
import { ParseTreeWalker, ParseTreeListener } from "antlr4";
import {
  ParseTreeListener,
  PlSqlParserListener,
  getParserFromFile,
} from "@griffithswaite/ts-plsql-parser";

const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const parser = getParserFromFile(__dirname + "/your-code.pbp");

class YourListener
  extends ParseTreeListener
  implements PlSqlParserListener
{
  enterUnit_statement(ctx: PlSqlParser.Unit_statementContext) {
    // Do something when entering a unit_statement
  }
}

const listener = new YourListener();
// Use the entry point for listeners
ParseTreeWalker.DEFAULT.walk(listener, parser.sql_script());

版本与发布记录

@griffithswaite/ts-plsql-parser 共发布 8 个版本,首次发布于 2023/10/05;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.1.1latest2026/07/233 个月前
1.1.02026/07/233 个月前
1.0.52023/10/173 年前
1.0.42023/10/113 年前
1.0.32023/10/063 年前
1.0.22023/10/063 年前

关于 @griffithswaite/ts-plsql-parser 的常见问题

@griffithswaite/ts-plsql-parser 是什么?

PL/SQL parser in TypeScript. Generated using Antlr4.

如何安装 @griffithswaite/ts-plsql-parser?

在项目目录运行 npm install @griffithswaite/ts-plsql-parser,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:antlr4(4.13.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@griffithswaite/ts-plsql-parser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@griffithswaite/ts-plsql-parser 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@griffithswaite/ts-plsql-parser 可以商用吗?

@griffithswaite/ts-plsql-parser 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@griffithswaite/ts-plsql-parser 的下载量有多少?

根据 npm 官方下载统计,@griffithswaite/ts-plsql-parser 在 2026/10/17 – 2026/11/15 这 30 天内被下载 21,697 次,日均约 723 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@griffithswaite/ts-plsql-parser 还在维护吗?

最新版本 1.1.1 发布于 2026/07/23(3 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/10/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。