antlr / antlr4

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
http://antlr.org
BSD 3-Clause "New" or "Revised" License
17.11k stars 3.28k forks source link

PL/SQL grammar cannot recognise identifiers that start with keywords #4565

Closed stephendrew closed 7 months ago

stephendrew commented 7 months ago

Target: C# Grammar: PL/SQL

I am trying to parse parser.sql_script() for this:

CREATE OR REPLACE PACKAGE ACCESS_SECURITY AS
-- omitted
END;

But it fails due to treating ACCESS as a keyword.

stephendrew commented 7 months ago
Token: [@0,0:5='CREATE',<305>,1:0]
Token: [@1,6:6=' ',<2380>,channel=1,1:6]
Token: [@2,7:8='OR',<1237>,1:7]
Token: [@3,9:9=' ',<2380>,channel=1,1:9]
Token: [@4,10:16='REPLACE',<1484>,1:10]
Token: [@5,17:17=' ',<2380>,channel=1,1:17]
Token: [@6,18:24='PACKAGE',<1257>,1:18]
Token: [@7,25:25=' ',<2380>,channel=1,1:25]
Token: [@8,26:31='ACCESS',<4>,1:26]
Token: [@9,32:32='_',<2372>,1:32]
Token: [@10,33:40='SECURITY',<1563>,1:33]
Token: [@11,41:42='\r\n',<2380>,channel=1,1:41]
Token: [@12,43:44='AS',<67>,2:0]
Exception of type 'Antlr4.Runtime.NoViableAltException' was thrown.
OffendingToken: [@9,32:32='_',<2372>,1:32]
stephendrew commented 7 months ago

Closing for https://github.com/antlr/grammars-v4/issues/4028