Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 9th, 2012, 04:37 PM
ctrl ctrl is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 ctrl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 9 sec
Reputation Power: 0
Advice on using regex or not

Hi, I'm trying to do a high-level parsing of Oracle SQL scripts to isolate single commands to execute, in an Oracle compilation plugin I'm writing for notepad++

E.g.
Code:
CREATE TABLE x (column_a data_type(length), ...);

ALTER TABLE y (column_a data_type)
/

CREATE OR REPLACE PACKAGE z IS ...
   ...
END;
/

CREATE OR REPLACE PACKAGE BODY z AS ...
   -- remark...
   -- END;
END;
/

INSERT INTO TABLE z (column_a) VALUES ('123');

This is a kind of script you usually can give to sqlplus for execution, with / or ; ending commands (usually ddl with / and dml with ; )

Now... I've this regex that correctly identifies each command with object owner, name and type, and I'm using it to check system tables for error after compilation:

Code:
(CREATE(\s+OR\s+REPLACE)?|ALTER)\s+(?<object_type>PACKAGE(?!\s+BODY)|PACKAGEs+BODY|VIEW|PROCEDURE|FUNCTION|TABLE|VIEW|TRIGGER)\s+((?<owner_name>[^\s\.]+?)\.)*(?<object_name>\w+)(\s+\w+|\s+IS|\s+AS|\s*\()

but I need something more reliable to isolate each command, considering remarks and dml instructions inside packages and procedures, that are to be ignored.

Right now, I'm using regex only to identify each object and I parse the script looking for a single / on a line, and it's working, but I can't handle single dml commands as the first and last in the example above. I was wondering if I'm using the right tool or if maybe it's better to learn antlr and build a grammar.

Reply With Quote
  #2  
Old December 13th, 2012, 08:06 PM
admiraln admiraln is offline
Still Learning
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Montreal, Canada
Posts: 55 admiraln User rank is Sergeant Major (2000 - 5000 Reputation Level)admiraln User rank is Sergeant Major (2000 - 5000 Reputation Level)admiraln User rank is Sergeant Major (2000 - 5000 Reputation Level)admiraln User rank is Sergeant Major (2000 - 5000 Reputation Level)admiraln User rank is Sergeant Major (2000 - 5000 Reputation Level)admiraln User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 18 h 57 m 51 sec
Reputation Power: 38
limits of what regexs can do

There are limits of what regex can do. I am pretty sure a single regex no matter how complex, cannot parse SQL. Language parsers tend to use more complex techniques in addition to REs.

I think you will have to use a procedural languages with calls to RE to match to specific patterns.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Advice on using regex or not

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap