-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PL/SQL] basic example as described by the documentation reports a TypeScript type error #3647
Comments
When you look into the grammars, you will see that both the lexer- and parser grammars have defined a |
@bkiers Thank you for your feedback. I agree that it should work, but unfortunately it does not seem to work when following the documentation. |
When using the import antlr4ts from 'antlr4ts';
import PlSqlLexer from './grammar/PlSqlLexer';
import PlSqlParser from './grammar/PlSqlParser';
const input = 'select * from dual';
const inputStream = antlr4ts.CharStreams.fromString(input);
const lexer = new PlSqlLexer(inputStream);
const tokenStream = new antlr4ts.CommonTokenStream(lexer);
const parser = new PlSqlParser(tokenStream);
const tree = parser.sql_script();
console.log(tree.toStringTree(null, parser)); Reports: |
All grammars in grammars-v4 have a "desc.xml". This file describes what ports work for a grammar, the entry point (if it cannot be found by analyzing the grammar), how to test the grammar, etc. This is analogous to the pom.xml, but for all targets, not just the Java target. The desc.xml only lists CSharp and Java. grammars-v4/sql/plsql/desc.xml Line 4 in eba5c44
The plsql/ grammar doesn't work for TypeScript. There may be code for a port, but that never means that the port actually "works". A script, sets up the initial values for the desc.xml, which I did earlier in 2023. I did a "grep grammars-v4 -R -i -e antlr4ts" a few weeks ago to note that plsql/ still uses the old Tunnelvision Antlr fork for TS. #3621. I will do the port now. |
The JS port is atrociously slow--times out at 300 seconds for "long-running/" examples. BTW, I added these timeouts so the builds don't hang the system, chew up money and resources, and force the Github Action to be killed. That's part of the reason why a port isn't listed as "working" in the desc.xml. The TS port is a wrapper around the JS port. Here's how the JS port worked on a few examples in "long-running/".
I'll redo the tests so we parse puny, "Hello World!" examples for these ports. At a later point, I'll have to go through and fix the grammar so that it can parse examples bigger than the "Hello World!" equivalent for plsql. |
Here's the planned "Hello World" examples for the JS port.
|
Do I understand you correctly:
I have also already tried using the antlr4ts library but still get type errors. Would you have a working example on how to use the PlSql grammar with the antlr4ts library? Is there any documentation explaining all of this that I missed? |
All grammars--such as this grammar, sql/plsql/--that are split and have target-specific code have to be in "target agnostic format". That's described here. I'm hoping that the proposed "string template actions" PR is adopted, though. |
Unfortunately I just started having a look at this project and do not understand the implementation details. Could you please just confirm that I understood you correctly:
|
It currently only supports CSharp (the "official" name of the C# port) and Java. But, I have a PR that fixes the JavaScript and TypeScript ports. #3650
Antlr version 4.12.0 supports TypeScript, but at it stands at this second, it does not work for TypeScript, nor JavaScript. The PR I'm finishing up fixes this. I have to bump up the "" in the desc.xml to note to the testing scripts and to people that at least 4.12.0 is required. We test using 4.13.0 for grammars-v4.
It probably does still "work", but "work" is a relative term. The generated parser is really slow, and I doubt that it would be any faster than the "official" Antlr Typescript port. Also, we just don't support the TunnelVision port for TypeScript. We don't have time to support all the different targets out there. I can only work so much, and have time only for the "official" targets. The plan is to work on optimizing the grammar on a few of the more egregious problems in a day or two. |
I understand. Thank you for all the good work. |
* Fix for #3647 The grammar was ported to JS and TS, requiring a few changes to bring it into "target agnostic format". A small subset of "Hello World" examples is used to test the JS and TS ports because the parser is pretty slow. * Update desc.xml to specify minimum required version of Antlr4.
Thank you for the commit, but unfortunately I'm still not able to get my basic TypeScript example to work. #!/bin/sh
# clean
rm -rf grammar
mkdir grammar
# download grammar
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 grammar for Typescript
antlr4 -Dlanguage=TypeScript grammar/PlSqlLexer.g4
antlr4 -Dlanguage=TypeScript grammar/PlSqlParser.g4
# download Typescript support files
curl --output grammar/PlSqlLexerBase.ts https://github.com/antlr/grammars-v4/blob/master/sql/plsql/TypeScript/PlSqlLexerBase.ts
curl --output grammar/PlSqlParserBase.ts https://github.com/antlr/grammars-v4/blob/master/sql/plsql/TypeScript/PlSqlParserBase.ts The TypeScript test I'm using looks like this: 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); // ERROR: Argument of type 'PlSqlLexer' is not assignable to parameter of type 'Lexer'.
const parser = new PlSqlParser(tokens);
const tree = parser.sql_script();
console.log(tree.toStringTree(null, parser)); // ERROR: Argument of type 'PlSqlParser' is not assignable to parameter of type 'Parser'. Unfortunately TypeScript still complains about type errors when using the lexer and the parser object: 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.
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. |
Sorry. The instructions for the TypeScript target are insufficient because you have to have both a package.json file and a tsconfig.json file. Otherwise, nothing will compile. Here is a generated driver for Linux for the grammar. Please have a look at what I do, which is what is generated for this repo for Github Actions testing. Here is what the build files look like:
For comparison, here is my driver program, Test.ts:
|
I did use a |
When trying to use the
PlSql
in a basic example as described by the documentation TypeScript reports a type error when using the gramma specificPlSqlLexer
andPlSqlParser
.This is how the grammar is generated:
This is the example code:
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.
The text was updated successfully, but these errors were encountered: