'*******************************************************************************
' EverEdit Syntax File
' Language: Oracle PL/SQL
' History:  v1.1, 2015-07-09: Minor updates
'           v1.0, 2014-04-20: Initial version (based on Cye3s version)
'*******************************************************************************
Include(".\const.mac")

Set orasql = CreateParser()

' --- Region ----------------------------

' Comment and String
Set rLineComment  = orasql.CreateRegion(COLOR_COMMENT1, "+--+", "$",    False)
Set rBlockComment = orasql.CreateRegion(COLOR_COMMENT1, "+/*+", "+*/+", True)
Set rString1 = orasql.CreateStringRegion(COLOR_STRING1, "'",    "",     False)
Set rString2 = orasql.CreateStringRegion(COLOR_STRING2, """",   "\",    False)

orasql.AddRegion(rLineComment)
orasql.AddRegion(rBlockComment)
orasql.AddRegion(rString1)
orasql.AddRegion(rString2)

' --- Item/Word ------------------------

' Number
Set iNumber = orasql.CreateItem(COLOR_NUMBER, "\b\d+\b", False)

' Operator
Set iOperator = orasql.CreateItem(COLOR_OPERATOR, "[\{\}\(\)\+\-\*\\/=%&\^!~\|<>?,:\.;@\[\]]", False)

' Type
Set wType = orasql.CreateWord(COLOR_WORD1, "BFILE BINARY_INTEGER BLOB BOOLEAN BYTE CHAR CHARACTER CLOB DATE DAY DEC DECIMAL FLOAT HOUR INT INTEGER LONG MINUTE MONTH NATURAL NATURALN NCHAR NCLOB NUMBER NUMERIC NVARCHAR2 POSITIVE POSITIVEN PLS_INTEGER RAW REAL RECORD ROWID ROWTYPE SECOND SMALLINT STRING SUBTYPE TIMESTAMP TIMEZONE_ABBR TIMEZONE_HOUR TIMEZONE_MINUTE TIMEZONE_REGION TYPE VARCHAR VARCHAR2 VARRAY YEAR", False)

' Reserved Word
Set wKeyWord1 = orasql.CreateWord(COLOR_WORD1, "ALL ALTER AND ANY AS ASC AT BEGIN BETWEEN BY CASE CHECK CLUSTER CLUSTERS COLUMNS COMPRESS CONNECT CRASH CREATE CURRENT DECLARE DEFAULT DELETE DESC DISTINCT DROP ELSE END EXCEPTION EXCLUSIVE EXISTS FETCH FOR FROM GOTO GRANT GROUP HAVING IDENTIFIED IF IN INDEX INDEXES INSERT INTERSECT INTO IS LIKE LOCK MINUS MODE NOCOMPRESS NOT NOWAIT NULL OF ON OPTION OR ORDER OVERLAPS PRIOR PROCEDURE PUBLIC RESOURCE REVOKE SELECT SHARE SIZE SQL START TABAUTH TABLE THEN TO UNION UNIQUE UPDATE VALUES VIEW VIEWS WHEN WHERE WITH", False)

' Keyword
Set wKeyWord2 = orasql.CreateWord(COLOR_WORD1, "ADD ARRAY ATTRIBUTE AUTHID AVG BINARY BLOCK BODY BOTH BOUND BULK CALL CASCADE CLOSE COLLECT COMMENT COMMIT COMMITTED CONSTANT CONTEXT CONTINUE CONVERT COUNT CURSOR DANGLING DATA DEFINE DOUBLE ELEMENT ELSIF EMPTY ESCAPE EXCEPT EXCEPTIONS EXECUTE EXIT EXTERNAL FINAL FORALL FORCE FUNCTION HASH HEAP IMMEDIATE INCLUDING INDICATOR INFINITE INSTANTIABLE INTERFACE INTERVAL INVALIDATE ISOLATION JAVA LANGUAGE LEADING LENGTH LEVEL LIBRARY LIKE2 LIKE4 LIKEC LIMIT LIMITED LOCAL LOOP MAX MEMBER MERGE MIN MOD MODIFY MULTISET NAME NAN NATIONAL NATIVE NEW NOCOPY OBJECT ONLY OPAQUE OPEN OPERATOR ORGANIZATION OUT PACKAGE PARAMETERS PARTITION PIPE PIPELINED PRAGMA PRECISION PRIVATE RAISE RANGE READ REF REFERENCE REM REMAINDER RENAME RESULT_CACHE RETURN RETURNING REVERSE ROLLBACK ROW SAMPLE SAVE SAVEPOINT SB1 SB2 SB4 SEGMENT SEPARATE SEQUENCE SERIALIZABLE SET SOME SQLCODE SQLSTATE STATIC STDDEV SUBMULTISET SUBPARTITION SUBSTITUTABLE SUM SYNONYM THE TIME TRAILING TRANSACTION TRANSACTIONAL TRUSTED UNDER USE USING VALUE VARIABLE VARIANCE VARYING WHILE WORK WRAPPED WRITE ZONE", False)

' Special
Set wSpecial = orasql.CreateWord(COLOR_FUNCTION, "ACCEPT AUTONOMOUS_TRANSACTION COMPUTE CROSS CURRVAL DUAL EXEC EXPLAIN EXTEND FALSE FIRST FOUND FULL INNER ISOPEN JOIN LAST LEFT NEXT NEXTVAL NOTFOUND OUTER PLAN RIGHT ROWCOUNT ROWNUM SLEEP SYSDATE TRUE WHENEVER", False)

' Exception
Set wException = orasql.CreateWord(COLOR_FUNCTION, "DUP_VAL_ON_INDEX EXCEPTION_INIT FORMAT_CALL_STACK INVALID_NUMBER NO_DATA_FOUND OTHERS RAISE_APPLICATION_ERROR SQLERROR SQLERRM TOO_MANY_ROWS VALUE_ERROR", False)

' Function
Set wFunction = orasql.CreateWord(COLOR_FUNCTION, "ABS ACOS ADD_MONTHS ASCII ASIN ATAN ATAN2 CAST CEIL CHARTOROWID CHR COALESCE CONCAT COS COSH CURRENT_TIMESTAMP DECODE DUMP EXP FLOOR GREATEST HEXTORAW INITCAP INSTR INSTRB LAST_DAY LEAST LENGTHB LENGTHC LN LOCALTIMESTAMP LOG LOWER LPAD LTRIM MONTHS_BETWEEN NEXT_DAY NVL NVL2 POWER PUT_LINE RAWTOHEX REGEXP_COUNT REGEXP_INSTR REGEXP_LIKE REGEXP_REPLACE REGEXP_SUBSTR REPLACE ROUND ROWIDTOCHAR RPAD RTRIM SIGN SIN SINH SOUNDEX SQRT SUBSTR SUBSTRB TAN TANH TO_CHAR TO_DATE TO_NUMBER TRANSLATE TRIM TRUNC UID UPPER USER USERENV VSIZE", False)

' Analytic
Set wAnalytic = orasql.CreateWord(COLOR_FUNCTION, "CUBE DENSE_RANK FIRST_VALUE FOLLOWING LAG LAST_VALUE LEAD NTILE NULLS OVER PERCENT_RANK PRECEDING RANK ROLLUP ROW_NUMBER ROWS SIBLINGS UNBOUNDED", False)

' Set operations or sql*plus related
Set wSetOps = orasql.CreateWord(COLOR_FUNCTION, "AUTOCOMMIT ECHO FEEDBACK HEADING LINESIZE NEWPAGE PAGESIZE PROMPT SERVEROUTPUT SPOOL TERM TIMING TRIMOUT TRIMSPOOL UNDERLINE VERIFY", False)

' DDL
Set wDml = orasql.CreateWord(COLOR_WORD1, "COLUMN COMPILE CONSTRAINT DATABASE DISABLE ENABLE FOREIGN KEY LINK OFF PRIMARY REBUILD REFERENCES SCHEMA SESSION TABLESPACE TRIGGER TRUNCATE", False)

' System Package
Set iSysPkg = orasql.CreateItem(COLOR_MACRO, "\b(DBMS|UTL)_\w+\b", False)

' Dictionary View
Set iDictView = orasql.CreateItem(COLOR_MACRO, "\b(GV\$|V_?\$)\w+\b", False)

' --- Add Item/Word --------------------

orasql.AddItem(iNumber)
orasql.AddItem(iOperator)
orasql.AddWord(wType)
orasql.AddWord(wKeyWord1)
orasql.AddWord(wKeyWord2)
orasql.AddWord(wException)
orasql.AddWord(wSpecial)
orasql.AddWord(wFunction)
orasql.AddWord(wAnalytic)
orasql.AddWord(wSetOps)
orasql.AddWord(wDml)
orasql.AddItem(iSysPkg)
orasql.AddItem(iDictView)

' --- Other ----------------------------

orasql.FoldText "\b(DECLARE|BEGIN|(?<!END\s+)LOOP|CREATE OR REPLACE|(?<!END\s+)CASE|(?<!END\s+)IF)\b", False, "\bEND(\s|\||;)+", False
orasql.IndentText "\b(THEN|LOOP|ELSE|BEGIN|IS|EXCEPTION|ELSIF)\b", False, "\b(ELSE|ELSIF)\b|\bEND(\s|\||;)+", False

Call orasql.SetPairs("[]{}()""""''")
Call orasql.CommentLine("--")
Call orasql.CommentBlock("/*", "*/")
