Skip to content

Commit 3831dea

Browse files
authored
[plsql] Fix for #3647 -- added TypeScript and JavaScript ports (#3650)
* 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.
1 parent 2a1e039 commit 3831dea

16 files changed

+43
-18
lines changed

sql/plsql/PlSqlLexer.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,10 +2449,10 @@ INTRODUCER: '_';
24492449
SINGLE_LINE_COMMENT: '--' ~('\r' | '\n')* NEWLINE_EOF -> channel(HIDDEN);
24502450
MULTI_LINE_COMMENT: '/*' .*? '*/' -> channel(HIDDEN);
24512451
// https://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve034.htm#SQPUG054
2452-
REMARK_COMMENT: 'REM' {self.IsNewlineAtPos(-4)}? 'ARK'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF -> channel(HIDDEN);
2452+
REMARK_COMMENT: 'REM' {this.IsNewlineAtPos(-4)}? 'ARK'? (' ' ~('\r' | '\n')*)? NEWLINE_EOF -> channel(HIDDEN);
24532453

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

24572457
// TODO: should starts with newline
24582458
START_CMD

sql/plsql/PlSqlParser.g4

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ storage_table_clause
22152215

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

22452245
audit_direct_path
2246-
: {self.isVersion12()}? DIRECT_PATH auditing_by_clause
2246+
: {this.isVersion12()}? DIRECT_PATH auditing_by_clause
22472247
;
22482248

22492249
audit_container_clause
2250-
: {self.isVersion12()}? (CONTAINER EQUALS_OP (CURRENT | ALL))
2250+
: {this.isVersion12()}? (CONTAINER EQUALS_OP (CURRENT | ALL))
22512251
;
22522252

22532253
audit_operation_clause
@@ -2289,7 +2289,7 @@ auditing_on_clause
22892289
: ON ( object_name
22902290
| DIRECTORY regular_id
22912291
| MINING MODEL model_name
2292-
| {self.isVersion12()}? SQL TRANSLATION PROFILE profile_name
2292+
| {this.isVersion12()}? SQL TRANSLATION PROFILE profile_name
22932293
| DEFAULT
22942294
)
22952295
;
@@ -2317,7 +2317,7 @@ sql_statement_shortcut
23172317
| MATERIALIZED VIEW
23182318
| NOT EXISTS
23192319
| OUTLINE
2320-
| {self.isVersion12()}? PLUGGABLE DATABASE
2320+
| {this.isVersion12()}? PLUGGABLE DATABASE
23212321
| PROCEDURE
23222322
| PROFILE
23232323
| PUBLIC DATABASE LINK
@@ -2550,11 +2550,11 @@ credential_name
25502550
;
25512551

25522552
library_editionable
2553-
: {self.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
2553+
: {this.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
25542554
;
25552555

25562556
library_debug
2557-
: {self.isVersion12()}? DEBUG
2557+
: {this.isVersion12()}? DEBUG
25582558
;
25592559

25602560

@@ -2623,7 +2623,7 @@ alter_view
26232623
;
26242624

26252625
alter_view_editionable
2626-
: {self.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
2626+
: {this.isVersion12()}? (EDITIONABLE | NONEDITIONABLE)
26272627
;
26282628

26292629
// https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/CREATE-VIEW.html
@@ -4222,7 +4222,7 @@ partial_database_recovery
42224222
;
42234223

42244224
partial_database_recovery_10g
4225-
: {self.isVersion10()}? STANDBY
4225+
: {this.isVersion10()}? STANDBY
42264226
( TABLESPACE tablespace (',' tablespace)*
42274227
| DATAFILE CHAR_STRING | filenumber (',' CHAR_STRING | filenumber)*
42284228
)
@@ -5046,7 +5046,7 @@ lob_partition_storage
50465046
;
50475047

50485048
period_definition
5049-
: {self.isVersion12()}? PERIOD FOR column_name
5049+
: {this.isVersion12()}? PERIOD FOR column_name
50505050
( '(' start_time_column ',' end_time_column ')' )?
50515051
;
50525052

sql/plsql/TypeScript/PlSqlLexerBase.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Lexer } from "antlr4ts";
1+
import { CommonToken, Lexer, CharStream, Token } from "antlr4";
2+
import PlSqlParser from './PlSqlParser';
23

3-
export abstract class PlSqlLexerBase extends Lexer {
4+
export default abstract class PlSqlLexerBase extends Lexer {
45
self : PlSqlLexerBase;
56

67
IsNewlineAtPos(pos: number): boolean {

sql/plsql/TypeScript/PlSqlParserBase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Parser, TokenStream } from "antlr4ts"
1+
import { Parser, TokenStream } from "antlr4";
22

3-
export abstract class PlSqlParserBase extends Parser {
3+
export default abstract class PlSqlParserBase extends Parser {
44

55
_isVersion10: boolean;
66
_isVersion12: boolean;

sql/plsql/desc.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../_scripts/desc.xsd">
3-
<antlr-version>^4.10</antlr-version>
4-
<targets>CSharp;Java</targets>
3+
<antlr-version>^4.12.0</antlr-version>
4+
<targets>CSharp;Java;JavaScript;TypeScript</targets>
5+
<test>
6+
<name>hw</name>
7+
<targets>JavaScript;TypeScript</targets>
8+
<inputs>hw-examples</inputs>
9+
</test>
10+
<test>
11+
<name>full</name>
12+
<targets>CSharp;Java</targets>
13+
<inputs>examples</inputs>
14+
</test>
515
</desc>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER OPERATOR eq_op COMPILE;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER OUTLINE salaries REBUILD;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP OPERATOR eq_op;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
select m.model from model

sql/plsql/hw-examples/lexer01.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
select * from dual where 1 < > 2 and 1 ! = 2 and 1 ^ /*aaa */ = 2
2+

0 commit comments

Comments
 (0)