npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@griffithswaite/ts-plsql-parser

v1.0.5

Published

PL/SQL parser in TypeScript. Generated using Antlr4.

Downloads

12

Readme

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());