Skip to content

Commit

Permalink
[plsql] Fix for #3647 -- added TypeScript and JavaScript ports (#3650)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
kaby76 authored Aug 9, 2023
1 parent 2a1e039 commit 3831dea
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 18 deletions.
4 changes: 2 additions & 2 deletions sql/plsql/PlSqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2449,10 +2449,10 @@ INTRODUCER: '_';
SINGLE_LINE_COMMENT: '--' ~('\r' | '\n')* NEWLINE_EOF -> channel(HIDDEN);
MULTI_LINE_COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
// https://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve034.htm#SQPUG054
REMARK_COMMENT: 'REM' {self.IsNewlineAtPos(-4)}? 'ARK'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF -> channel(HIDDEN);
REMARK_COMMENT: 'REM' {this.IsNewlineAtPos(-4)}? 'ARK'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF -> channel(HIDDEN);

// https://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve032.htm#SQPUG052
PROMPT_MESSAGE: 'PRO' {self.IsNewlineAtPos(-4)}? 'MPT'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF;
PROMPT_MESSAGE: 'PRO' {this.IsNewlineAtPos(-4)}? 'MPT'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF;

// TODO: should starts with newline
START_CMD
Expand Down
20 changes: 10 additions & 10 deletions sql/plsql/PlSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ storage_table_clause

// https://docs.oracle.com/database/121/SQLRF/statements_4008.htm#SQLRF56110
unified_auditing
: {self.isVersion12()}?
: {this.isVersion12()}?
AUDIT (POLICY policy_name ((BY | EXCEPT) audit_user (',' audit_user)* )?
(WHENEVER NOT? SUCCESSFUL)?
| CONTEXT NAMESPACE oracle_namespace
Expand Down Expand Up @@ -2243,11 +2243,11 @@ audit_traditional
;

audit_direct_path
: {self.isVersion12()}? DIRECT_PATH auditing_by_clause
: {this.isVersion12()}? DIRECT_PATH auditing_by_clause
;

audit_container_clause
: {self.isVersion12()}? (CONTAINER EQUALS_OP (CURRENT | ALL))
: {this.isVersion12()}? (CONTAINER EQUALS_OP (CURRENT | ALL))
;

audit_operation_clause
Expand Down Expand Up @@ -2289,7 +2289,7 @@ auditing_on_clause
: ON ( object_name
| DIRECTORY regular_id
| MINING MODEL model_name
| {self.isVersion12()}? SQL TRANSLATION PROFILE profile_name
| {this.isVersion12()}? SQL TRANSLATION PROFILE profile_name
| DEFAULT
)
;
Expand Down Expand Up @@ -2317,7 +2317,7 @@ sql_statement_shortcut
| MATERIALIZED VIEW
| NOT EXISTS
| OUTLINE
| {self.isVersion12()}? PLUGGABLE DATABASE
| {this.isVersion12()}? PLUGGABLE DATABASE
| PROCEDURE
| PROFILE
| PUBLIC DATABASE LINK
Expand Down Expand Up @@ -2550,11 +2550,11 @@ credential_name
;

library_editionable
: {self.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
: {this.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
;

library_debug
: {self.isVersion12()}? DEBUG
: {this.isVersion12()}? DEBUG
;


Expand Down Expand Up @@ -2623,7 +2623,7 @@ alter_view
;

alter_view_editionable
: {self.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
: {this.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
;

// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-VIEW.html
Expand Down Expand Up @@ -4222,7 +4222,7 @@ partial_database_recovery
;

partial_database_recovery_10g
: {self.isVersion10()}? STANDBY
: {this.isVersion10()}? STANDBY
( TABLESPACE tablespace (',' tablespace)*
| DATAFILE CHAR_STRING | filenumber (',' CHAR_STRING | filenumber)*
)
Expand Down Expand Up @@ -5046,7 +5046,7 @@ lob_partition_storage
;

period_definition
: {self.isVersion12()}? PERIOD FOR column_name
: {this.isVersion12()}? PERIOD FOR column_name
( '(' start_time_column ',' end_time_column ')' )?
;

Expand Down
5 changes: 3 additions & 2 deletions sql/plsql/TypeScript/PlSqlLexerBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Lexer } from "antlr4ts";
import { CommonToken, Lexer, CharStream, Token } from "antlr4";
import PlSqlParser from './PlSqlParser';

export abstract class PlSqlLexerBase extends Lexer {
export default abstract class PlSqlLexerBase extends Lexer {
self : PlSqlLexerBase;

IsNewlineAtPos(pos: number): boolean {
Expand Down
4 changes: 2 additions & 2 deletions sql/plsql/TypeScript/PlSqlParserBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Parser, TokenStream } from "antlr4ts"
import { Parser, TokenStream } from "antlr4";

export abstract class PlSqlParserBase extends Parser {
export default abstract class PlSqlParserBase extends Parser {

_isVersion10: boolean;
_isVersion12: boolean;
Expand Down
14 changes: 12 additions & 2 deletions sql/plsql/desc.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../_scripts/desc.xsd">
<antlr-version>^4.10</antlr-version>
<targets>CSharp;Java</targets>
<antlr-version>^4.12.0</antlr-version>
<targets>CSharp;Java;JavaScript;TypeScript</targets>
<test>
<name>hw</name>
<targets>JavaScript;TypeScript</targets>
<inputs>hw-examples</inputs>
</test>
<test>
<name>full</name>
<targets>CSharp;Java</targets>
<inputs>examples</inputs>
</test>
</desc>
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/alter_operator.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER OPERATOR eq_op COMPILE;
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/alter_outline.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER OUTLINE salaries REBUILD;
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/drop_operator.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP OPERATOR eq_op;
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/keywordasidentifier02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select m.model from model
2 changes: 2 additions & 0 deletions sql/plsql/hw-examples/lexer01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
select * from dual where 1 < > 2 and 1 ! = 2 and 1 ^ /*aaa */ = 2

2 changes: 2 additions & 0 deletions sql/plsql/hw-examples/lexer02.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
select 'A' | | 'B' from dual

2 changes: 2 additions & 0 deletions sql/plsql/hw-examples/lexer03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
select :1, :X, :1 + 1, 1 + :2 from A where A=:3 and b= : 4 and c= :5and :A = :b

1 change: 1 addition & 0 deletions sql/plsql/hw-examples/lexer04.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select tbl$or$idx$part$num("sys"."wrh$_seg_stat",0,4,0,"rowid") as c1 from t1
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/lexer05.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select tbl$or$idx$part$num("sys"."wrh:_seg_stat",0,4,0,"rowid") as c1 from t1
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/simple11.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select a.* from dual
1 change: 1 addition & 0 deletions sql/plsql/hw-examples/truncate_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
truncate table test;

0 comments on commit 3831dea

Please sign in to comment.