Skip to content

[PL/SQL] basic example as described by the documentation reports a TypeScript type error #3647

@doberkofler

Description

@doberkofler

When trying to use the PlSql in a basic example as described by the documentation TypeScript reports a type error when using the gramma specific PlSqlLexer and PlSqlParser.

This is how the grammar is generated:

# clean
rm -rf grammar
mkdir grammar

# download gramma
curl --output grammar/PlSqlLexer.g4 https://raw.githubusercontent.com/antlr/grammars-v4/master/sql/plsql/PlSqlLexer.g4
curl --output grammar/PlSqlParser.g4 https://raw.githubusercontent.com/antlr/grammars-v4/master/sql/plsql/PlSqlParser.g4

### convert gramma for Typescript
antlr4 -Dlanguage=TypeScript grammar/PlSqlLexer.g4
antlr4 -Dlanguage=TypeScript grammar/PlSqlParser.g4

This is the example code:

import antlr4 from 'antlr4';
import PlSqlLexer from './grammar/PlSqlLexer';
import PlSqlParser from './grammar/PlSqlParser';

const input = 'select * from dual';
const chars = new antlr4.CharStream(input);
const lexer = new PlSqlLexer(chars);
const tokens = new antlr4.CommonTokenStream(lexer); /* type error 1 */
const parser = new PlSqlParser(tokens);
const tree = parser.sql_script();
console.log(tree.toStringTree(null, parser)); /* type error 2 */

type error 1:

Argument of type 'PlSqlLexer' is not assignable to parameter of type 'Lexer'.
Type 'PlSqlLexer' is missing the following properties from type 'Lexer': _input, _interp, text, line, and 18 more.

type error 2:

Argument of type 'PlSqlParser' is not assignable to parameter of type 'Parser'.
Type 'PlSqlParser' is missing the following properties from type 'Parser': _input, _ctx, _interp, _errHandler, and 25 more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions