Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.gwenn:sqlite-parser

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.gwenn:sqlite-parser

SQL parser generated by jlemon

  • 0.2.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

jlemon

A fork of the LEMON parser generator that generates Java code and the associated SQL parser.

Files lemon.c, lempar.c are extracted from SQLite v3.18.0.

Maven Central Javadocs

Usage

> # compile
> cc -g -O2 -o jlemon lemon.c
> # run
> jlemon <filename>.y
> # preprocess generated code
> cpp -P <filename>.j > yyParser.java

For example:

cc -g -O2 -o jlemon lemon.c
./jlemon src/test/java/simple/parser.y
cpp -P src/test/java/simple/parser.j > src/test/java/simple/yyParser.java
mvn test

Or on Windows platform:

cl /O2 /Fejlemon.exe lemon.c
jlemon.exe src\test\java\simple\parser.y
cl /EP /C src\test\java\simple\parser.j > src\test\java\simple\yyParser.java

Generated Parser API

public class yyParser {
  // %extra_argument declaration

  public yyParser(
    ParseARG_PDECL               /* Optional %extra_argument parameter */
  ) {
    // constructor
  }
  public void ParseFinalize() {  /* or can be renamed to %nameFinalize */
    // optional (clean the stack)
  }
  public void Parse(             /* or can be renamed to %name */
    int yymajor,                 /* The major token code number */
    ParseTOKENTYPE yyminor       /* The value for the token */
  ){
    // To be called by lexer
  }
}

Hack

As there is no union in Java, yy%d fields of YYMINORTYPE have been replaced by yy%d() getters and yy%d(%type value) setters. But when translating code (see translate_code), the logic used to make the difference between a read access to a yy%d field and a write access is fallible.

Maybe try a code manipulator (janino) ? Or javolution Union ?

SQL Parser

SQLite lexer and SQLite parser have been ported from C to Java. The parser generates an AST.

The parser is/will be used to fix DatabaseMetaData implementation.

  • java.sql.DatabaseMetaData.getColumns
  • java.sql.DatabaseMetaData.getPrimaryKeys
  • java.sql.DatabaseMetaData.getBestRowIdentifier
  • java.sql.DatabaseMetaData.getCrossReference
  • java.sql.DatabaseMetaData.getImportedKeys
  • java.sql.DatabaseMetaData.getExportedKeys
  • java.sql.DatabaseMetaData.getIndexInfo

Lexer/Parser

  • Keep track of position (line, column).
  • Streamable (stop at the end of statement).
  • Resumable (restart after the end of statement).

Test

SQL lexer and parser have been tested with the following scripts:

FAQs

Package last updated on 22 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc